Socket
Socket
Sign inDemoInstall

yn

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    yn

Parse yes/no like values


Version published
Weekly downloads
17M
decreased by-7.57%
Maintainers
1
Install size
2.18 kB
Created
Weekly downloads
 

Package description

What is yn?

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.

What are yn's main functionalities?

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

Other packages similar to yn

Readme

Source

yn Build Status

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

Install

$ npm install --save yn

Usage

var yn = require('yn');

yn('y');
//=> true

yn('NO');
//=> false

yn(true);
//=> true

yn('unicorn');
//=> null

Unrecognized values returns null.

License

MIT © Sindre Sorhus

Keywords

FAQs

Last updated on 06 Aug 2014

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc