Skip to content

Instantly share code, notes, and snippets.

@olaferlandsen
Last active December 12, 2016 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olaferlandsen/42149aabdb9082214fab7b20120ded0a to your computer and use it in GitHub Desktop.
Save olaferlandsen/42149aabdb9082214fab7b20120ded0a to your computer and use it in GitHub Desktop.
Check
//
function isNull (value) {
return value === null;
}
//
function isUndefined (value, strict) {
if (strict === true) return value === undefined;
return value == 'undefined';
}
//
function isObject (value) {
return null != value && toString.call(value) === '[object Object]';
}
//
function isArray (value) {
if (Array.isArray) return Array.isArray(value);
return value instanceof Array;
}
//
function isString (value) {
return typeof value === 'string';
}
//
function isInt (value, strict) {
if (strict === true && typeof value !== 'number') return false;
return Number(value) === value && value % 1 === 0;
}
//
function isFloat (value, strict) {
if (strict === true && typeof value !== 'number') return false;
return Number(value) === value && value % 1 !== 0;
}
//
function isDouble (value, strict) {
return isFloat(value, strict);
}
//
function isNumber (value, strict) {
return isFloat(value, strict) || isInt(value, strict);
}
//
function isNumeric (value, strict) {
return isNumber(value, strict);
}
//
function isEmpty (value) {
if (value === null || value === undefined) return true;
if (isArray(value)) return value.length == 0;
if (isString(value)) return value.length == 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment