Skip to content

Instantly share code, notes, and snippets.

@vordan
Created March 26, 2017 13:32
Show Gist options
  • Save vordan/9e7c332e2421b3eca6da0cbfa9760dea to your computer and use it in GitHub Desktop.
Save vordan/9e7c332e2421b3eca6da0cbfa9760dea to your computer and use it in GitHub Desktop.
nzBool function
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