tcomb
Advanced tools
Comparing version 2.2.1 to 2.3.0
@@ -15,2 +15,44 @@ # Changelog | ||
## v2.3.0 | ||
- **New Feature** | ||
- Add support for lazy messages in asserts, fix #124 | ||
- Better error messages for assert failures, fix #120 | ||
The messages now have the following general form: | ||
``` | ||
Invalid value <value> supplied to <context> | ||
``` | ||
where context is a slash-separated string with the following properties: | ||
- the first element is the name of the "root" | ||
- the following elements have the form: `<field name>: <field type>` | ||
Note: for more readable messages remember to give types a name | ||
Example: | ||
```js | ||
var Person = t.struct({ | ||
name: t.String | ||
}, 'Person'); // <- remember to give types a name | ||
var User = t.struct({ | ||
email: t.String, | ||
profile: Person | ||
}, 'User'); | ||
var mynumber = t.Number('a'); | ||
// => Invalid value "a" supplied to Number | ||
var myuser = User({ email: 1 }); | ||
// => Invalid value 1 supplied to User/email: String | ||
myuser = User({ email: 'email', profile: { name: 2 } }); | ||
// => Invalid value 2 supplied to User/profile: Person/name: String | ||
``` | ||
## v2.2.1 | ||
@@ -17,0 +59,0 @@ |
@@ -668,3 +668,3 @@ # Setup | ||
``` | ||
type, [guard], result | ||
type, [guard], block | ||
``` | ||
@@ -674,3 +674,3 @@ | ||
- `guard` an optional predicate `(x) => t.Any` | ||
- `result` a function `(x) => t.Any` called when the match succeded | ||
- `block` a function `(x) => t.Any` called when the match succeded | ||
@@ -677,0 +677,0 @@ Example: |
185
index.js
@@ -65,6 +65,6 @@ 'use strict'; | ||
function create(type, value) { | ||
function create(type, value, path) { | ||
if (isType(type)) { | ||
// for structs the new operator is allowed | ||
return isStruct(type) ? new type(value) : type(value); | ||
return isStruct(type) ? new type(value, path) : type(value, path); | ||
} | ||
@@ -74,3 +74,4 @@ | ||
// type should be a class constructor and value some instance, just check membership and return the value | ||
assert(isInstanceOf(value, type), 'The value ' + exports.stringify(value) + ' is not an instance of ' + getFunctionName(type)); | ||
path = path || [getFunctionName(type)]; | ||
assert(isInstanceOf(value, type), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/'); }); | ||
} | ||
@@ -97,3 +98,9 @@ | ||
if (guard !== true) { | ||
exports.fail(message || 'Assert failed'); | ||
if (isFunction(message)) { | ||
message = message(); | ||
} | ||
else if (isNil(message)) { | ||
message = 'Assert failed (turn on "Pause on exceptions" in your Source panel)'; | ||
} | ||
exports.fail(message); | ||
} | ||
@@ -109,3 +116,3 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(!target.hasOwnProperty(k), 'Invalid call to mixin(): cannot overwrite property ' + exports.stringify(k) + ' of target object'); | ||
assert(!target.hasOwnProperty(k), function () { return 'Invalid call to mixin(target, source, [overwrite]): cannot overwrite property "' + k + '" of target object'; }); | ||
} | ||
@@ -120,3 +127,3 @@ } | ||
function forbidNewOperator(x, type) { | ||
assert(!isInstanceOf(x, type), 'Cannot use the new operator to instantiate a type ' + getTypeName(type)); | ||
assert(!isInstanceOf(x, type), function () { return 'Cannot use the new operator to instantiate the type ' + getTypeName(type); }); | ||
} | ||
@@ -134,3 +141,3 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isObject(spec), 'Invalid argument spec = ' + exports.stringify(spec) + ' supplied to function update(instance, spec): expected an object containing commands'); | ||
assert(isObject(spec), function () { return 'Invalid argument spec ' + exports.stringify(spec) + ' supplied to function update(instance, spec): expected an object containing commands'; }); | ||
} | ||
@@ -156,3 +163,3 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isFunction(f), 'Invalid argument f supplied to immutability helper { $apply: f }: expected a function'); | ||
assert(isFunction(f), 'Invalid argument f supplied to immutability helper { $apply: f } (expected a function)'); | ||
} | ||
@@ -164,4 +171,4 @@ return f(value); | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isArray(elements), 'Invalid argument elements supplied to immutability helper { $push: elements }: expected an array'); | ||
assert(isArray(arr), 'Invalid value supplied to immutability helper "$push": expected an array'); | ||
assert(isArray(elements), 'Invalid argument elements supplied to immutability helper { $push: elements } (expected an array)'); | ||
assert(isArray(arr), 'Invalid value supplied to immutability helper $push (expected an array)'); | ||
} | ||
@@ -173,4 +180,4 @@ return arr.concat(elements); | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isArray(keys), 'Invalid argument keys supplied to immutability helper { $remove: keys }: expected an array'); | ||
assert(isObject(obj), 'Invalid value supplied to immutability helper $remove: expected an object'); | ||
assert(isArray(keys), 'Invalid argument keys supplied to immutability helper { $remove: keys } (expected an array)'); | ||
assert(isObject(obj), 'Invalid value supplied to immutability helper $remove (expected an object)'); | ||
} | ||
@@ -189,4 +196,4 @@ for (var i = 0, len = keys.length; i < len; i++ ) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(list(Arr).is(splices), 'Invalid argument splices supplied to immutability helper { $splice: splices }: expected an array of arrays'); | ||
assert(isArray(arr), 'Invalid value supplied to immutability helper $splice: expected an array'); | ||
assert(list(Arr).is(splices), 'Invalid argument splices supplied to immutability helper { $splice: splices } (expected an array of arrays)'); | ||
assert(isArray(arr), 'Invalid value supplied to immutability helper $splice (expected an array)'); | ||
} | ||
@@ -201,6 +208,6 @@ return splices.reduce(function (acc, splice) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isObject(config), 'Invalid argument config supplied to immutability helper { $swap: config }: expected an object'); | ||
assert(isNumber(config.from), 'Invalid argument config.from supplied to immutability helper { $swap: config }: expected a number'); | ||
assert(isNumber(config.to), 'Invalid argument config.to supplied to immutability helper { $swap: config }: expected a number'); | ||
assert(isArray(arr), 'Invalid value supplied to immutability helper $swap'); | ||
assert(isObject(config), 'Invalid argument config supplied to immutability helper { $swap: config } (expected an object)'); | ||
assert(isNumber(config.from), 'Invalid argument config.from supplied to immutability helper { $swap: config } (expected a number)'); | ||
assert(isNumber(config.to), 'Invalid argument config.to supplied to immutability helper { $swap: config } (expected a number)'); | ||
assert(isArray(arr), 'Invalid value supplied to immutability helper $swap (expected an array)'); | ||
} | ||
@@ -215,4 +222,4 @@ var element = arr[config.to]; | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isArray(elements), 'Invalid argument elements supplied to immutability helper {$unshift: elements}'); | ||
assert(isArray(arr), 'Invalid value supplied to immutability helper $unshift'); | ||
assert(isArray(elements), 'Invalid argument elements supplied to immutability helper {$unshift: elements} (expected an array)'); | ||
assert(isArray(arr), 'Invalid value supplied to immutability helper $unshift (expected an array)'); | ||
} | ||
@@ -240,11 +247,12 @@ return elements.concat(arr); | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isString(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to irreducible(name, predicate)'); | ||
assert(isString(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to irreducible(name, predicate) (expected a string)'; }); | ||
assert(isFunction(predicate), 'Invalid argument predicate supplied to irreducible(name, predicate)'); | ||
} | ||
function Irreducible(value) { | ||
function Irreducible(value, path) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
forbidNewOperator(this, Irreducible); | ||
assert(predicate(value), 'Invalid argument value = ' + exports.stringify(value) + ' supplied to irreducible type ' + name); | ||
path = path || [name]; | ||
assert(predicate(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/'); }); | ||
} | ||
@@ -306,4 +314,4 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(dict(Str, Func).is(props), 'Invalid argument props = ' + exports.stringify(props) + ' supplied to struct(props, name): expected a dictionary of tcomb types'); | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to struct(props, name): expected a string'); | ||
assert(dict(Str, Func).is(props), function () { return 'Invalid argument props ' + exports.stringify(props) + ' supplied to struct(props, [name]) combinator (expected a dictionary String -> Type)'; }); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to struct(props, [name]) combinator (expected a string)'; }); | ||
} | ||
@@ -313,3 +321,3 @@ | ||
function Struct(value) { | ||
function Struct(value, path) { | ||
@@ -321,3 +329,4 @@ if (Struct.is(value)) { // makes Struct idempotent | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isObject(value), 'Invalid argument value = ' + exports.stringify(value) + ' supplied to struct ' + displayName + ': expected an object'); | ||
path = path || [displayName]; | ||
assert(isObject(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/') + ' (expected an object)'; }); | ||
} | ||
@@ -333,3 +342,3 @@ | ||
var actual = value[k]; | ||
this[k] = create(expected, actual); | ||
this[k] = create(expected, actual, ( process.env.NODE_ENV !== 'production' ? path.concat(k + ': ' + getTypeName(expected)) : null )); | ||
} | ||
@@ -366,3 +375,3 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isStruct(x), 'Invalid argument structs[' + i + '] = ' + exports.stringify(structs[i]) + ' supplied to ' + displayName + '.extend(structs, name)'); | ||
assert(isStruct(x), function () { return 'Invalid argument structs[' + i + '] ' + exports.stringify(structs[i]) + ' supplied to ' + displayName + '.extend(structs, name)'; }); | ||
} | ||
@@ -387,4 +396,4 @@ return x.meta.props; | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isArray(types) && types.every(isFunction) && types.length >= 2, 'Invalid argument types = ' + exports.stringify(types) + ' supplied to union(types, name): expected an array of at least 2 types'); | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to union(types, name): expected a string'); | ||
assert(isArray(types) && types.every(isFunction) && types.length >= 2, function () { return 'Invalid argument types ' + exports.stringify(types) + ' supplied to union(types, [name]) combinator (expected an array of at least 2 types)'; }); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to union(types, [name]) combinator (expected a string)'; }); | ||
} | ||
@@ -394,7 +403,6 @@ | ||
function Union(value) { | ||
function Union(value, path) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
forbidNewOperator(this, Union); | ||
assert(isFunction(Union.dispatch), 'Unimplemented dispatch() function for union ' + displayName); | ||
} | ||
@@ -405,6 +413,7 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isType(type), 'The dispatch() function of union ' + displayName + ' returns no type'); | ||
path = path || [displayName]; | ||
assert(isType(type), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/'); }); | ||
} | ||
return create(type, value); | ||
return create(type, value, path); | ||
} | ||
@@ -427,3 +436,3 @@ | ||
Union.dispatch = function (x) { // default dispatch implementation | ||
for (var i = 0; i < types.length; i++ ) { | ||
for (var i = 0, len = types.length; i < len; i++ ) { | ||
if (is(x, types[i])) { | ||
@@ -445,4 +454,4 @@ return types[i]; | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isArray(types) && types.every(isFunction) && types.length >= 2, 'Invalid argument types = ' + exports.stringify(types) + ' supplied to intersection(types, name): expected an array of at least 2 types'); | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to intersection(types, name): expected a string'); | ||
assert(isArray(types) && types.every(isFunction) && types.length >= 2, function () { return 'Invalid argument types ' + exports.stringify(types) + ' supplied to intersection(types, [name]) combinator (expected an array of at least 2 types)'; }); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to intersection(types, [name]) combinator (expected a string)'; }); | ||
} | ||
@@ -452,12 +461,10 @@ | ||
function Intersection(value) { | ||
function Intersection(value, path) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
forbidNewOperator(this, Intersection); | ||
path = path || [displayName]; | ||
assert(Intersection.is(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/'); }); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(Intersection.is(value), 'Invalid argument value = ' + exports.stringify(value) + ' supplied to intersection ' + displayName); | ||
} | ||
return value; | ||
@@ -494,3 +501,3 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isFunction(type), 'Invalid argument type = ' + exports.stringify(type) + ' supplied to maybe(type, name): expected a type'); | ||
assert(isFunction(type), function () { return 'Invalid argument type ' + exports.stringify(type) + ' supplied to maybe(type, [name]) combinator (expected a type)'; }); | ||
} | ||
@@ -503,3 +510,3 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to maybe(type, name): expected a string'); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to maybe(type, [name]) combinator (expected a string)'; }); | ||
} | ||
@@ -509,7 +516,7 @@ | ||
function Maybe(value) { | ||
function Maybe(value, path) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
forbidNewOperator(this, Maybe); | ||
} | ||
return isNil(value) ? null : create(type, value); | ||
return isNil(value) ? null : create(type, value, path); | ||
} | ||
@@ -539,4 +546,4 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isObject(map), 'Invalid argument map = ' + exports.stringify(map) + ' supplied to enums(map, name): expected a hash of strings / numbers'); | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to enums(map, name): expected a string'); | ||
assert(isObject(map), function () { return 'Invalid argument map ' + exports.stringify(map) + ' supplied to enums(map, [name]) combinator (expected a dictionary of String -> String | Number)'; }); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to enums(map, [name]) combinator (expected a string)'; }); | ||
} | ||
@@ -546,7 +553,10 @@ | ||
function Enums(value) { | ||
function Enums(value, path) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
forbidNewOperator(this, Enums); | ||
assert(Enums.is(value), 'Invalid argument value = ' + exports.stringify(value) + ' supplied to enums ' + displayName + ': expected one of ' + exports.stringify(Object.keys(map))); | ||
path = path || [displayName]; | ||
assert(Enums.is(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/') + ' (expected one of ' + exports.stringify(Object.keys(map)) + ')'; }); | ||
} | ||
return value; | ||
@@ -586,4 +596,4 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isArray(types) && types.every(isFunction), 'Invalid argument types = ' + exports.stringify(types) + ' supplied to tuple(types, name): expected an array of types'); | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to tuple(types, name): expected a string'); | ||
assert(isArray(types) && types.every(isFunction), function () { return 'Invalid argument types ' + exports.stringify(types) + ' supplied to tuple(types, [name]) combinator (expected an array of types)'; }); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to tuple(types, [name]) combinator (expected a string)'; }); | ||
} | ||
@@ -599,6 +609,7 @@ | ||
function Tuple(value) { | ||
function Tuple(value, path) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isArray(value) && value.length === types.length, 'Invalid argument value = ' + exports.stringify(value) + ' supplied to tuple ' + displayName + ': expected an array of length ' + types.length); | ||
path = path || [displayName]; | ||
assert(isArray(value) && value.length === types.length, function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/') + ' (expected an array of length ' + types.length + ')'; }); | ||
} | ||
@@ -614,6 +625,6 @@ | ||
var arr = [], expected, actual; | ||
for (var i = 0; i < types.length; i++) { | ||
for (var i = 0, len = types.length; i < len; i++) { | ||
expected = types[i]; | ||
actual = value[i]; | ||
arr.push(create(expected, actual)); | ||
arr.push(create(expected, actual, ( process.env.NODE_ENV !== 'production' ? path.concat(i + ': ' + getTypeName(expected)) : null ))); | ||
} | ||
@@ -656,5 +667,5 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isFunction(type), 'Invalid argument type = ' + exports.stringify(type) + ' supplied to subtype(type, predicate, name): expected a type'); | ||
assert(isFunction(predicate), 'Invalid argument predicate supplied to subtype(type, predicate, name): expected a function'); | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to subtype(type, predicate, name): expected a string'); | ||
assert(isFunction(type), function () { return 'Invalid argument type ' + exports.stringify(type) + ' supplied to subtype(type, predicate, [name]) combinator (expected a type)'; }); | ||
assert(isFunction(predicate), function () { return 'Invalid argument predicate supplied to subtype(type, predicate, [name]) combinator (expected a function)'; }); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to subtype(type, predicate, [name]) combinator (expected a string)'; }); | ||
} | ||
@@ -664,12 +675,13 @@ | ||
function Subtype(value) { | ||
function Subtype(value, path) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
forbidNewOperator(this, Subtype); | ||
path = path || [displayName]; | ||
} | ||
var x = create(type, value); | ||
var x = create(type, value, path); | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(predicate(x), 'Invalid argument value = ' + exports.stringify(value) + ' supplied to subtype ' + displayName); | ||
assert(predicate(x), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/'); }); | ||
} | ||
@@ -707,7 +719,8 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isFunction(type), 'Invalid argument type = ' + exports.stringify(type) + ' supplied to list(type, name): expected a type'); | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to list(type, name): expected a string'); | ||
assert(isFunction(type), function () { return 'Invalid argument type ' + exports.stringify(type) + ' supplied to list(type, [name]) combinator (expected a type)'; }); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to list(type, [name]) combinator (expected a string)'; }); | ||
} | ||
var displayName = name || getDefaultListName(type); | ||
var typeNameCache = getTypeName(type); | ||
@@ -720,6 +733,7 @@ function isList(x) { | ||
function List(value) { | ||
function List(value, path) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isArray(value), 'Invalid argument value = ' + exports.stringify(value) + ' supplied to list ' + displayName); | ||
assert(isArray(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + displayName + ' (expected an array of ' + typeNameCache + ')'; }); | ||
path = path || [displayName]; | ||
} | ||
@@ -737,3 +751,3 @@ | ||
var actual = value[i]; | ||
arr.push(create(type, actual)); | ||
arr.push(create(type, actual, ( process.env.NODE_ENV !== 'production' ? path.concat(i + ': ' + typeNameCache) : null ))); | ||
} | ||
@@ -774,8 +788,10 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isFunction(domain), 'Invalid argument domain = ' + exports.stringify(domain) + ' supplied to dict(domain, codomain, name): expected a type'); | ||
assert(isFunction(codomain), 'Invalid argument codomain = ' + exports.stringify(codomain) + ' supplied to dict(domain, codomain, name): expected a type'); | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to dict(domain, codomain, name): expected a string'); | ||
assert(isFunction(domain), function () { return 'Invalid argument domain ' + exports.stringify(domain) + ' supplied to dict(domain, codomain, [name]) combinator (expected a type)'; }); | ||
assert(isFunction(codomain), function () { return 'Invalid argument codomain ' + exports.stringify(codomain) + ' supplied to dict(domain, codomain, [name]) combinator (expected a type)'; }); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to dict(domain, codomain, [name]) combinator (expected a string)'; }); | ||
} | ||
var displayName = name || getDefaultDictName(domain, codomain); | ||
var domainNameCache = getTypeName(domain); | ||
var codomainNameCache = getTypeName(codomain); | ||
@@ -793,6 +809,7 @@ function isDict(x) { | ||
function Dict(value) { | ||
function Dict(value, path) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isObject(value), 'Invalid argument value = ' + exports.stringify(value) + ' supplied to dict ' + displayName); | ||
assert(isObject(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + displayName; }); | ||
path = path || [displayName]; | ||
} | ||
@@ -810,5 +827,5 @@ | ||
if (value.hasOwnProperty(k)) { | ||
k = create(domain, k); | ||
k = create(domain, k, ( process.env.NODE_ENV !== 'production' ? path.concat(domainNameCache) : null )); | ||
var actual = value[k]; | ||
obj[k] = create(codomain, actual); | ||
obj[k] = create(codomain, actual, ( process.env.NODE_ENV !== 'production' ? path.concat(k + ': ' + codomainNameCache) : null )); | ||
} | ||
@@ -857,5 +874,5 @@ } | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(list(Func).is(domain), 'Invalid argument domain = ' + exports.stringify(domain) + ' supplied to func(domain, codomain, name): expected an array of types'); | ||
assert(isFunction(codomain), 'Invalid argument codomain = ' + exports.stringify(codomain) + ' supplied to func(domain, codomain, name): expected a type'); | ||
assert(isTypeName(name), 'Invalid argument name = ' + exports.stringify(name) + ' supplied to func(domain, codomain, name): expected a string'); | ||
assert(list(Func).is(domain), function () { return 'Invalid argument domain ' + exports.stringify(domain) + ' supplied to func(domain, codomain, [name]) combinator (expected an array of types)'; }); | ||
assert(isFunction(codomain), function () { return 'Invalid argument codomain ' + exports.stringify(codomain) + ' supplied to func(domain, codomain, [name]) combinator (expected a type)'; }); | ||
assert(isTypeName(name), function () { return 'Invalid argument name ' + exports.stringify(name) + ' supplied to func(domain, codomain, [name]) combinator (expected a string)'; }); | ||
} | ||
@@ -872,3 +889,3 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(FuncType.is(value), 'Invalid argument value = ' + exports.stringify(value) + ' supplied to func ' + displayName); | ||
assert(FuncType.is(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + displayName; }); | ||
} | ||
@@ -900,4 +917,4 @@ | ||
if (process.env.NODE_ENV !== 'production') { | ||
assert(isFunction(f), 'Invalid argument f supplied to func.of ' + displayName + ': expected a function'); | ||
assert(isNil(curried) || isBoolean(curried), 'Invalid argument curried = ' + exports.stringify(curried) + ' supplied to func.of ' + displayName + ': expected a boolean'); | ||
assert(isFunction(f), function () { return 'Invalid argument f supplied to func.of ' + displayName + ' (expected a function)'; }); | ||
assert(isNil(curried) || isBoolean(curried), function () { return 'Invalid argument curried ' + exports.stringify(curried) + ' supplied to func.of ' + displayName + ' (expected a boolean)'; }); | ||
} | ||
@@ -962,5 +979,5 @@ | ||
count = (count || 0) + 1; | ||
assert(isType(type), 'Invalid type in clause #' + count); | ||
assert(isFunction(guard), 'Invalid guard in clause #' + count + ''); | ||
assert(isFunction(f), 'Invalid block in clause #' + count + ''); | ||
assert(isType(type), function () { return 'Invalid type in clause #' + count; }); | ||
assert(isFunction(guard), function () { return 'Invalid guard in clause #' + count; }); | ||
assert(isFunction(f), function () { return 'Invalid block in clause #' + count; }); | ||
} | ||
@@ -967,0 +984,0 @@ |
{ | ||
"name": "tcomb", | ||
"version": "2.2.1", | ||
"version": "2.3.0", | ||
"description": "Type checking and DDD for JavaScript", | ||
@@ -29,6 +29,9 @@ "main": "index.js", | ||
"safety", | ||
"models", | ||
"model", | ||
"domain", | ||
"debugging", | ||
"immutable" | ||
"immutable", | ||
"DDD", | ||
"JSON", | ||
"store" | ||
], | ||
@@ -40,7 +43,10 @@ "keywords": [ | ||
"safety", | ||
"models", | ||
"model", | ||
"domain", | ||
"debugging", | ||
"immutable" | ||
"immutable", | ||
"DDD", | ||
"JSON", | ||
"store" | ||
] | ||
} |
55943
772