@wkovacs64/booleanize
v2.0.2
Published
Small utility to coerce a value to its boolean equivalent
Downloads
3
Readme
@wkovacs64/booleanize
A small utility to coerce a value to its boolean equivalent.
Installation
npm install @wkovacs64/booleanize
Usage
The primary purpose of this package is to deal with environment variables
received as strings. For example, SOME_CONDITIONAL=false
will be truthy if you
just pass it to the Boolean
constructor as it comes through as a non-empty
string. Instead, pass it to booleanize
and you will get the value back that I
expect. Please note that it may not be the value YOU expect, but I created this
primarily for myself. 🙂
Basically, the following strings are considered falsy:
'null'
'undefined'
'false'
'no'
'0'
Example
# .env
SOME_CONDITIONAL=false
import { booleanize } from '@wkovacs64/booleanize';
Boolean(process.env.SOME_CONDITIONAL); // true 😕
booleanize(process.env.SOME_CONDITIONAL); // false 😊
License
This module is distributed under the MIT License.