Skip to content

bconnorwhite/read-boolean

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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