mirror of
https://github.com/cachix/install-nix-action.git
synced 2025-06-08 09:54:28 +00:00
v6
This commit is contained in:
parent
cd5893b2c6
commit
70742d22d9
6774 changed files with 1602535 additions and 1 deletions
65
node_modules/yn/index.d.ts
generated
vendored
Normal file
65
node_modules/yn/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,65 @@
|
|||
declare namespace yn {
|
||||
interface Options {
|
||||
/**
|
||||
Use a key distance-based score to leniently accept typos of `yes` and `no`.
|
||||
|
||||
@default false
|
||||
*/
|
||||
readonly lenient?: boolean;
|
||||
|
||||
/**
|
||||
Default value if no match was found.
|
||||
|
||||
@default null
|
||||
*/
|
||||
readonly default?: boolean | null;
|
||||
}
|
||||
|
||||
interface OptionsWithDefault extends Options {
|
||||
default: boolean;
|
||||
}
|
||||
}
|
||||
|
||||
declare const yn: {
|
||||
/**
|
||||
Parse yes/no like values.
|
||||
|
||||
The following case-insensitive values are recognized: `'y', 'yes', 'true', true, '1', 1, 'n', 'no', 'false', false, '0', 0`
|
||||
|
||||
@param input - Value that should be converted.
|
||||
@returns The parsed input if it can be parsed or the default value defined in the `default` option.
|
||||
|
||||
@example
|
||||
```
|
||||
import yn = require('yn');
|
||||
|
||||
yn('y');
|
||||
//=> true
|
||||
|
||||
yn('NO');
|
||||
//=> false
|
||||
|
||||
yn(true);
|
||||
//=> true
|
||||
|
||||
yn('abomasum');
|
||||
//=> null
|
||||
|
||||
yn('abomasum', {default: false});
|
||||
//=> false
|
||||
|
||||
yn('mo', {lenient: true});
|
||||
//=> false
|
||||
```
|
||||
*/
|
||||
(input: unknown, options: yn.OptionsWithDefault): boolean;
|
||||
(input: unknown, options?: yn.Options): boolean | null;
|
||||
|
||||
// TODO: Remove this for the next major release, refactor the whole definition to:
|
||||
// declare function yn(input: unknown, options: yn.OptionsWithDefault): boolean;
|
||||
// declare function yn(input: unknown, options?: yn.Options): boolean | null;
|
||||
// export = yn;
|
||||
default: typeof yn;
|
||||
};
|
||||
|
||||
export = yn;
|
33
node_modules/yn/index.js
generated
vendored
Normal file
33
node_modules/yn/index.js
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
const lenient = require('./lenient');
|
||||
|
||||
const yn = (input, options) => {
|
||||
input = String(input).trim();
|
||||
|
||||
options = Object.assign({
|
||||
lenient: false,
|
||||
default: null
|
||||
}, options);
|
||||
|
||||
if (options.default !== null && typeof options.default !== 'boolean') {
|
||||
throw new TypeError(`Expected the \`default\` option to be of type \`boolean\`, got \`${typeof options.default}\``);
|
||||
}
|
||||
|
||||
if (/^(?:y|yes|true|1)$/i.test(input)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (/^(?:n|no|false|0)$/i.test(input)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (options.lenient === true) {
|
||||
return lenient(input, options);
|
||||
}
|
||||
|
||||
return options.default;
|
||||
};
|
||||
|
||||
module.exports = yn;
|
||||
// TODO: Remove this for the next major release
|
||||
module.exports.default = yn;
|
105
node_modules/yn/lenient.js
generated
vendored
Normal file
105
node_modules/yn/lenient.js
generated
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
'use strict';
|
||||
|
||||
const YES_MATCH_SCORE_THRESHOLD = 2;
|
||||
const NO_MATCH_SCORE_THRESHOLD = 1.25;
|
||||
|
||||
const yMatch = new Map([
|
||||
[5, 0.25],
|
||||
[6, 0.25],
|
||||
[7, 0.25],
|
||||
['t', 0.75],
|
||||
['y', 1],
|
||||
['u', 0.75],
|
||||
['g', 0.25],
|
||||
['h', 0.25],
|
||||
['j', 0.25]
|
||||
]);
|
||||
|
||||
const eMatch = new Map([
|
||||
[2, 0.25],
|
||||
[3, 0.25],
|
||||
[4, 0.25],
|
||||
['w', 0.75],
|
||||
['e', 1],
|
||||
['r', 0.75],
|
||||
['s', 0.25],
|
||||
['d', 0.25],
|
||||
['f', 0.25]
|
||||
]);
|
||||
|
||||
const sMatch = new Map([
|
||||
['q', 0.25],
|
||||
['w', 0.25],
|
||||
['e', 0.25],
|
||||
['a', 0.75],
|
||||
['s', 1],
|
||||
['d', 0.75],
|
||||
['z', 0.25],
|
||||
['x', 0.25],
|
||||
['c', 0.25]
|
||||
]);
|
||||
|
||||
const nMatch = new Map([
|
||||
['h', 0.25],
|
||||
['j', 0.25],
|
||||
['k', 0.25],
|
||||
['b', 0.75],
|
||||
['n', 1],
|
||||
['m', 0.75]
|
||||
]);
|
||||
|
||||
const oMatch = new Map([
|
||||
[9, 0.25],
|
||||
[0, 0.25],
|
||||
['i', 0.75],
|
||||
['o', 1],
|
||||
['p', 0.75],
|
||||
['k', 0.25],
|
||||
['l', 0.25]
|
||||
]);
|
||||
|
||||
function getYesMatchScore(value) {
|
||||
const [y, e, s] = value;
|
||||
let score = 0;
|
||||
|
||||
if (yMatch.has(y)) {
|
||||
score += yMatch.get(y);
|
||||
}
|
||||
|
||||
if (eMatch.has(e)) {
|
||||
score += eMatch.get(e);
|
||||
}
|
||||
|
||||
if (sMatch.has(s)) {
|
||||
score += sMatch.get(s);
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
function getNoMatchScore(value) {
|
||||
const [n, o] = value;
|
||||
let score = 0;
|
||||
|
||||
if (nMatch.has(n)) {
|
||||
score += nMatch.get(n);
|
||||
}
|
||||
|
||||
if (oMatch.has(o)) {
|
||||
score += oMatch.get(o);
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
module.exports = (input, options) => {
|
||||
if (getYesMatchScore(input) >= YES_MATCH_SCORE_THRESHOLD) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (getNoMatchScore(input) >= NO_MATCH_SCORE_THRESHOLD) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return options.default;
|
||||
};
|
9
node_modules/yn/license
generated
vendored
Normal file
9
node_modules/yn/license
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
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.
|
42
node_modules/yn/package.json
generated
vendored
Normal file
42
node_modules/yn/package.json
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"name": "yn",
|
||||
"version": "3.1.1",
|
||||
"description": "Parse yes/no like values",
|
||||
"license": "MIT",
|
||||
"repository": "sindresorhus/yn",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava && tsd"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"lenient.js",
|
||||
"index.d.ts"
|
||||
],
|
||||
"keywords": [
|
||||
"yn",
|
||||
"yes",
|
||||
"no",
|
||||
"cli",
|
||||
"prompt",
|
||||
"validate",
|
||||
"input",
|
||||
"answer",
|
||||
"true",
|
||||
"false",
|
||||
"parse",
|
||||
"lenient"
|
||||
],
|
||||
"devDependencies": {
|
||||
"ava": "^1.4.1",
|
||||
"tsd": "^0.7.2",
|
||||
"xo": "^0.24.0"
|
||||
}
|
||||
}
|
83
node_modules/yn/readme.md
generated
vendored
Normal file
83
node_modules/yn/readme.md
generated
vendored
Normal file
|
@ -0,0 +1,83 @@
|
|||
# yn [](https://travis-ci.org/sindresorhus/yn)
|
||||
|
||||
> Parse yes/no like values
|
||||
|
||||
Useful for validating answers of a CLI prompt.
|
||||
|
||||
---
|
||||
|
||||
The following case-insensitive values are recognized:
|
||||
|
||||
```js
|
||||
'y', 'yes', 'true', true, '1', 1, 'n', 'no', 'false', false, '0', 0
|
||||
```
|
||||
|
||||
*Enable lenient mode to gracefully handle typos.*
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install yn
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const yn = require('yn');
|
||||
|
||||
yn('y');
|
||||
//=> true
|
||||
|
||||
yn('NO');
|
||||
//=> false
|
||||
|
||||
yn(true);
|
||||
//=> true
|
||||
|
||||
yn('abomasum');
|
||||
//=> null
|
||||
|
||||
yn('abomasum', {default: false});
|
||||
//=> false
|
||||
|
||||
yn('mo', {lenient: true});
|
||||
//=> false
|
||||
```
|
||||
|
||||
Unrecognized values return `null`.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### yn(input, [options])
|
||||
|
||||
#### input
|
||||
|
||||
Type: `any`
|
||||
|
||||
Value that should be converted.
|
||||
|
||||
#### options
|
||||
|
||||
Type: `Object`
|
||||
|
||||
##### lenient
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `false`
|
||||
|
||||
Use a key distance-based score to leniently accept typos of `yes` and `no`.
|
||||
|
||||
##### default
|
||||
|
||||
Type: `boolean`<br>
|
||||
Default: `null`
|
||||
|
||||
Default value if no match was found.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
Loading…
Add table
Add a link
Reference in a new issue