Skip to content

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

License

Notifications You must be signed in to change notification settings

isaacs/string-locale-compare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

@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

About

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

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published