Socket
Book a DemoInstallSign in
Socket

yn

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yn

Parse yes/no like values

latest
Source
npmnpm
Version
5.1.0
Version published
Weekly downloads
13M
-54.53%
Maintainers
1
Weekly downloads
 
Created
Source

yn

Parse yes/no like values

Useful for validating answers of a CLI prompt.

The following case-insensitive values are recognized:

'y', 'yes', 't', 'true', true, '1', 1, 'n', 'no', 'f', '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

yn

FAQs

Package last updated on 22 Aug 2025

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