2.0.0 • Published 1 year ago

read-boolean v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

If I should maintain this repo, please ⭐️

DM me on Twitter if you have questions or suggestions.


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
  • autorepo: Autorepo abstracts away your dev dependencies, providing a single command to run all of your scripts.

MIT - MIT License