You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

yn

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yn

Parse yes/no like values


Version published
Weekly downloads
16M
decreased by-18.64%
Maintainers
1
Install size
6.79 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

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.

Install

$ npm install yn

Usage

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.

API

yn(input, options?)

input

Type: unknown

The value that should be converted.

options

Type: object

lenient

Type: boolean
Default: false

Use a key distance-based score to leniently accept typos of yes and no.

default

Type: boolean
Default: undefined

The default value if no match was found.

Keywords

FAQs

Package last updated on 14 Aug 2021

Did you know?

Socket

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
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc