Skip to content

Instantly share code, notes, and snippets.

@guzmanfg
Last active July 1, 2024 00:12
Show Gist options
  • Save guzmanfg/9fb983ffdb5bc95a1e2a8a0d7225531e to your computer and use it in GitHub Desktop.
Save guzmanfg/9fb983ffdb5bc95a1e2a8a0d7225531e 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