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
Maintainers
1
Weekly downloads
14,328,545
decreased by-26.42%

Weekly downloads

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

Last updated on 14 Aug 2021

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