diff options
Diffstat (limited to 'node_modules/@isaacs')
-rw-r--r-- | node_modules/@isaacs/string-locale-compare/index.js | 36 | ||||
-rw-r--r-- | node_modules/@isaacs/string-locale-compare/package.json | 2 |
2 files changed, 29 insertions, 9 deletions
diff --git a/node_modules/@isaacs/string-locale-compare/index.js b/node_modules/@isaacs/string-locale-compare/index.js index a6cec27ef..0f68ab677 100644 --- a/node_modules/@isaacs/string-locale-compare/index.js +++ b/node_modules/@isaacs/string-locale-compare/index.js @@ -2,21 +2,41 @@ const hasIntl = typeof Intl === 'object' && !!Intl const Collator = hasIntl && Intl.Collator const cache = new Map() -const collatorCompare = locale => { - const collator = new Collator(locale) +const collatorCompare = (locale, opts) => { + const collator = new Collator(locale, opts) return (a, b) => collator.compare(a, b) } -const localeCompare = locale => (a, b) => a.localeCompare(b, locale) +const localeCompare = (locale, opts) => (a, b) => a.localeCompare(b, locale, opts) -module.exports = locale => { +const knownOptions = [ + 'sensitivity', + 'numeric', + 'ignorePunctuation', + 'caseFirst', +] + +const { hasOwnProperty } = Object.prototype + +module.exports = (locale, options = {}) => { if (!locale || typeof locale !== 'string') throw new TypeError('locale required') - if (cache.has(locale)) - return cache.get(locale) + const opts = knownOptions.reduce((opts, k) => { + if (hasOwnProperty.call(options, k)) { + opts[k] = options[k] + } + return opts + }, {}) + const key = `${locale}\n${JSON.stringify(opts)}` + + if (cache.has(key)) + return cache.get(key) + + const compare = hasIntl + ? collatorCompare(locale, opts) + : localeCompare(locale, opts) + cache.set(key, compare) - const compare = hasIntl ? collatorCompare(locale) : localeCompare(locale) - cache.set(locale, compare) return compare } diff --git a/node_modules/@isaacs/string-locale-compare/package.json b/node_modules/@isaacs/string-locale-compare/package.json index a322c1c92..58de848a0 100644 --- a/node_modules/@isaacs/string-locale-compare/package.json +++ b/node_modules/@isaacs/string-locale-compare/package.json @@ -1,6 +1,6 @@ { "name": "@isaacs/string-locale-compare", - "version": "1.0.1", + "version": "1.1.0", "files": [ "index.js" ], |