JSPM

@isaacs/string-locale-compare

1.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2896351
  • Score
    100M100P100Q228300F
  • License ISC

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

Package Exports

  • @isaacs/string-locale-compare

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@isaacs/string-locale-compare) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@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