aboutsummaryrefslogtreecommitdiff
path: root/_mint/node_modules/abbrev/abbrev.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2021-12-21 15:25:09 +0100
committerMinteck <contact@minteck.org>2021-12-21 15:25:09 +0100
commite703e51c9c09b22e3bcda9a1faf1e05897f60616 (patch)
tree4fd67a209ad6988fbf569d7dff8bc37ba45baf95 /_mint/node_modules/abbrev/abbrev.js
downloadmint-e703e51c9c09b22e3bcda9a1faf1e05897f60616.tar.gz
mint-e703e51c9c09b22e3bcda9a1faf1e05897f60616.tar.bz2
mint-e703e51c9c09b22e3bcda9a1faf1e05897f60616.zip
Initial commit
Diffstat (limited to '_mint/node_modules/abbrev/abbrev.js')
-rw-r--r--_mint/node_modules/abbrev/abbrev.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/_mint/node_modules/abbrev/abbrev.js b/_mint/node_modules/abbrev/abbrev.js
new file mode 100644
index 0000000..7b1dc5d
--- /dev/null
+++ b/_mint/node_modules/abbrev/abbrev.js
@@ -0,0 +1,61 @@
+module.exports = exports = abbrev.abbrev = abbrev
+
+abbrev.monkeyPatch = monkeyPatch
+
+function monkeyPatch () {
+ Object.defineProperty(Array.prototype, 'abbrev', {
+ value: function () { return abbrev(this) },
+ enumerable: false, configurable: true, writable: true
+ })
+
+ Object.defineProperty(Object.prototype, 'abbrev', {
+ value: function () { return abbrev(Object.keys(this)) },
+ enumerable: false, configurable: true, writable: true
+ })
+}
+
+function abbrev (list) {
+ if (arguments.length !== 1 || !Array.isArray(list)) {
+ list = Array.prototype.slice.call(arguments, 0)
+ }
+ for (var i = 0, l = list.length, args = [] ; i < l ; i ++) {
+ args[i] = typeof list[i] === "string" ? list[i] : String(list[i])
+ }
+
+ // sort them lexicographically, so that they're next to their nearest kin
+ args = args.sort(lexSort)
+
+ // walk through each, seeing how much it has in common with the next and previous
+ var abbrevs = {}
+ , prev = ""
+ for (var i = 0, l = args.length ; i < l ; i ++) {
+ var current = args[i]
+ , next = args[i + 1] || ""
+ , nextMatches = true
+ , prevMatches = true
+ if (current === next) continue
+ for (var j = 0, cl = current.length ; j < cl ; j ++) {
+ var curChar = current.charAt(j)
+ nextMatches = nextMatches && curChar === next.charAt(j)
+ prevMatches = prevMatches && curChar === prev.charAt(j)
+ if (!nextMatches && !prevMatches) {
+ j ++
+ break
+ }
+ }
+ prev = current
+ if (j === cl) {
+ abbrevs[current] = current
+ continue
+ }
+ for (var a = current.substr(0, j) ; j <= cl ; j ++) {
+ abbrevs[a] = current
+ a += current.charAt(j)
+ }
+ }
+ return abbrevs
+}
+
+function lexSort (a, b) {
+ return a === b ? 0 : a > b ? 1 : -1
+}