@js-util/is-trueish
v1.0.0
Published
A very relaxed varient of `=== true`. Validate that the given param is true, 'true', 1, or '1'
Downloads
4
Readme
Is Trueish
A very relaxed varient of === true
. Validate that the given param is true, 'true', 1, or '1'
npm install
npm install --save @js-util/is-trueish
Example usage
// Importing the module
const isTrueish = require("@js-util/is-trueish");
// Validate if isTrueish
if( isTrueish(someConfig) ) {
// does something
}
Its code
/**
* Returns true if the given value is any of the following strictly
*
* - true
* - "true"
* - 1
* - "1"
*
* @param {*} val to evaluate
* @return {boolean} true/false accordingly
*/
function isTrueish(val) {
return val === true || val === 1 || val === "1" || val === "true"
}
// Export the function
module.exports = isTrueish;