Last active
July 1, 2024 00:12
-
-
Save guzmanfg/9fb983ffdb5bc95a1e2a8a0d7225531e to your computer and use it in GitHub Desktop.
Parse boolean values (accepts any truthy or falsy values)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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