Created
June 13, 2019 03:05
-
-
Save nhalstead/b1c2d569f5b22b47452ee4546c2e843a to your computer and use it in GitHub Desktop.
Turn `"true"`. `"yes"`, `"1"` into a true or false value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Truthy, Extends the Normal Truthy and makes it only true values. | |
* Normal Truthy will be true if the value is defined. | |
* | |
* @author Noah Halstead <[email protected]> | |
* @param {string|number|boolean} value Something the Evaluate for the "TRUE" value. | |
* @return boolean If the Value is a "TRUE" value. | |
*/ | |
function truthy(value){ | |
if (value === undefined) return false; | |
if (!["string", "number", "boolean"].includes(typeof value)) return false; | |
if(typeof value == "string") value = value.toLowerCase(); | |
if(value === "true" || value === "yes" || value === true || value === 1 || value === "1") return true; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment