Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2021-09-28 20:05:08 +0300
committerGar <gar+gh@danger.computer>2021-09-28 20:05:08 +0300
commite94ddeaca1e75ecc8f54ebcb3df222965e3635d1 (patch)
treeb2ec351450e8392bebd0410fe6367101a1e1b4b2 /node_modules/@isaacs/string-locale-compare/index.js
parent075fe50565ae5c66df727cdd7df9dd5ed8cd4015 (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.js22
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
+}