-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
886 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
This software is dual-licensed under the ISC and MIT licenses. | ||
You may use this software under EITHER of the following licenses. | ||
|
||
---------- | ||
|
||
The 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. | ||
|
||
---------- | ||
|
||
Copyright Isaac Z. Schlueter and Contributors | ||
All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module.exports = abbrev | ||
|
||
function abbrev (...args) { | ||
let list = args.length === 1 || Array.isArray(args[0]) ? args[0] : args | ||
|
||
for (let i = 0, l = list.length; i < l; i++) { | ||
list[i] = typeof list[i] === 'string' ? list[i] : String(list[i]) | ||
} | ||
|
||
// sort them lexicographically, so that they're next to their nearest kin | ||
list = list.sort(lexSort) | ||
|
||
// walk through each, seeing how much it has in common with the next and previous | ||
const abbrevs = {} | ||
let prev = '' | ||
for (let ii = 0, ll = list.length; ii < ll; ii++) { | ||
const current = list[ii] | ||
const next = list[ii + 1] || '' | ||
let nextMatches = true | ||
let prevMatches = true | ||
if (current === next) { | ||
continue | ||
} | ||
let j = 0 | ||
const cl = current.length | ||
for (; j < cl; j++) { | ||
const 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 (let a = current.slice(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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"name": "abbrev", | ||
"version": "2.0.0", | ||
"description": "Like ruby's abbrev module, but in js", | ||
"author": "GitHub Inc.", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "tap", | ||
"lint": "eslint \"**/*.js\"", | ||
"postlint": "template-oss-check", | ||
"template-oss-apply": "template-oss-apply --force", | ||
"lintfix": "npm run lint -- --fix", | ||
"snap": "tap", | ||
"posttest": "npm run lint" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/npm/abbrev-js.git" | ||
}, | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@npmcli/eslint-config": "^4.0.0", | ||
"@npmcli/template-oss": "4.8.0", | ||
"tap": "^16.3.0" | ||
}, | ||
"tap": { | ||
"nyc-arg": [ | ||
"--exclude", | ||
"tap-snapshots/**" | ||
] | ||
}, | ||
"files": [ | ||
"bin/", | ||
"lib/" | ||
], | ||
"engines": { | ||
"node": "^14.17.0 || ^16.13.0 || >=18.0.0" | ||
}, | ||
"templateOSS": { | ||
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.", | ||
"version": "4.8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
The 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env node | ||
const nopt = require('../lib/nopt') | ||
const path = require('path') | ||
console.log('parsed', nopt({ | ||
num: Number, | ||
bool: Boolean, | ||
help: Boolean, | ||
list: Array, | ||
'num-list': [Number, Array], | ||
'str-list': [String, Array], | ||
'bool-list': [Boolean, Array], | ||
str: String, | ||
clear: Boolean, | ||
config: Boolean, | ||
length: Number, | ||
file: path, | ||
}, { | ||
s: ['--str', 'astring'], | ||
b: ['--bool'], | ||
nb: ['--no-bool'], | ||
tft: ['--bool-list', '--no-bool-list', '--bool-list', 'true'], | ||
'?': ['--help'], | ||
h: ['--help'], | ||
H: ['--help'], | ||
n: ['--num', '125'], | ||
c: ['--config'], | ||
l: ['--length'], | ||
f: ['--file'], | ||
}, process.argv, 2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/* istanbul ignore next */ | ||
module.exports = process.env.DEBUG_NOPT || process.env.NOPT_DEBUG | ||
// eslint-disable-next-line no-console | ||
? (...a) => console.error(...a) | ||
: () => {} |
Oops, something went wrong.