yn
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
"yn" is a handy Node.js package used for parsing yes/no like values. It's particularly useful for validating answers from a command-line interface (CLI) prompt. The package recognizes case-insensitive values such as 'y', 'yes', 'true', '1', 'n', 'no', 'false', '0', 'on', 'off', and their Boolean and numeric equivalents.
You can install the "yn" package using the npm command npm install yn
. After you've installed the package, you can use it in your JavaScript code as follows:
// Import the yn package
import yn from 'yn';
// Using yn function to parse 'y'
yn('y'); // Returns true
// Using yn function to parse 'NO'
yn('NO'); // Returns false
// Using yn function to parse true
yn(true); // Returns true
// Parsing an unsupported string
yn('abomasum'); // Returns undefined
// Specifying a default return value when parsing fails
yn('abomasum', {default: false}); // Returns false
// Enabling lenient mode to handle typos
yn('mo', {lenient: true}); // Returns false
In the provided examples, unrecognized values return undefined
, unless a default value is specified in the options.
The documentation for the "yn" Node.js package can be found directly in the package's README file at the GitHub repository https://github.com/sindresorhus/yn. The documentation covers installation, usage instructions, and details of the API including the "yn" function and associated options.