
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
The yn package is a simple yet powerful utility for parsing yes/no like values. It can be used to convert various types of user inputs into boolean values. This is particularly useful for handling configurations, environment variables, or any input that requires a boolean interpretation.
Basic parsing
This demonstrates basic parsing of yes/no like values into booleans. It shows how 'y', 'NO', true, and false are interpreted.
const yn = require('yn');
console.log(yn('y')); // true
console.log(yn('NO')); // false
console.log(yn(true)); // true
console.log(yn(false)); // false
Parsing with options
This shows how to use options to control the parsing behavior, such as setting a default value or enabling lenient parsing for more flexible yes values.
const yn = require('yn');
console.log(yn('y', { default: false })); // true
console.log(yn('abracadabra', { default: false })); // false
console.log(yn(null, { default: true })); // true
console.log(yn('yes', { lenient: true })); // true
Handling numeric truthy/falsy values
Demonstrates yn's ability to interpret '1' as true and '0' as false, which is useful for numeric representations of boolean values.
const yn = require('yn');
console.log(yn('1')); // true
console.log(yn('0')); // false
Similar to yn, the boolean package is designed to convert various types of values into booleans. However, it focuses more on a broader range of truthy and falsy values without the specific emphasis on yes/no strings.
This package offers functionality similar to yn by converting strings to boolean values. It differs in its approach to parsing and the range of strings it considers to be true or false.
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.
$ npm install yn
import yn from '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
.
Type: unknown
The value that should be converted.
Type: object
Type: boolean
Default: false
Use a key distance-based score to leniently accept typos of yes
and no
.
Type: boolean
Default: undefined
The default value if no match was found.
FAQs
Parse yes/no like values
The npm package yn receives a total of 12,311,357 weekly downloads. As such, yn popularity was classified as popular.
We found that yn demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.