# yn

> Parse yes/no like values

Latest version **5.1.0** (published 2025-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install yn
pnpm add yn
yarn add yn
bun add yn
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2025-08-22 |
| First published | 2014-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 274 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | yn, yes, no, cli, prompt, validate, input, answer, true, false, parse, lenient |

## Links

- npm: https://www.npmjs.com/package/yn
- Repository: https://github.com/sindresorhus/yn
- Homepage: https://github.com/sindresorhus/yn#readme
- Issues: https://github.com/sindresorhus/yn/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/yn

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 5.1.0 (latest) — 2025-08-22
- 5.0.0 — 2021-08-14
- 4.0.0 — 2019-12-01
- 3.1.1 — 2019-07-30
- 3.1.0 — 2019-04-06
- 3.0.0 — 2018-12-08
- 2.0.0 — 2017-05-12
- 1.3.0 — 2017-05-08
- 1.2.0 — 2015-09-15
- 1.1.0 — 2014-10-10
- 1.0.0 — 2014-08-06

## README

# yn

> Parse yes/no like values

Useful for validating answers of a CLI prompt.

---

The following case-insensitive values are recognized:

```js
'y', 'yes', 't', 'true', true, '1', 1, 'n', 'no', 'f', 'false', false, '0', 0, 'on', 'off'
```

*Enable lenient mode to gracefully handle typos.*

## Install

```sh
npm install yn
```

## Usage

```js
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.

---
_Source: https://npm.io/package/yn · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
