@pivoto/core
Version:

111 lines (86 loc) • 2.25 kB
text/typescript
export function is(v: any): boolean {
return !!v;
}
export function not(v: any): boolean {
return !v;
}
export function isDef(v: any): boolean {
return v !== undefined && v !== null;
}
export function notDef(v: any): boolean {
return v === undefined || v === null;
}
export function isTrue(v: any): boolean {
return v === true;
}
export function isFalse(v: any): boolean {
return v === false;
}
export function isPrimitive(v: any): boolean {
return (
typeof v === 'string' ||
typeof v === 'number' ||
typeof v === 'symbol' ||
typeof v === 'boolean'
)
}
export function getType(val: any): string {
return Object.prototype.toString.call(val).slice(8, -1)
}
export function isString(val: any): boolean {
return getType(val) === 'String'
}
export function isNumber(val: any): boolean {
return getType(val) === 'Number'
}
export function isBoolean(val: any): boolean {
return getType(val) === 'Boolean'
}
export function isFunction(val: any): boolean {
return getType(val) === 'Function'
}
export function isNull(val: any): boolean {
return getType(val) === 'Null'
}
export function isUndefined(val: any): boolean {
return getType(val) === 'Undefined'
}
export function isObject(val: any): boolean {
return getType(val) === 'Object'
}
export function isArray(val: any): boolean {
// return getType(val) === 'Array'
return Array.isArray(val)
}
export function isRegExp(val: any): boolean {
return getType(val) === 'RegExp'
}
export function isDate(val: any): boolean {
return getType(val) === 'Date'
}
export function isError(val: any): boolean {
return getType(val) === 'Error'
}
export function isSymbol(val: any): boolean {
return getType(val) === 'Symbol'
}
export function isSet(val: any): boolean {
return getType(val) === 'Set'
}
export function isMap(val: any): boolean {
return getType(val) === 'Map'
}
export function isPromise(val: any): boolean {
return getType(val) === 'Promise'
/*return (
isDef(val) &&
typeof val.then === 'function' &&
typeof val.catch === 'function'
)*/
}
export function isObjectOrArray(value: any): boolean {
return isObject(value) || isArray(value)
}
export function isNumeric(value: any): boolean {
return !isNaN(parseFloat(value)) && isFinite(value)
}