Module: util/checkType
Functions
checkType
▸ checkType(object
, key
, type
, nullable?
, defaultValue?
): any
Checks a key if an object for a specified type using the typeof operator. If type is "string" will also check, the value is not empty.
If nullable and a default is given, this will be returned, if the field is undefined (NOT if the type check was unsuccessful)
Parameters
Name | Type | Description |
---|---|---|
object | object | The object in which to check the key |
key | string | The key in the object in which to check the type |
type | "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function" | The Expected type of the field. Must be one of the types returned by the typeof operator |
nullable? | boolean | Set to true if the field may be undefined |
defaultValue? | any | If undefined, this value will be returned instead |
Returns
any
The field value if the type check was successful, if undefined and nullable the default value
Throws
Error with according message if the type check wasn't successful