chek
Version:
Minimal utility for checking types, working with arrays and objects.
35 lines (34 loc) • 1.38 kB
TypeScript
/**
* Cast Type
* Attempts to cast to specified type.
*
* @param val the value to be cast.
* @param type the type to cast to.
* @param def optional default value to return on null.
*/
export declare function castType<T>(val: any, type: any, def?: any): T;
/**
* Get Type
* Gets the type of the provided value.
*
* Value Type Strict
* -------------------------------------------------
* {} literal object
* true boolean boolean
* 'true' boolean string
* 25 integer number
* 25.5 float number
* new Date() date date
* '01/01/2017' date string
* RegExp regexp regexp
* '/^test/g' regexp string
* null null null
* function() {} function function
* [] array array
* 'some string' string string
*
* @param val the object to get type from.
* @param strict when true returns the strict type see examples.
* @param def the optional string name for unknown types.
*/
export declare function getType(val: any, strict?: boolean | string, def?: string): any;