Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/watson/normalize-bool
Converts strings representing an on/off-state to booleans
https://github.com/watson/normalize-bool
Last synced: about 2 months ago
JSON representation
Converts strings representing an on/off-state to booleans
- Host: GitHub
- URL: https://github.com/watson/normalize-bool
- Owner: watson
- License: mit
- Created: 2017-03-14T08:32:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-03-14T08:37:28.000Z (over 7 years ago)
- Last Synced: 2024-07-06T01:38:28.752Z (3 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# normalize-bool
Converts strings representing an on/off-state to booleans. Falsy values
and a whitelist of keywords are converted to the boolean `false`.
Everything else is considered `true`.Useful for normalizing environment variables and other user-input to
booleans.[![Build status](https://travis-ci.org/watson/normalize-bool.svg?branch=master)](https://travis-ci.org/watson/normalize-bool)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)## Installation
```
npm install normalize-bool --save
```## Usage
```js
var bool = require('normalize-bool')console.log(bool('no')) // => false
console.log(bool('yes')) // => true
```## API
### `var bool = normalizeBool(value)`
Converts the input value to a boolean. Falsy values and a whitelist of
keywords are converted to the boolean `false`. Everything else is
considered `true`.The following values are considered `false`:
- All normal [falsy values](https://developer.mozilla.org/en-US/docs/Glossary/Falsy)
- `'0'`
- `'false'`
- `'no'`
- `'off'`
- `'disabled'`## License
MIT