@trashpanda001/helpers
    Preparing search index...

    Function compareStringsNatural

    • Compare two strings with a natural alphabetic ordering (numbers sort properly).

      Empty values sort last: "", null, and undefined last.

      Parameters

      • target: Optional<string>

        the first string to compare

      • other: Optional<string>

        the second string to compare

      Returns number

      alphabetic ordering, with numbers sorted naturally

      Error if string-natural-compare is not available

      Sort strings with ascending numbers.

      import { compareStringsNatural } from "@trashpanda001/helpers/comparators"

      compareStringsNatural("1 Dog", "2 Dogs")
      // -1 .. 1 Dog, 2 Dogs
      compareStringsNatural("9 Cats", "8 Cats")
      // 1 ... 8 Cats, 9 Cats