Contains error throwing facilities for when a value doesn't match a type.
In addition gives you curried and uncurried versions of the multi arity functions included.
- Source:
Members
(static) exports.version
Properties:
Name | Type | Description |
---|---|---|
version |
String | Semantic version string. |
- Source:
Methods
(static) defaultTypeChecker(Type, value) → {Boolean}
Same as `defaultTypeChecker$` except curried:
"Returns a boolean indicating whether given value matches given type".
Parameters:
Name | Type | Description |
---|---|---|
Type |
String | function | Type name, constructor and/or class. |
value |
* |
- Source:
Returns:
- Type
- Boolean
(static) defaultTypeChecker$(Type, value) → {Boolean}
Returns a boolean indicating whether given value matches given type.
Parameters:
Name | Type | Description |
---|---|---|
Type |
String | function | Type name, constructor and/or class. |
value |
* |
- Source:
Returns:
- Type
- Boolean
(static) errorIfNotCheckableType(contextName, type) → {TypeRef}
Throws an error if `type` is not a checkable type (can't be checked by the `TypeChecker` type)
Parameters:
Name | Type | Description |
---|---|---|
contextName |
String | |
type |
TypeRef |
- Source:
Returns:
- Type passed in if `type` is checkable
- Type
- TypeRef
(static) errorIfNotType(type, contextName, valueName, value, messageSuffixopt) → {undefined}
Checks that passed in `value` is of given `type`. Throws an error if value
is not of given `type`. Curried.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
String | function | Type's name or type itself. | ||
contextName |
String | Name of context to attribute errors if thrown. | ||
valueName |
String | String rep of value. | ||
value |
* | |||
messageSuffix |
String |
<optional> |
null | Optional. |
- Source:
Returns:
- Type
- undefined
(static) errorIfNotType$(type, contextName, valueName, value, messageSuffixopt) → {undefined}
Checks that passed in `value` is of given `type`. Throws an error if value
is not of given `type`. This is the un-curried version. For the curried version
see `module:fjlErrorThrowing.errorIfNotType`.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
type |
String | function | Type's name or type itself. | ||
contextName |
String | Name of context to attribute errors if thrown. | ||
valueName |
String | String rep of value. | ||
value |
* | |||
messageSuffix |
String |
<optional> |
null | Optional. |
- Source:
Returns:
- Type
- undefined
(static) errorIfNotTypes(types, contextName, valueName, value) → {undefined}
Checks that passed in `value` is of one of the given `types`. Throws an error if value
is not of one of the given `types`. Curried.
Parameters:
Name | Type | Description |
---|---|---|
types |
Array | Array of one or more types or type names themselves. |
contextName |
String | Name of context to attribute errors if thrown. |
valueName |
String | String rep of value. |
value |
* |
- Source:
Returns:
- Type
- undefined
(static) errorIfNotTypes$(types, contextName, valueName, value) → {undefined}
Checks that passed in `value` is of one of the given `types`. Throws an error if value
is not of one of the given `types`. This is the un-curried version. For the curried version
see `module:fjlErrorThrowing.errorIfNotTypes`.
Parameters:
Name | Type | Description |
---|---|---|
types |
Array | Array of one or more types or type names themselves. |
contextName |
String | Name of context to attribute errors if thrown. |
valueName |
String | String rep of value. |
value |
* |
- Source:
Returns:
- Type
- undefined
(static) getErrorIfNotTypesThrower(errorMessageCall) → {function|ErrorIfNotTypes}
Returns a function that can be used to ensure that a value is of one or more given types.
The returned function is used in cases where informative error messages
containing the value types, names, expected type names, are-required/should-be-used etc.
Parameters:
Name | Type | Description |
---|---|---|
errorMessageCall |
function | ErrorMessageCall | Template function (takes an info-object and returns a printed string). |
- Source:
Returns:
- Returns a function with the same signature as `errorIfNotTypes` though curried.
- Type
- function | ErrorIfNotTypes
(static) getErrorIfNotTypesThrower$(errorMessageCall, typeChecker) → {function|ErrorIfNotTypes}
Gets the error message thrower seeded with passed in errorMessage template call.
Parameters:
Name | Type | Description |
---|---|---|
errorMessageCall |
function | ErrorMessageCall | |
typeChecker |
function | TypeChecker | Function |
- Source:
Returns:
- Type
- function | ErrorIfNotTypes
(static) getErrorIfNotTypeThrower(errorMessageCall) → {function|ErrorIfNotType}
Returns a function that can be used to ensure that values are of a given type.
Also throws informative error messages containing the value types, names, expected type names,
etc.
Parameters:
Name | Type | Description |
---|---|---|
errorMessageCall |
function | ErrorMessageCall | Template function (takes an info-object and returns a printed string). |
- Source:
Returns:
- Returns a function with the same signature as `errorIfNotType` though curried.
- Type
- function | ErrorIfNotType
(static) getErrorIfNotTypeThrower$(errorMessageCall, typeChecker) → {function|ErrorIfNotType}
Gets the error message thrower seeded with passed in errorMessage template call.
Parameters:
Name | Type | Description |
---|---|---|
errorMessageCall |
function | ErrorMessageCall | |
typeChecker |
function | TypeChecker | Function |
- Source:
Returns:
- Type
- function | ErrorIfNotType
(static) isCheckableType(type) → {Boolean}
Checks if `type` is a string or a function (constructor or constructor name)
Parameters:
Name | Type | Description |
---|---|---|
type |
TypeRef |
- Source:
Returns:
- Type
- Boolean
Type Definitions
Any
Synonym for 'any value'.
Type:
- *
- Source:
ErrorIfNotType(type, contextName, valueName, value) → {Undefined}
Used to ensure value matches passed in type.
Parameters:
Name | Type | Description |
---|---|---|
type |
TypeRef | Constructor name or constructor. |
contextName |
String | |
valueName |
String | |
value |
* |
- Source:
Throws:
-
- If value doesn't match type.
- Type
- Error
Returns:
- Type
- Undefined
ErrorIfNotTypes(valueTypes, contextName, valueName, value) → {Undefined}
Used to ensure a value matches one of one or more types passed in.
Parameters:
Name | Type | Description |
---|---|---|
valueTypes |
TypesArray | Array of constructor names or constructors. |
contextName |
String | |
valueName |
String | |
value |
* |
- Source:
Throws:
-
- If value doesn't match type.
- Type
- Error
Returns:
- Type
- Undefined
ErrorMessageCall(tmplContext) → {String}
Error message template function.
Parameters:
Name | Type | Description |
---|---|---|
tmplContext |
TemplateContext |
- Source:
Returns:
- Type
- String
TemplateContext
Template context used for error message renderers (functions that take a context obj and return a string).
Type:
- Object.<value, valueName, expectedTypeName, foundTypeName, messageSuffix>
Properties:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
value |
* | |||
valueName |
String | |||
expectedTypeName |
String | Expected name of constructor of `value`; E.g., usually `SomeConstructor.name`; | ||
foundTypeName |
String | Found types name; E.g., `FoundConstructor.name`; | ||
messageSuffix |
* |
<optional> |
null | Message suffix (sometimes an extra hint or instructions for directing user to fix where his/her error has occurred). Optional. |
- Source:
TypeChecker(Type, value) → {Boolean}
Checks whether a value is of given type.
Parameters:
Name | Type | Description |
---|---|---|
Type |
TypeRef | a Type or it's name; E.g., `Type.name`. |
value |
* |
- Source:
Returns:
- Type
- Boolean
TypeRef()
Type reference. Type itself or Type's name; E.g., `Type.name`;
- Source:
TypesArray
Type:
- Array.<(String|function())>
- Source: