Détail du package

read-boolean

bconnorwhite121MIT2.0.0

A simple utility for parsing boolean values from strings.

read, parse, boolean, string

readme

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

changelog

2.0.0 (2023-01-10)

1.0.0 (2021-07-02)