Skip to content

Instantly share code, notes, and snippets.

@Uvacoder
Forked from DavidWells/string-to-boolean.js
Created January 2, 2022 01:40
Show Gist options
  • Select an option

  • Save Uvacoder/3f96f752ed0f6ce8ebe20f41f1fc02d5 to your computer and use it in GitHub Desktop.

Select an option

Save Uvacoder/3f96f752ed0f6ce8ebe20f41f1fc02d5 to your computer and use it in GitHub Desktop.
Convert string, number to boolean value
function cleanBooleanParam(value) {
switch(value.toString().toLowerCase()) {
case "true":
case "on":
case "yes":
case "1":
return true;
case "false":
case "off":
case "no":
case "0":
return false;
default:
return value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment