Created
September 18, 2013 08:58
-
-
Save gwa/6606490 to your computer and use it in GitHub Desktop.
javascript string to boolean function.
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
function stringToBoolean( value ) { | |
switch (typeof value) { | |
case "object": | |
case "string": return (/(true|1)/i).test(value); | |
case "number": return !!value; | |
case "boolean": return value; | |
case "undefined": return null; | |
default: return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment