Skip to content

Instantly share code, notes, and snippets.

@hogash
Created July 14, 2016 15:22
Show Gist options
  • Save hogash/2f75b4cd0f7048b86e1b961029f6acb5 to your computer and use it in GitHub Desktop.
Save hogash/2f75b4cd0f7048b86e1b961029f6acb5 to your computer and use it in GitHub Desktop.
// helper functions
function is_null(a) {
return (a === null);
}
function is_undefined(a) {
return (is_null(a) || typeof a == 'undefined' || a === '' || a === 'undefined');
}
function is_array(a) {
return (a instanceof Array);
}
function is_jquery(a) {
return (a instanceof jQuery);
}
function is_object(a) {
return ((a instanceof Object || typeof a == 'object') && !is_null(a) && !is_jquery(a) && !is_array(a) && !is_function(a));
}
function is_number(a) {
return ((a instanceof Number || typeof a == 'number') && !isNaN(a));
}
function is_string(a) {
return ((a instanceof String || typeof a == 'string') && !is_undefined(a) && !is_true(a) && !is_false(a));
}
function is_function(a) {
return (a instanceof Function || typeof a == 'function');
}
function is_boolean(a) {
return (a instanceof Boolean || typeof a == 'boolean' || is_true(a) || is_false(a));
}
function is_true(a) {
return (a === true || a === 'true');
}
function is_false(a) {
return (a === false || a === 'false');
}
function is_percentage(x) {
return (is_string(x) && x.slice(-1) == '%');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment