Skip to content

Instantly share code, notes, and snippets.

@gwa
Created September 18, 2013 08:58
Show Gist options
  • Save gwa/6606490 to your computer and use it in GitHub Desktop.
Save gwa/6606490 to your computer and use it in GitHub Desktop.
javascript string to boolean function.
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