Skip to content

Instantly share code, notes, and snippets.

@shakahl
Forked from guzmanfg/parseBool.js
Created July 1, 2024 00:12
Show Gist options
  • Save shakahl/7d08e1baaf190597a142702bfc835523 to your computer and use it in GitHub Desktop.
Save shakahl/7d08e1baaf190597a142702bfc835523 to your computer and use it in GitHub Desktop.
Parse boolean values (accepts any truthy or falsy values)
function parseBool (value){
var isEmptyString = (typeof value === "string" && value.length <= 0);
var isFalsy = typeof value === "undefined" || isEmptyString;
return !isFalsy && !!JSON.parse(value);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment