2.0.2 • Published 3 years ago
@wkovacs64/booleanize v2.0.2
@wkovacs64/booleanize
A small utility to coerce a value to its boolean equivalent.
Installation
npm install @wkovacs64/booleanizeUsage
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=falseimport { 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.