Created
September 18, 2014 02:38
-
-
Save kostasx/361da6eca0480d57c97e to your computer and use it in GitHub Desktop.
Javascript boolean caster
This file contains 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
/* | |
* Convert values: 1, 0, true, false, "1", "0", "true", "false", "TRUE", "FALSE", "True", "False" | |
* "ON", "OFF", "On", "Off", negative numbers, positive numbers, to booleans with a single JS line. | |
* Easily extensible with new truthy values. | |
*/ | |
function checkBool(val){ | |
return ({1:1,true:1,on:1,yes:1}[(((typeof val !=="number")?val:(val>0))+"").toLowerCase()])?true:false; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment