Created
March 26, 2017 13:32
-
-
Save vordan/9e7c332e2421b3eca6da0cbfa9760dea to your computer and use it in GitHub Desktop.
nzBool function
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
function nzBool(val, def_val) { | |
var ret_val = val; | |
if (typeof def_val == "undefined" || def_val === null || def_val.length === 0) { | |
def_val = false; | |
} | |
if (typeof(val) == "undefined" || val === null || val.length === 0) | |
ret_val = def_val; | |
else if (typeof(val) == 'number') | |
ret_val = val == 1; | |
else if (typeof(val) == 'string') | |
ret_val = val == '1' || val == 'true'; | |
else if (typeof(val) == 'boolean') | |
ret_val = val; | |
else | |
ret_val = def_val; | |
return ret_val; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment