Security News
The Unpaid Backbone of Open Source: Solo Maintainers Face Increasing Security Demands
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
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
Enable lenient mode to gracefully handle typos.
$ npm install yn
const yn = require('yn');
yn('y');
//=> true
yn('NO');
//=> false
yn(true);
//=> true
yn('abomasum');
//=> null
yn('abomasum', {default: false});
//=> false
yn('mo', {lenient: true});
//=> false
Unrecognized values return null
.
Type: any
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: null
Default value if no match was found.
MIT © Sindre Sorhus
FAQs
Parse yes/no like values
The npm package yn receives a total of 16,509,524 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
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.
Security News
A developer is accusing Tencent of violating the GPL by modifying a Python utility and changing its license to BSD, highlighting the importance of copyleft compliance.