Name: intl-to-mongo-collation
Owner: TABLEFLIP
Description: Convert intl collation opts to mongodb collation opts
Created: 2017-11-22 12:07:36.0
Updated: 2017-11-22 12:42:08.0
Pushed: 2017-11-22 12:42:41.0
Homepage: null
Size: 38
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Intl.Collator options are similar to the MongoDB collation options, so let's automate the conversion.
The tests demonstrate:
('converts intl collation opts to mongo collation opts', t => {
nst intlOpts = {
sensitivity: 'base',
ignorePunctuation: true,
numeric: true,
caseFirst: 'upper'
nst mongoOpts = {
strength: 1,
alternate: 'shifted',
numericOrdering: true,
caseFirst: 'upper'
nst actual = intlToMongo(intlOpts)
deepEqual(actual, mongoOpts)
With this, it's possible to define the browser Intl.Collator sort options once, and re-use them for the server side mongo collation opts.
The conversion is best effort. You need to evaluate if it works for your i18n needs.
PRs to make the conversion more accurate are welcome!
A (?°?°???TABLEFLIP side project.