errorThrowing

Contains error throwing facilities for when a value doesn't match a type.

Methods

static errorIfNotType(type, contextName, valueName, value, messageSuffixopt) → {*}

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.
Returns:
* - - Given `value` if `value` matches passed in type.

static errorIfNotTypes(types, contextName, valueName, value) → {*}

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 *
Returns:
* - - Given `value` if `value` matches passed in type.

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).
Returns:
function | ErrorIfNotTypes - - Returns a function with the same signature as `errorIfNotTypes` though curried.

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).
Returns:
function | ErrorIfNotType - - Returns a function with the same signature as `errorIfNotType` though curried.