@isaacs/string-locale-compare

1.1.0 • Public • Published

@isaacs/string-locale-compare

Compare strings with Intl.Collator if available, falling back to String.localeCompare otherwise.

This also forces the use of a specific locale, to avoid using the system locale, which is non-deterministic.

USAGE

const stringLocaleCompare = require('@isaacs/string-locale-compare')

myArrayOfStrings.sort(stringLocaleCompare('en'))

// can also pass extra options
myArrayOfNumericStrings.sort(stringLocaleCompare('en', { numeric: true }))

API

stringLocaleCompare(locale, [options])

Locale is required, must be a valid locale string.

Options is optional. The following options are supported:

  • sensitivity
  • numeric
  • ignorePunctuation
  • caseFirst

/@isaacs/string-locale-compare/

    Package Sidebar

    Install

    npm i @isaacs/string-locale-compare

    Weekly Downloads

    1,910,602

    Version

    1.1.0

    License

    ISC

    Unpacked Size

    3.16 kB

    Total Files

    4

    Last publish

    Collaborators

    • isaacs