Parse yes/no like values
Useful for validating answers of a CLI prompt.
The following case-insensitive values are recognized:
'y', 'yes', 'true', true, 'n', 'no', 'false', false
Enable lenient mode to gracefully handle typos.
$ npm install --save yn
var yn = require('yn');
yn('y');
//=> true
yn('NO');
//=> false
yn(true);
//=> true
yn('abomasum');
//=> null
// lenient mode will use a key distance-based score
// to leniently accept typos of "yes" and "no"
yn('mo', {lenient: true});
//=> false
Unrecognized values return null
.
MIT © Sindre Sorhus