diff options
author | Gar <gar+gh@danger.computer> | 2021-09-28 20:05:08 +0300 |
---|---|---|
committer | Gar <gar+gh@danger.computer> | 2021-09-28 20:05:08 +0300 |
commit | e94ddeaca1e75ecc8f54ebcb3df222965e3635d1 (patch) | |
tree | b2ec351450e8392bebd0410fe6367101a1e1b4b2 /node_modules/@isaacs/string-locale-compare/index.js | |
parent | 075fe50565ae5c66df727cdd7df9dd5ed8cd4015 (diff) |
deps: @npmcli/arborist@2.9.0
* fix: avoid infinite loops in peer dep replacements
* fix: use Intl.Collator for string sorting when available
* feat(vuln): expose isDirect
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 +} |