Created
May 6, 2017 14:40
-
-
Save brian-lim-42/bfb431073341c581fdb028d7abd81535 to your computer and use it in GitHub Desktop.
JavaScript Type Handling
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
class Type { | |
static isBoolean(val) { | |
return typeof(val) === 'boolean'; | |
} | |
static isNull(val) { | |
return val === null; | |
} | |
static isUndefined(val) { | |
return typeof(val) === 'undefined'; | |
} | |
static isNumber(val) { | |
return typeof(val) === 'number'; | |
} | |
static isString(val) { | |
return typeof(val) === 'string'; | |
} | |
static isSymbol(val) { | |
return typeof(val) === 'symbol'; | |
} | |
static isPrimitive(val) { | |
return Type.isBoolean(val) || | |
Type.isNull(val) || | |
Type.isUndefined(val) || | |
Type.isNumber(val) || | |
Type.isString(val) || | |
Type.isSymbol(val); | |
} | |
static isObjectLiteral(val) { | |
return typeof(val) === 'object' && val !== null; | |
} | |
static isArray(val) { | |
return Array.isArray(val); | |
} | |
static isSet(val) { | |
return val !== null && typeof(val) !== 'undefined'; | |
} | |
static isEmptyString(val) { | |
return val === ''; | |
} | |
} | |
module.exports = Type; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment