pax_global_header00006660000000000000000000000064127303204570014515gustar00rootroot0000000000000052 comment=c386cd9dbb1d8d7581718c54d4ba944cc9298d6f abbrev-js-1.0.9/000077500000000000000000000000001273032045700133775ustar00rootroot00000000000000abbrev-js-1.0.9/.gitignore000066400000000000000000000000551273032045700153670ustar00rootroot00000000000000.nyc_output nyc_output node_modules coverage abbrev-js-1.0.9/.travis.yml000066400000000000000000000001641273032045700155110ustar00rootroot00000000000000language: node_js node_js: - '0.8' - '0.10' - '0.12' - 'iojs' before_install: - npm install -g npm@latest abbrev-js-1.0.9/CONTRIBUTING.md000066400000000000000000000001731273032045700156310ustar00rootroot00000000000000 To get started, sign the Contributor License Agreement. abbrev-js-1.0.9/LICENSE000066400000000000000000000013751273032045700144120ustar00rootroot00000000000000The ISC License Copyright (c) Isaac Z. Schlueter and Contributors Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. abbrev-js-1.0.9/README.md000066400000000000000000000007631273032045700146640ustar00rootroot00000000000000# abbrev-js Just like [ruby's Abbrev](http://apidock.com/ruby/Abbrev). Usage: var abbrev = require("abbrev"); abbrev("foo", "fool", "folding", "flop"); // returns: { fl: 'flop' , flo: 'flop' , flop: 'flop' , fol: 'folding' , fold: 'folding' , foldi: 'folding' , foldin: 'folding' , folding: 'folding' , foo: 'foo' , fool: 'fool' } This is handy for command-line scripts, or other cases where you want to be able to accept shorthands. abbrev-js-1.0.9/abbrev.js000066400000000000000000000033441273032045700152020ustar00rootroot00000000000000 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 } abbrev-js-1.0.9/package.json000066400000000000000000000005721273032045700156710ustar00rootroot00000000000000{ "name": "abbrev", "version": "1.0.9", "description": "Like ruby's abbrev module, but in js", "author": "Isaac Z. Schlueter ", "main": "abbrev.js", "scripts": { "test": "tap test.js --cov" }, "repository": "http://github.com/isaacs/abbrev-js", "license": "ISC", "devDependencies": { "tap": "^5.7.2" }, "files": [ "abbrev.js" ] } abbrev-js-1.0.9/test.js000066400000000000000000000020551273032045700147160ustar00rootroot00000000000000var abbrev = require('./abbrev.js') var assert = require("assert") var util = require("util") console.log("TAP version 13") var count = 0 function test (list, expect) { count++ var actual = abbrev(list) assert.deepEqual(actual, expect, "abbrev("+util.inspect(list)+") === " + util.inspect(expect) + "\n"+ "actual: "+util.inspect(actual)) actual = abbrev.apply(exports, list) assert.deepEqual(abbrev.apply(exports, list), expect, "abbrev("+list.map(JSON.stringify).join(",")+") === " + util.inspect(expect) + "\n"+ "actual: "+util.inspect(actual)) console.log('ok - ' + list.join(' ')) } test([ "ruby", "ruby", "rules", "rules", "rules" ], { rub: 'ruby' , ruby: 'ruby' , rul: 'rules' , rule: 'rules' , rules: 'rules' }) test(["fool", "foom", "pool", "pope"], { fool: 'fool' , foom: 'foom' , poo: 'pool' , pool: 'pool' , pop: 'pope' , pope: 'pope' }) test(["a", "ab", "abc", "abcd", "abcde", "acde"], { a: 'a' , ab: 'ab' , abc: 'abc' , abcd: 'abcd' , abcde: 'abcde' , ac: 'acde' , acd: 'acde' , acde: 'acde' }) console.log("1..%d", count)