Skip to content

Instantly share code, notes, and snippets.

@brian-lim-42
Created May 6, 2017 14:40
Show Gist options
  • Save brian-lim-42/bfb431073341c581fdb028d7abd81535 to your computer and use it in GitHub Desktop.
Save brian-lim-42/bfb431073341c581fdb028d7abd81535 to your computer and use it in GitHub Desktop.
JavaScript Type Handling
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