@gik/tools-checker v0.0.11
@gik/tools-checker 0.0.11
A minimal type-checker for JavaScript purists. Part of our tools suite.
Contributors
Supported platforms
Table of contents
- checker A minimal type-checker for JavaScript purists.
- is Determine if given value really belongs to the corresponding type.
- objectEmpty
memberDetermine if an element is an object and has no keys - string
memberDetermines ifvalueis really a string. - number
memberDetermines ifvalueis really a number. - array
memberDetermines ifvalueis really an array. - function
memberDetermines ifvalueis really a function. - regexp
memberDetermines ifvalueis really a regexp. - boolean
memberDetermines ifvalueis really a boolean. - object
memberDetermines ifvalueis really an object.
- objectEmpty
- props
functionValidates properties of given object.
- is Determine if given value really belongs to the corresponding type.
- Types
checker
A minimal type-checker for JavaScript purists.
Members
is
Determine if given value really belongs to the corresponding type.
Members
objectEmpty
static property of
checker.is
Determine if an element is an object and has no keys
Parameters
Returns
boolean - Whether the object is empty or not.
string
static property of
checker.is
Determines if value is really a string.
Parameters
Returns
boolean - Wheter value is string or not.
number
static property of
checker.is
Determines if value is really a number.
Parameters
Returns
boolean - Wheter value is number or not.
array
static property of
checker.is
Determines if value is really an array.
Parameters
Returns
boolean - Wheter value is array or not.
function
static property of
checker.is
Determines if value is really a function.
Parameters
Returns
boolean - Wheter value is function or not.
regexp
static property of
checker.is
Determines if value is really a regexp.
Parameters
Returns
boolean - Wheter value is regexp or not.
boolean
static property of
checker.is
Determines if value is really a boolean.
Parameters
Returns
boolean - Wheter value is boolean or not.
object
static property of
checker.is
Determines if value is really an object.
Parameters
Returns
boolean - Wheter value is object or not.
props
static method of
checker
Validates properties of given object.
Parameters
Returns
Object - The validated subject extended with default values (when applies).
Throws
CheckerPropParamErrorwhen invalid parameters are passed.CheckerPropDefErrorwhen a type definition is invalid.CheckerPropDefTypeErrorwhen a type defintiion is not supported.CheckerPropReqErrorwhen a required property is not found.CheckerPropTypeErrorwhen a property does not match the defintion.
Example
const subject = { a: 1, b: 'hello' z: undefined };
const result = props(subject, {
a: { type:'number', required:true },
b: 'string',
c: { default: new Date() },
d: { required: false, default: null, map: value => [value, true] },
})
// result:
// { a: 1, b: 'hello', c: '1981-06-23 10:06:08', d: [null, true], z: undefined }Types
Members
CheckerPropParamError
static typedef of
Types
A definition prop was sent, but it was invalid.
CheckerPropDefError
static typedef of
Types
The specified type is not a supported primitive.
CheckerPropDefTypeError
static typedef of
Types
A required property was not found in subject.
CheckerPropReqError
static typedef of
Types
A property didn't have the correct type.