diff options
Diffstat (limited to 'node_modules/@isaacs/string-locale-compare/index.js')
-rw-r--r-- | node_modules/@isaacs/string-locale-compare/index.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/node_modules/@isaacs/string-locale-compare/index.js b/node_modules/@isaacs/string-locale-compare/index.js new file mode 100644 index 000000000..a6cec27ef --- /dev/null +++ b/node_modules/@isaacs/string-locale-compare/index.js @@ -0,0 +1,22 @@ +const hasIntl = typeof Intl === 'object' && !!Intl +const Collator = hasIntl && Intl.Collator +const cache = new Map() + +const collatorCompare = locale => { + const collator = new Collator(locale) + return (a, b) => collator.compare(a, b) +} + +const localeCompare = locale => (a, b) => a.localeCompare(b, locale) + +module.exports = locale => { + if (!locale || typeof locale !== 'string') + throw new TypeError('locale required') + + if (cache.has(locale)) + return cache.get(locale) + + const compare = hasIntl ? collatorCompare(locale) : localeCompare(locale) + cache.set(locale, compare) + return compare +} |