A small utility to coerce a value to its boolean equivalent.
npm install @wkovacs64/booleanize
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'
# .env
SOME_CONDITIONAL=false
import { booleanize } from '@wkovacs64/booleanize';
Boolean(process.env.SOME_CONDITIONAL); // true 😕
booleanize(process.env.SOME_CONDITIONAL); // false 😊
This module is distributed under the MIT License.