Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sindresorhus/yn
Parse yes/no like values
https://github.com/sindresorhus/yn
Last synced: 6 days ago
JSON representation
Parse yes/no like values
- Host: GitHub
- URL: https://github.com/sindresorhus/yn
- Owner: sindresorhus
- License: mit
- Created: 2014-08-06T23:42:30.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2022-07-08T13:20:11.000Z (over 2 years ago)
- Last Synced: 2024-12-06T14:06:04.327Z (6 days ago)
- Language: JavaScript
- Size: 30.3 KB
- Stars: 268
- Watchers: 9
- Forks: 20
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Funding: .github/funding.yml
- License: license
- Security: .github/security.md
Awesome Lists containing this project
- awesome-nodejs-cn - yn - 将包含 yes/no 语义的字符串解析为布尔值 (包 / 命令行工具)
- awesome-nodejs-cn - yn - **star:266** 解析yes/no 类似的值 (包 / 命令行实用工具)
- awesome-nodejs - yn - Parse yes/no like values. (Packages / Command-line utilities)
- awesome-nodejs - yn - Parse yes/no like values - ★ 120 (Command-line utilities)
- awesome-node - yn - Parse yes/no like values. (Packages / Command-line utilities)
- awesome-nodejs-cn - yn - 解析 yes/no 像值. (目录 / 命令行工具)
README
# 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, 'on', 'off'
```*Enable lenient mode to gracefully handle typos.*
## Install
```
$ npm install yn
```## Usage
```js
import yn from 'yn';yn('y');
//=> trueyn('NO');
//=> falseyn(true);
//=> trueyn('abomasum');
//=> undefinedyn('abomasum', {default: false});
//=> falseyn('mo', {lenient: true});
//=> false
```Unrecognized values return `undefined`.
## API
### yn(input, options?)
#### input
Type: `unknown`
The value that should be converted.
#### options
Type: `object`
##### lenient
Type: `boolean`\
Default: `false`Use a key distance-based score to leniently accept typos of `yes` and `no`.
##### default
Type: `boolean`\
Default: `undefined`The default value if no match was found.