@deep-trace/boolean-like
v0.1.1
Published
Simple helper function to properly cast a value into boolean.
Readme
boolean-like
Simple helper function to cast a value into boolean.
npm install boolean-like| given value | casted value |
|------------:|:--------------|
| undefined | false |
| null | false |
| false | false |
| 0 | false |
| "" | false |
| "false" | false |
| true | true |
| 1 | true |
| "true" | true |
Usage
const blike = require('boolean-like')
const config = {
enabled: blike(process.env.IS_ENABLED || false)
}
if (!config.enabled) {
console.error('the variable was evaluated to `false`')
process.exit(1)
}
console.log('the variable was evaluated to `true`')$ IS_ENABLED=1 node ./sample.js
the variable was evaluated to `true`$ IS_ENABLED=false node ./sample.js
the variable was evaluated to `false`