react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / abbrev / abbrev.js
80681 views1module.exports = exports = abbrev.abbrev = abbrev23abbrev.monkeyPatch = monkeyPatch45function monkeyPatch () {6Object.defineProperty(Array.prototype, 'abbrev', {7value: function () { return abbrev(this) },8enumerable: false, configurable: true, writable: true9})1011Object.defineProperty(Object.prototype, 'abbrev', {12value: function () { return abbrev(Object.keys(this)) },13enumerable: false, configurable: true, writable: true14})15}1617function abbrev (list) {18if (arguments.length !== 1 || !Array.isArray(list)) {19list = Array.prototype.slice.call(arguments, 0)20}21for (var i = 0, l = list.length, args = [] ; i < l ; i ++) {22args[i] = typeof list[i] === "string" ? list[i] : String(list[i])23}2425// sort them lexicographically, so that they're next to their nearest kin26args = args.sort(lexSort)2728// walk through each, seeing how much it has in common with the next and previous29var abbrevs = {}30, prev = ""31for (var i = 0, l = args.length ; i < l ; i ++) {32var current = args[i]33, next = args[i + 1] || ""34, nextMatches = true35, prevMatches = true36if (current === next) continue37for (var j = 0, cl = current.length ; j < cl ; j ++) {38var curChar = current.charAt(j)39nextMatches = nextMatches && curChar === next.charAt(j)40prevMatches = prevMatches && curChar === prev.charAt(j)41if (!nextMatches && !prevMatches) {42j ++43break44}45}46prev = current47if (j === cl) {48abbrevs[current] = current49continue50}51for (var a = current.substr(0, j) ; j <= cl ; j ++) {52abbrevs[a] = current53a += current.charAt(j)54}55}56return abbrevs57}5859function lexSort (a, b) {60return a === b ? 0 : a > b ? 1 : -161}626364