tableflip/intl-to-mongo-collation

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

intl-to-mongo-collation

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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.