Created
June 26, 2013 11:12
-
-
Save simonpioli/5866633 to your computer and use it in GitHub Desktop.
Converts a string to boolean in Javascript.
Useful if passing settings through data- attributes.
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(string){ | |
switch(string.toLowerCase()){ | |
case "true": case "yes": case "1": return true; | |
case "false": case "no": case "0": case "": return false; | |
default: return Boolean(string); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment