yn
Parse yes/no like values
Last updated 10 months ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install yn 
SYNC missed versions from official npm registry.

yn Build Status

Parse yes/no like values

Useful for validating answers of a CLI prompt.


The following case-insensitive values are recognized:

'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

const yn = require('yn');

yn('y');
//=> true

yn('NO');
//=> false

yn(true);
//=> true

yn('abomasum');
//=> undefined

yn('abomasum', {default: false});
//=> false

yn('mo', {lenient: true});
//=> false

Unrecognized values return undefined.

API

yn(input, options?)

input

Type: unknown

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

Default value if no match was found.

Current Tags

  • 4.0.0                                ...           latest (10 months ago)

9 Versions

  • 4.0.0                                ...           10 months ago
  • 3.1.1                                ...           a year ago
  • 3.1.0                                ...           a year ago
  • 3.0.0                                ...           2 years ago
  • 2.0.0                                ...           3 years ago
  • 1.3.0                                ...           3 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 4
This Week 29,410
This Month 198,060
Last Day 9,262
Last Week 61,206
Last Month 249,715
Dependencies (0)
None
Dev Dependencies (3)
Dependents (164)

Copyright 2014 - 2016 © taobao.org |