Open
Description
Possibly es5-ext
can be split into two packages, that will handle following scopes
1. normalization & validation
For some supported coercible primitive types it may have following functions
coerce
- Resolves a valid value of given type and returns it. If valid value can't be resolved returnsnull
ensure
- Resolves a valid value of given type and returns it. If valid value can't be resolved throwsTypeError
exception. Supports following options:optional: false
- If value isnull
orundefined
thenensure
returnsnull
(doesn't throw)errorClass: TypeError
- Error class to useerrorMessage: "%v is not a {type}"
- Eventual error message to override
is
- Is value a valid value of given type
For some duck-typed object types it may have following functions
is-like
- Returns true if value matches contractensure
- Returns value if it matches contract, otherwise throwsTypeError
exception
For some other object types it may have following functions
is
- Returns true if value is an object of given typeensure
- Returns value if it's object of given type, otherwise throwsTypeError
exception
Example modules
value/is
(oris-value
)value/ensure
(orensure-value
)string/is
(oris-string
)string/coerce
(orstring-coerce
)string/ensure
(orstring-ensure
)number/is
(oris-number
)number/integer/ensure
(orensure-integer
)number/natural/ensure
(orensure-natural-number
)array/like/is
(oris-array-like
)array/like/ensure
array/is
(this may be omitted as it's directly served by nativeArray.isArray
)array/ensure
date/is
date/ensure
function/plain/is
(oris-plain-function
)iterable/is
(oris-iterable
)promise/is
promise/is-like
thenable/is
2. extensions
A standard library of extra functions and methods (including shims)