Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
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
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.