Skip to content

Instantly share code, notes, and snippets.

@db
Last active September 25, 2015 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save db/986496 to your computer and use it in GitHub Desktop.
Save db/986496 to your computer and use it in GitHub Desktop.
Converts string based values to boolean.
var toBool = function(value) {
switch (value.toLowerCase()) {
case "true":
case "yes":
case "y":
case "o":
case "off":
case "1":
return true;
case "false":
case "no":
case "n":
case "x":
case "on":
case "0":
case "-1":
case null:
return false;
default:
return Boolean(value);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment