read-boolean
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

read-boolean

NPM TypeScript Coverage Status

A simple utility for parsing boolean values from strings.

If I should maintain this repo, please ⭐️ GitHub stars

DM me on Twitter if you have questions or suggestions. Twitter


About

Installation

yarn add read-boolean
npm install read-boolean
pnpm add read-boolean

Usage

import { readBoolean } from "read-boolean";

readBoolean("true"); // true
readBoolean("false"); // false
readBoolean("maybe"); // undefined
readBoolen(undefined); // undefined

Options

An options argument is also provided, which allows for more control over the parsing.

If extended is set to true, the following list of values will be accepted:

["true", "t", "yes", "y", "1"]
["false", "f", "no", "n", "0"]

If strict is set to true, values must match exactly. Otherwise, the value will be converted to lowercase before being compared.

readBoolean("yes", { extended: true }); // true
readBoolean("no", { extended: true }); // false

readBoolean("true", { strict: true }); // true
readBoolean("TRUE", { strict: true }); // undefined

readBoolean("yes", { strict: true, extended: true }); // true
readBoolean("YES", { strict: true, extended: true }); // undefined

Dev Dependencies

  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.

License license

MIT - MIT License

Package Sidebar

Install

npm i read-boolean

Weekly Downloads

33

Version

2.0.0

License

MIT

Unpacked Size

6.41 kB

Total Files

8

Last publish

Collaborators

  • bconnorwhite