Created
January 26, 2017 14:07
-
-
Save pablo-sg-pacheco/813bc8a4d7a1270f2dea91a2ac2ba206 to your computer and use it in GitHub Desktop.
Convert a string to Boolean.
It handles 'True' and 'False' Strings written as Lowercase or Uppercase.
It also detects '0' and '1' Strings
This file contains hidden or 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
/** | |
* Convert a string to Boolean. | |
* It handles 'True' and 'False' Strings written as Lowercase or Uppercase. | |
* It also detects '0' and '1' Strings | |
*/ | |
function convertToBoolean(variable){ | |
variable = variable.toLowerCase(); | |
return Boolean(variable == true | variable === 'true'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment