Last active
December 12, 2016 18:59
-
-
Save olaferlandsen/42149aabdb9082214fab7b20120ded0a to your computer and use it in GitHub Desktop.
Check
This file contains 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 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