intl-to-mongo-collation
v0.1.0
Published
Convert Intl Collator opts to mongo collation opts
Downloads
2
Readme
intl-to-mongo-collation
Intl.Collator options are similar to the MongoDB collation options, so let's automate the conversion.
The tests demonstrate:
test('converts intl collation opts to mongo collation opts', t => {
const intlOpts = {
sensitivity: 'base',
ignorePunctuation: true,
numeric: true,
caseFirst: 'upper'
}
const mongoOpts = {
strength: 1,
alternate: 'shifted',
numericOrdering: true,
caseFirst: 'upper'
}
const actual = intlToMongo(intlOpts)
t.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.