Socket
Socket
Sign inDemoInstall

tcomb

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcomb - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

4

CHANGELOG.md

@@ -0,1 +1,5 @@

# v0.3.3
- add `displayName` to combinators, fix #69
# v0.3.2

@@ -2,0 +6,0 @@

310

index.js

@@ -15,3 +15,3 @@ (function (root, factory) {

var failed = false;
function onFail(message) {

@@ -26,3 +26,3 @@ // start debugger only once

/*jshint debug: true*/
debugger;
debugger;
}

@@ -45,3 +45,3 @@ failed = true;

}
function assert(guard) {

@@ -56,3 +56,3 @@ if (guard !== true) {

*/
fail(message);
fail(message);
}

@@ -64,5 +64,5 @@ }

//
var slice = Array.prototype.slice;
function mixin(target, source, overwrite) {

@@ -88,3 +88,3 @@ if (Nil.is(source)) {

var message = args[0];
function formatArgument(match, type) {

@@ -97,3 +97,3 @@ if (match === '%%') { return '%'; } // handle escaping %

}
var str = message.replace(/%([a-z%])/g, formatArgument);

@@ -105,3 +105,3 @@ if (i < len) {

}
function replacer(key, value) {

@@ -113,8 +113,8 @@ if (typeof value === 'function') {

}
format.formatters = {
s: function (x) { return String(x); },
j: function (x) { return JSON.stringify(x, replacer); }
s: function formatString(x) { return String(x); },
j: function formatJSON(x) { return JSON.stringify(x, replacer); }
};
function getName(type) {

@@ -155,7 +155,7 @@ assert(Type.is(type), 'Invalid argument `type` of value `%j` supplied to `getName()`, expected a type.', type);

update.commands = {
'$apply': function (f, value) {
'$apply': function $apply(f, value) {
assert(Func.is(f));
return f(value);
},
'$push': function (elements, arr) {
'$push': function $push(elements, arr) {
assert(Arr.is(elements));

@@ -165,3 +165,3 @@ assert(Arr.is(arr));

},
'$remove': function (keys, obj) {
'$remove': function $remove(keys, obj) {
assert(Arr.is(keys));

@@ -174,9 +174,9 @@ assert(Obj.is(obj));

},
'$set': function (value) {
'$set': function $set(value) {
return value;
},
'$splice': function (splices, arr) {
'$splice': function $splice(splices, arr) {
assert(list(Arr).is(splices));
assert(Arr.is(arr));
return splices.reduce(function (acc, splice) {
return splices.reduce(function reducer(acc, splice) {
acc.splice.apply(acc, splice);

@@ -186,3 +186,3 @@ return acc;

},
'$swap': function (config, arr) {
'$swap': function $swap(config, arr) {
assert(Obj.is(config));

@@ -197,3 +197,3 @@ assert(Num.is(config.from));

},
'$unshift': function (elements, arr) {
'$unshift': function $unshift(elements, arr) {
assert(Arr.is(elements));

@@ -208,5 +208,5 @@ assert(Arr.is(arr));

//
function irriducible(name, is) {
// DEBUG HINT: if the debugger stops here, the first argument is not a string

@@ -226,6 +226,6 @@ assert(typeof name === 'string', 'Invalid argument `name` supplied to `irriducible()`');

assert(is(value), 'Invalid `%s` supplied to `%s`', value, name);
return value;
}
Irriducible.meta = {

@@ -235,5 +235,7 @@ kind: 'irriducible',

};
Irriducible.displayName = name;
Irriducible.is = is;
return Irriducible;

@@ -245,39 +247,39 @@ }

});
var Nil = irriducible('Nil', function isNil(x) {
return x === null || x === void 0;
});
var Str = irriducible('Str', function isStr(x) {
return typeof x === 'string';
});
var Num = irriducible('Num', function isNum(x) {
return typeof x === 'number' && isFinite(x) && !isNaN(x);
});
var Bool = irriducible('Bool', function isBool(x) {
return x === true || x === false;
});
var Arr = irriducible('Arr', function isArr(x) {
return x instanceof Array;
});
var Obj = irriducible('Obj', function isObj(x) {
return !Nil.is(x) && typeof x === 'object' && !Arr.is(x);
});
var Func = irriducible('Func', function isFunc(x) {
return typeof x === 'function';
});
var Err = irriducible('Err', function isErr(x) {
return x instanceof Error;
});
var Re = irriducible('Re', function isRe(x) {
return x instanceof RegExp;
});
var Dat = irriducible('Dat', function isDat(x) {

@@ -290,5 +292,5 @@ return x instanceof Date;

});
function struct(props, name) {
// DEBUG HINT: if the debugger stops here, the first argument is not a dict of types

@@ -304,5 +306,5 @@ // mouse over the `props` variable to see what's wrong

name = name || 'struct';
function Struct(value, mut) {
// makes Struct idempotent

@@ -312,12 +314,12 @@ if (Struct.is(value)) {

}
// DEBUG HINT: if the debugger stops here, the first argument is invalid
// mouse over the `value` variable to see what's wrong. In `name` there is the name of the type
assert(Obj.is(value), 'Invalid `%s` supplied to `%s`, expected an `Obj`', value, name);
// makes `new` optional
if (!(this instanceof Struct)) {
return new Struct(value, mut);
if (!(this instanceof Struct)) {
return new Struct(value, mut);
}
for (var k in props) {

@@ -332,8 +334,8 @@ if (props.hasOwnProperty(k)) {

}
if (mut !== true) {
Object.freeze(this);
if (mut !== true) {
Object.freeze(this);
}
}
Struct.meta = {

@@ -344,11 +346,13 @@ kind: 'struct',

};
Struct.is = function isStruct(x) {
return x instanceof Struct;
Struct.displayName = name;
Struct.is = function isStruct(x) {
return x instanceof Struct;
};
Struct.update = function updateStruct(instance, spec, value) {
return new Struct(update(instance, spec, value));
};
Struct.extend = function extendStruct(newProps, name) {

@@ -362,3 +366,3 @@ return struct([props].concat(newProps).reduce(mixin, {}), name);

function union(types, name) {
// DEBUG HINT: if the debugger stops here, the first argument is not a list of types

@@ -382,3 +386,3 @@ assert(list(Type).is(types), 'Invalid argument `types` supplied to `union()`');

blockNew(this, Union);
// DEBUG HINT: if the debugger stops here, you must implement the `dispatch` static method for this type

@@ -391,3 +395,3 @@ assert(Func.is(Union.dispatch), 'unimplemented %s.dispatch()', name);

assert(Type.is(type), '%s.dispatch() returns no type', name);
// DEBUG HINT: if the debugger stops here, `value` can't be converted to `type`

@@ -397,3 +401,3 @@ // mouse over the `value` and `type` variables to see what's wrong

}
Union.meta = {

@@ -404,3 +408,5 @@ kind: 'union',

};
Union.displayName = name;
Union.is = function isUnion(x) {

@@ -411,3 +417,3 @@ return types.some(function isType(type) {

};
// default dispatch implementation

@@ -426,6 +432,6 @@ Union.dispatch = function dispatch(x) {

function maybe(type, name) {
// DEBUG HINT: if the debugger stops here, the first argument is not a type
assert(Type.is(type), 'Invalid argument `type` supplied to `maybe()`');
// makes the combinator idempotent

@@ -439,3 +445,3 @@ if (getKind(type) === 'maybe') {

assert(Nil.is(name) || Str.is(name), 'Invalid argument `name` supplied to `maybe()`');
name = name || format('maybe(%s)', getName(type));

@@ -447,3 +453,3 @@

blockNew(this, Maybe);
// DEBUG HINT: if the debugger stops here, `value` can't be converted to `type`

@@ -453,3 +459,3 @@ // mouse over the `value` and `type` variables to see what's wrong

}
Maybe.meta = {

@@ -460,7 +466,9 @@ kind: 'maybe',

};
Maybe.displayName = name;
Maybe.is = function isMaybe(x) {
return Nil.is(x) || type.is(x);
};
return Maybe;

@@ -470,7 +478,7 @@ }

function enums(map, name) {
// DEBUG HINT: if the debugger stops here, the first argument is not a hash
// mouse over the `map` variable to see what's wrong
assert(Obj.is(map), 'Invalid argument `map` supplied to `enums()`');
// DEBUG HINT: if the debugger stops here, the second argument is not a string

@@ -484,3 +492,3 @@ // mouse over the `name` variable to see what's wrong

var keys = Object.keys(map);
function Enums(value) {

@@ -494,6 +502,6 @@

assert(Enums.is(value), 'Invalid `%s` supplied to `%s`, expected one of %j', value, name, keys);
return value;
}
Enums.meta = {

@@ -504,14 +512,16 @@ kind: 'enums',

};
Enums.displayName = name;
Enums.is = function isEnums(x) {
return Str.is(x) && map.hasOwnProperty(x);
};
return Enums;
}
enums.of = function enumsOf(keys, name) {
keys = Str.is(keys) ? keys.split(' ') : keys;
var value = {};
keys.forEach(function (k) {
keys.forEach(function setEnum(k) {
value[k] = k;

@@ -534,9 +544,9 @@ });

name = name || format('tuple([%s])', types.map(getName).join(', '));
function Tuple(value, mut) {
// DEBUG HINT: if the debugger stops here, the value is not one of the defined enums
// mouse over the `value`, `name` and `len` variables to see what's wrong
assert(Arr.is(value) && value.length === len, 'Invalid `%s` supplied to `%s`, expected an `Arr` of length `%s`', value, name, len);
// makes Tuple idempotent

@@ -546,3 +556,3 @@ if (Tuple.isTuple(value)) {

}
var arr = [];

@@ -556,9 +566,9 @@ for (var i = 0 ; i < len ; i++) {

}
if (mut !== true) {
Object.freeze(arr);
if (mut !== true) {
Object.freeze(arr);
}
return arr;
}
Tuple.meta = {

@@ -570,17 +580,19 @@ kind: 'tuple',

};
Tuple.isTuple = function (x) {
return types.every(function (type, i) {
return type.is(x[i]);
Tuple.displayName = name;
Tuple.isTuple = function isTuple(x) {
return types.every(function isType(type, i) {
return type.is(x[i]);
});
};
Tuple.is = function isTuple(x) {
return Arr.is(x) && x.length === len && Tuple.isTuple(x);
};
Tuple.update = function updateTuple(instance, spec, value) {
return Tuple(update(instance, spec, value));
};
return Tuple;

@@ -590,9 +602,9 @@ }

function subtype(type, predicate, name) {
// DEBUG HINT: if the debugger stops here, the first argument is not a type
assert(Type.is(type), 'Invalid argument `type` supplied to `subtype()`');
// DEBUG HINT: if the debugger stops here, the second argument is not a function
assert(Func.is(predicate), 'Invalid argument `predicate` supplied to `subtype()`');
// DEBUG HINT: if the debugger stops here, the third argument is not a string

@@ -607,3 +619,3 @@ // mouse over the `name` variable to see what's wrong

var expected = predicate.__doc__ || format('insert a valid value for %s', predicate.name || 'the subtype');
function Subtype(value, mut) {

@@ -613,6 +625,6 @@

blockNew(this, Subtype);
// DEBUG HINT: if the debugger stops here, the value cannot be converted to the base type
var x = type(value, mut);
// DEBUG HINT: if the debugger stops here, the value is converted to the base type

@@ -623,3 +635,3 @@ // but the predicate returns `false`

}
Subtype.meta = {

@@ -631,7 +643,9 @@ kind: 'subtype',

};
Subtype.displayName = name;
Subtype.is = function isSubtype(x) {
return type.is(x) && predicate(x);
};
Subtype.update = function updateSubtype(instance, spec, value) {

@@ -645,6 +659,6 @@ return Subtype(update(instance, spec, value));

function list(type, name) {
// DEBUG HINT: if the debugger stops here, the first argument is not a type
assert(Type.is(type), 'Invalid argument `type` supplied to `list()`');
// DEBUG HINT: if the debugger stops here, the third argument is not a string

@@ -658,3 +672,3 @@ // mouse over the `name` variable to see what's wrong

function List(value, mut) {
// DEBUG HINT: if the debugger stops here, you have used the `new` operator but it's forbidden

@@ -665,3 +679,3 @@

assert(Arr.is(value), 'Invalid `%s` supplied to `%s`, expected an `Arr`', value, name);
// makes List idempotent

@@ -671,3 +685,3 @@ if (List.isList(value)) {

}
var arr = [];

@@ -680,9 +694,9 @@ for (var i = 0, len = value.length ; i < len ; i++ ) {

}
if (mut !== true) {
Object.freeze(arr);
if (mut !== true) {
Object.freeze(arr);
}
return arr;
}
List.meta = {

@@ -693,15 +707,17 @@ kind: 'list',

};
List.isList = function (x) {
List.displayName = name;
List.isList = function isList(x) {
return x.every(type.is);
};
List.is = function isList(x) {
return Arr.is(x) && List.isList(x);
};
List.update = function updateList(instance, spec, value) {
return List(update(instance, spec, value));
};
return List;

@@ -711,3 +727,3 @@ }

function dict(domain, codomain, name) {
// DEBUG HINT: if the debugger stops here, the first argument is not a type

@@ -718,3 +734,3 @@ assert(Type.is(domain), 'Invalid argument `domain` supplied to `dict()`');

assert(Type.is(codomain), 'Invalid argument `codomain` supplied to `dict()`');
// DEBUG HINT: if the debugger stops here, the third argument is not a string

@@ -728,7 +744,7 @@ // mouse over the `name` variable to see what's wrong

function Dict(value, mut) {
// DEBUG HINT: if the debugger stops here, the value is not an object
// mouse over the `value` and `name` variables to see what's wrong
assert(Obj.is(value), 'Invalid `%s` supplied to `%s`, expected an `Obj`', value, name);
// makes Dict idempotent

@@ -738,3 +754,3 @@ if (Dict.isDict(value)) {

}
var obj = {};

@@ -752,9 +768,9 @@ for (var k in value) {

}
if (mut !== true) {
Object.freeze(obj);
if (mut !== true) {
Object.freeze(obj);
}
return obj;
}
Dict.meta = {

@@ -766,4 +782,6 @@ kind: 'dict',

};
Dict.isDict = function (x) {
Dict.displayName = name;
Dict.isDict = function isDict(x) {
for (var k in x) {

@@ -776,12 +794,12 @@ if (x.hasOwnProperty(k)) {

};
Dict.is = function isDict(x) {
return Obj.is(x) && Dict.isDict(x);
};
Dict.update = function updateDict(instance, spec, value) {
return Dict(update(instance, spec, value));
};
return Dict;

@@ -817,3 +835,3 @@ }

assert(Func.is(value), 'Invalid `%s` supplied to `%s`', value, name);
return value;

@@ -829,9 +847,11 @@ }

Func.displayName = name;
Func.is = function isFunc(x) {
return func.is(x) &&
x.func.domain.length === domain.length &&
x.func.domain.every(function (type, i) {
return func.is(x) &&
x.func.domain.length === domain.length &&
x.func.domain.every(function isEqual(type, i) {
return type === domain[i];
}) &&
x.func.codomain === codomain;
}) &&
x.func.codomain === codomain;
};

@@ -850,6 +870,6 @@

function fn() {
var args = slice.call(arguments);
var len = Math.min(args.length, domainLen);
// DEBUG HINT: if the debugger stops here, you provided wrong arguments to the function

@@ -863,7 +883,7 @@ // mouse over the `args` variable to see what's wrong

var r = f.apply(this, args);
// DEBUG HINT: if the debugger stops here, the return value of the function is invalid
// mouse over the `r` variable to see what's wrong
r = codomain(r);
return r;

@@ -878,5 +898,5 @@

}
}
fn.func = {

@@ -887,3 +907,3 @@ domain: domain,

};
return fn;

@@ -898,3 +918,3 @@

// returns true if x is an instrumented function
func.is = function (f) {
func.is = function isFunc(f) {
return Func.is(f) && Obj.is(f.func);

@@ -918,3 +938,3 @@ };

fail: fail,
Any: Any,

@@ -921,0 +941,0 @@ Nil: Nil,

{
"name": "tcomb",
"version": "0.3.2",
"version": "0.3.3",
"description": "Pragmatic runtime type checking for JavaScript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,6 +0,6 @@

// tcomb 0.3.2
// tcomb 0.3.3
// https://github.com/gcanti/tcomb
// (c) 2014 Giulio Canti <giulio.canti@gmail.com>
// tcomb may be freely distributed under the MIT license.
!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.t=b()}(this,function(){"use strict";function a(a){throw v=!0,new Error(a)}function b(a){w.onFail(a)}function c(a){if(a!==!0){var c=x.call(arguments,1),d=c[0]?e.apply(null,c):"assert failed";b(d)}}function d(a,b,d){if(z.is(b))return a;for(var e in b)b.hasOwnProperty(e)&&(d!==!0&&c(!a.hasOwnProperty(e),"cannot overwrite property %s",e),a[e]=b[e]);return a}function e(){function a(a,f){if("%%"===a)return"%";if(d>=c)return a;var g=e.formatters[f];return g?g(b[d++]):a}var b=x.call(arguments),c=b.length,d=1,f=b[0],g=f.replace(/%([a-z%])/g,a);return c>d&&(g+=" "+b.slice(d).join(" ")),g}function f(a,b){return"function"==typeof b?e("Func",b.name):b}function g(a){return c(J.is(a),"Invalid argument `type` of value `%j` supplied to `getName()`, expected a type.",a),a.meta.name}function h(a){return c(J.is(a),"Invalid argument `type` of value `%j` supplied to `geKind()`, expected a type.",a),a.meta.kind}function i(a,b){c(!(a instanceof b),"Operator `new` is forbidden for `%s`",g(b))}function j(a){return D.is(a)?a.concat():E.is(a)?d({},a):a}function k(a,b){c(E.is(b));var d=j(a);for(var e in b)if(b.hasOwnProperty(e)){if(k.commands.hasOwnProperty(e))return c(1===Object.keys(b).length),k.commands[e](b[e],d);d[e]=k(d[e],b[e])}return d}function l(a,b){function d(e){return i(this,d),c(b(e),"Invalid `%s` supplied to `%s`",e,a),e}return c("string"==typeof a,"Invalid argument `name` supplied to `irriducible()`"),c("function"==typeof b,"Invalid argument `is` supplied to `irriducible()`"),d.meta={kind:"irriducible",name:a},d.is=b,d}function m(a,b){function e(d,f){if(e.is(d))return d;if(c(E.is(d),"Invalid `%s` supplied to `%s`, expected an `Obj`",d,b),!(this instanceof e))return new e(d,f);for(var g in a)if(a.hasOwnProperty(g)){var h=a[g],i=d[g];this[g]=h(i,f)}f!==!0&&Object.freeze(this)}return c(t(A,J).is(a),"Invalid argument `props` supplied to `struct()`"),c(o(A).is(b),"Invalid argument `name` supplied to `struct()`"),b=b||"struct",e.meta={kind:"struct",props:a,name:b},e.is=function(a){return a instanceof e},e.update=function(a,b,c){return new e(k(a,b,c))},e.extend=function(b,c){return m([a].concat(b).reduce(d,{}),c)},e}function n(a,b){function d(a,e){i(this,d),c(F.is(d.dispatch),"unimplemented %s.dispatch()",b);var f=d.dispatch(a);return c(J.is(f),"%s.dispatch() returns no type",b),f(a,e)}c(s(J).is(a),"Invalid argument `types` supplied to `union()`");var f=a.length;return c(f>=2,"Invalid argument `types` supplied to `union()`"),c(o(A).is(b),"Invalid argument `name` supplied to `union()`"),b=b||e("union([%s])",a.map(g).join(", ")),d.meta={kind:"union",types:a,name:b},d.is=function(b){return a.some(function(a){return a.is(b)})},d.dispatch=function(b){for(var c=0,d=a.length;d>c;c++)if(a[c].is(b))return a[c]},d}function o(a,b){function d(b,c){return i(this,d),z.is(b)?null:a(b,c)}return c(J.is(a),"Invalid argument `type` supplied to `maybe()`"),"maybe"===h(a)?a:(c(z.is(b)||A.is(b),"Invalid argument `name` supplied to `maybe()`"),b=b||e("maybe(%s)",g(a)),d.meta={kind:"maybe",type:a,name:b},d.is=function(b){return z.is(b)||a.is(b)},d)}function p(a,b){function d(a){return i(this,d),c(d.is(a),"Invalid `%s` supplied to `%s`, expected one of %j",a,b,e),a}c(E.is(a),"Invalid argument `map` supplied to `enums()`"),c(o(A).is(b),"Invalid argument `name` supplied to `enums()`"),b=b||"enums";var e=Object.keys(a);return d.meta={kind:"enums",map:a,name:b},d.is=function(b){return A.is(b)&&a.hasOwnProperty(b)},d}function q(a,b){function d(e,g){if(c(D.is(e)&&e.length===f,"Invalid `%s` supplied to `%s`, expected an `Arr` of length `%s`",e,b,f),d.isTuple(e))return e;for(var h=[],i=0;f>i;i++){var j=a[i],k=e[i];h.push(j(k,g))}return g!==!0&&Object.freeze(h),h}c(s(J).is(a),"Invalid argument `types` supplied to `tuple()`");var f=a.length;return c(o(A).is(b),"Invalid argument `name` supplied to `tuple()`"),b=b||e("tuple([%s])",a.map(g).join(", ")),d.meta={kind:"tuple",types:a,length:f,name:b},d.isTuple=function(b){return a.every(function(a,c){return a.is(b[c])})},d.is=function(a){return D.is(a)&&a.length===f&&d.isTuple(a)},d.update=function(a,b,c){return d(k(a,b,c))},d}function r(a,b,d){function f(e,g){i(this,f);var j=a(e,g);return c(b(j),"Invalid `%s` supplied to `%s`, %s",e,d,h),j}c(J.is(a),"Invalid argument `type` supplied to `subtype()`"),c(F.is(b),"Invalid argument `predicate` supplied to `subtype()`"),c(o(A).is(d),"Invalid argument `name` supplied to `subtype()`"),d=d||e("subtype(%s)",g(a));var h=b.__doc__||e("insert a valid value for %s",b.name||"the subtype");return f.meta={kind:"subtype",type:a,predicate:b,name:d},f.is=function(c){return a.is(c)&&b(c)},f.update=function(a,b,c){return f(k(a,b,c))},f}function s(a,b){function d(e,f){if(c(D.is(e),"Invalid `%s` supplied to `%s`, expected an `Arr`",e,b),d.isList(e))return e;for(var g=[],h=0,i=e.length;i>h;h++){var j=e[h];g.push(a(j,f))}return f!==!0&&Object.freeze(g),g}return c(J.is(a),"Invalid argument `type` supplied to `list()`"),c(o(A).is(b),"Invalid argument `name` supplied to `list()`"),b=b||e("list(%s)",g(a)),d.meta={kind:"list",type:a,name:b},d.isList=function(b){return b.every(a.is)},d.is=function(a){return D.is(a)&&d.isList(a)},d.update=function(a,b,c){return d(k(a,b,c))},d}function t(a,b,d){function f(e,g){if(c(E.is(e),"Invalid `%s` supplied to `%s`, expected an `Obj`",e,d),f.isDict(e))return e;var h={};for(var i in e)if(e.hasOwnProperty(i)){i=a(i);var j=e[i];h[i]=b(j,g)}return g!==!0&&Object.freeze(h),h}return c(J.is(a),"Invalid argument `domain` supplied to `dict()`"),c(J.is(b),"Invalid argument `codomain` supplied to `dict()`"),c(o(A).is(d),"Invalid argument `name` supplied to `dict()`"),d=d||e("dict(%s, %s)",g(a),g(b)),f.meta={kind:"dict",domain:a,codomain:b,name:d},f.isDict=function(c){for(var d in c)if(c.hasOwnProperty(d)&&(!a.is(d)||!b.is(c[d])))return!1;return!0},f.is=function(a){return E.is(a)&&f.isDict(a)},f.update=function(a,b,c){return f(k(a,b,c))},f}function u(a,b,d){function f(a){return u.is(a)||(a=f.of(a)),c(f.is(a),"Invalid `%s` supplied to `%s`",a,d),a}a=D.is(a)?a:[a],c(s(J).is(a),"Invalid argument `domain` supplied to `func()`"),c(J.is(b),"Invalid argument `codomain` supplied to `func()`"),d=d||e("func([%s], %s)",a.map(g).join(", "),g(b));var h=a.length;return f.meta={kind:"func",domain:a,codomain:b,name:d},f.is=function(c){return u.is(c)&&c.func.domain.length===a.length&&c.func.domain.every(function(b,c){return b===a[c]})&&c.func.codomain===b},f.of=function(d){function e(){var c=x.call(arguments),e=Math.min(c.length,h);if(c=q(a.slice(0,e))(c),e===h){var f=d.apply(this,c);return f=b(f)}var g=Function.prototype.bind.apply(d,[this].concat(c)),i=u(a.slice(e),b);return i.of(g)}return c("function"==typeof d),f.is(d)?d:(e.func={domain:a,codomain:b,f:d},e)},f}var v=!1,w={onFail:a},x=Array.prototype.slice;e.formatters={s:function(a){return String(a)},j:function(a){return JSON.stringify(a,f)}},k.commands={$apply:function(a,b){return c(F.is(a)),a(b)},$push:function(a,b){return c(D.is(a)),c(D.is(b)),b.concat(a)},$remove:function(a,b){c(D.is(a)),c(E.is(b));for(var d=0,e=a.length;e>d;d++)delete b[a[d]];return b},$set:function(a){return a},$splice:function(a,b){return c(s(D).is(a)),c(D.is(b)),a.reduce(function(a,b){return a.splice.apply(a,b),a},b)},$swap:function(a,b){c(E.is(a)),c(B.is(a.from)),c(B.is(a.to)),c(D.is(b));var d=b[a.to];return b[a.to]=b[a.from],b[a.from]=d,b},$unshift:function(a,b){return c(D.is(a)),c(D.is(b)),a.concat(b)}};var y=l("Any",function(){return!0}),z=l("Nil",function(a){return null===a||void 0===a}),A=l("Str",function(a){return"string"==typeof a}),B=l("Num",function(a){return"number"==typeof a&&isFinite(a)&&!isNaN(a)}),C=l("Bool",function(a){return a===!0||a===!1}),D=l("Arr",function(a){return a instanceof Array}),E=l("Obj",function(a){return!z.is(a)&&"object"==typeof a&&!D.is(a)}),F=l("Func",function(a){return"function"==typeof a}),G=l("Err",function(a){return a instanceof Error}),H=l("Re",function(a){return a instanceof RegExp}),I=l("Dat",function(a){return a instanceof Date}),J=l("Type",function(a){return F.is(a)&&E.is(a.meta)});return p.of=function(a,b){a=A.is(a)?a.split(" "):a;var c={};return a.forEach(function(a){c[a]=a}),p(c,b)},u.is=function(a){return F.is(a)&&E.is(a.func)},{util:{mixin:d,format:e,getName:g,getKind:h,slice:x,shallowCopy:j,update:k},options:w,assert:c,fail:b,Any:y,Nil:z,Str:A,Num:B,Bool:C,Arr:D,Obj:E,Func:F,Err:G,Re:H,Dat:I,Type:J,irriducible:l,struct:m,enums:p,union:n,maybe:o,tuple:q,subtype:r,list:s,dict:t,func:u}});
!function(a,b){"use strict";"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.t=b()}(this,function(){"use strict";function a(a){throw v=!0,new Error(a)}function b(a){w.onFail(a)}function c(a){if(a!==!0){var c=x.call(arguments,1),d=c[0]?e.apply(null,c):"assert failed";b(d)}}function d(a,b,d){if(z.is(b))return a;for(var e in b)b.hasOwnProperty(e)&&(d!==!0&&c(!a.hasOwnProperty(e),"cannot overwrite property %s",e),a[e]=b[e]);return a}function e(){function a(a,f){if("%%"===a)return"%";if(d>=c)return a;var g=e.formatters[f];return g?g(b[d++]):a}var b=x.call(arguments),c=b.length,d=1,f=b[0],g=f.replace(/%([a-z%])/g,a);return c>d&&(g+=" "+b.slice(d).join(" ")),g}function f(a,b){return"function"==typeof b?e("Func",b.name):b}function g(a){return c(J.is(a),"Invalid argument `type` of value `%j` supplied to `getName()`, expected a type.",a),a.meta.name}function h(a){return c(J.is(a),"Invalid argument `type` of value `%j` supplied to `geKind()`, expected a type.",a),a.meta.kind}function i(a,b){c(!(a instanceof b),"Operator `new` is forbidden for `%s`",g(b))}function j(a){return D.is(a)?a.concat():E.is(a)?d({},a):a}function k(a,b){c(E.is(b));var d=j(a);for(var e in b)if(b.hasOwnProperty(e)){if(k.commands.hasOwnProperty(e))return c(1===Object.keys(b).length),k.commands[e](b[e],d);d[e]=k(d[e],b[e])}return d}function l(a,b){function d(e){return i(this,d),c(b(e),"Invalid `%s` supplied to `%s`",e,a),e}return c("string"==typeof a,"Invalid argument `name` supplied to `irriducible()`"),c("function"==typeof b,"Invalid argument `is` supplied to `irriducible()`"),d.meta={kind:"irriducible",name:a},d.displayName=a,d.is=b,d}function m(a,b){function e(d,f){if(e.is(d))return d;if(c(E.is(d),"Invalid `%s` supplied to `%s`, expected an `Obj`",d,b),!(this instanceof e))return new e(d,f);for(var g in a)if(a.hasOwnProperty(g)){var h=a[g],i=d[g];this[g]=h(i,f)}f!==!0&&Object.freeze(this)}return c(t(A,J).is(a),"Invalid argument `props` supplied to `struct()`"),c(o(A).is(b),"Invalid argument `name` supplied to `struct()`"),b=b||"struct",e.meta={kind:"struct",props:a,name:b},e.displayName=b,e.is=function(a){return a instanceof e},e.update=function(a,b,c){return new e(k(a,b,c))},e.extend=function(b,c){return m([a].concat(b).reduce(d,{}),c)},e}function n(a,b){function d(a,e){i(this,d),c(F.is(d.dispatch),"unimplemented %s.dispatch()",b);var f=d.dispatch(a);return c(J.is(f),"%s.dispatch() returns no type",b),f(a,e)}c(s(J).is(a),"Invalid argument `types` supplied to `union()`");var f=a.length;return c(f>=2,"Invalid argument `types` supplied to `union()`"),c(o(A).is(b),"Invalid argument `name` supplied to `union()`"),b=b||e("union([%s])",a.map(g).join(", ")),d.meta={kind:"union",types:a,name:b},d.displayName=b,d.is=function(b){return a.some(function(a){return a.is(b)})},d.dispatch=function(b){for(var c=0,d=a.length;d>c;c++)if(a[c].is(b))return a[c]},d}function o(a,b){function d(b,c){return i(this,d),z.is(b)?null:a(b,c)}return c(J.is(a),"Invalid argument `type` supplied to `maybe()`"),"maybe"===h(a)?a:(c(z.is(b)||A.is(b),"Invalid argument `name` supplied to `maybe()`"),b=b||e("maybe(%s)",g(a)),d.meta={kind:"maybe",type:a,name:b},d.displayName=b,d.is=function(b){return z.is(b)||a.is(b)},d)}function p(a,b){function d(a){return i(this,d),c(d.is(a),"Invalid `%s` supplied to `%s`, expected one of %j",a,b,e),a}c(E.is(a),"Invalid argument `map` supplied to `enums()`"),c(o(A).is(b),"Invalid argument `name` supplied to `enums()`"),b=b||"enums";var e=Object.keys(a);return d.meta={kind:"enums",map:a,name:b},d.displayName=b,d.is=function(b){return A.is(b)&&a.hasOwnProperty(b)},d}function q(a,b){function d(e,g){if(c(D.is(e)&&e.length===f,"Invalid `%s` supplied to `%s`, expected an `Arr` of length `%s`",e,b,f),d.isTuple(e))return e;for(var h=[],i=0;f>i;i++){var j=a[i],k=e[i];h.push(j(k,g))}return g!==!0&&Object.freeze(h),h}c(s(J).is(a),"Invalid argument `types` supplied to `tuple()`");var f=a.length;return c(o(A).is(b),"Invalid argument `name` supplied to `tuple()`"),b=b||e("tuple([%s])",a.map(g).join(", ")),d.meta={kind:"tuple",types:a,length:f,name:b},d.displayName=b,d.isTuple=function(b){return a.every(function(a,c){return a.is(b[c])})},d.is=function(a){return D.is(a)&&a.length===f&&d.isTuple(a)},d.update=function(a,b,c){return d(k(a,b,c))},d}function r(a,b,d){function f(e,g){i(this,f);var j=a(e,g);return c(b(j),"Invalid `%s` supplied to `%s`, %s",e,d,h),j}c(J.is(a),"Invalid argument `type` supplied to `subtype()`"),c(F.is(b),"Invalid argument `predicate` supplied to `subtype()`"),c(o(A).is(d),"Invalid argument `name` supplied to `subtype()`"),d=d||e("subtype(%s)",g(a));var h=b.__doc__||e("insert a valid value for %s",b.name||"the subtype");return f.meta={kind:"subtype",type:a,predicate:b,name:d},f.displayName=d,f.is=function(c){return a.is(c)&&b(c)},f.update=function(a,b,c){return f(k(a,b,c))},f}function s(a,b){function d(e,f){if(c(D.is(e),"Invalid `%s` supplied to `%s`, expected an `Arr`",e,b),d.isList(e))return e;for(var g=[],h=0,i=e.length;i>h;h++){var j=e[h];g.push(a(j,f))}return f!==!0&&Object.freeze(g),g}return c(J.is(a),"Invalid argument `type` supplied to `list()`"),c(o(A).is(b),"Invalid argument `name` supplied to `list()`"),b=b||e("list(%s)",g(a)),d.meta={kind:"list",type:a,name:b},d.displayName=b,d.isList=function(b){return b.every(a.is)},d.is=function(a){return D.is(a)&&d.isList(a)},d.update=function(a,b,c){return d(k(a,b,c))},d}function t(a,b,d){function f(e,g){if(c(E.is(e),"Invalid `%s` supplied to `%s`, expected an `Obj`",e,d),f.isDict(e))return e;var h={};for(var i in e)if(e.hasOwnProperty(i)){i=a(i);var j=e[i];h[i]=b(j,g)}return g!==!0&&Object.freeze(h),h}return c(J.is(a),"Invalid argument `domain` supplied to `dict()`"),c(J.is(b),"Invalid argument `codomain` supplied to `dict()`"),c(o(A).is(d),"Invalid argument `name` supplied to `dict()`"),d=d||e("dict(%s, %s)",g(a),g(b)),f.meta={kind:"dict",domain:a,codomain:b,name:d},f.displayName=d,f.isDict=function(c){for(var d in c)if(c.hasOwnProperty(d)&&(!a.is(d)||!b.is(c[d])))return!1;return!0},f.is=function(a){return E.is(a)&&f.isDict(a)},f.update=function(a,b,c){return f(k(a,b,c))},f}function u(a,b,d){function f(a){return u.is(a)||(a=f.of(a)),c(f.is(a),"Invalid `%s` supplied to `%s`",a,d),a}a=D.is(a)?a:[a],c(s(J).is(a),"Invalid argument `domain` supplied to `func()`"),c(J.is(b),"Invalid argument `codomain` supplied to `func()`"),d=d||e("func([%s], %s)",a.map(g).join(", "),g(b));var h=a.length;return f.meta={kind:"func",domain:a,codomain:b,name:d},f.displayName=d,f.is=function(c){return u.is(c)&&c.func.domain.length===a.length&&c.func.domain.every(function(b,c){return b===a[c]})&&c.func.codomain===b},f.of=function(d){function e(){var c=x.call(arguments),e=Math.min(c.length,h);if(c=q(a.slice(0,e))(c),e===h){var f=d.apply(this,c);return f=b(f)}var g=Function.prototype.bind.apply(d,[this].concat(c)),i=u(a.slice(e),b);return i.of(g)}return c("function"==typeof d),f.is(d)?d:(e.func={domain:a,codomain:b,f:d},e)},f}var v=!1,w={onFail:a},x=Array.prototype.slice;e.formatters={s:function(a){return String(a)},j:function(a){return JSON.stringify(a,f)}},k.commands={$apply:function(a,b){return c(F.is(a)),a(b)},$push:function(a,b){return c(D.is(a)),c(D.is(b)),b.concat(a)},$remove:function(a,b){c(D.is(a)),c(E.is(b));for(var d=0,e=a.length;e>d;d++)delete b[a[d]];return b},$set:function(a){return a},$splice:function(a,b){return c(s(D).is(a)),c(D.is(b)),a.reduce(function(a,b){return a.splice.apply(a,b),a},b)},$swap:function(a,b){c(E.is(a)),c(B.is(a.from)),c(B.is(a.to)),c(D.is(b));var d=b[a.to];return b[a.to]=b[a.from],b[a.from]=d,b},$unshift:function(a,b){return c(D.is(a)),c(D.is(b)),a.concat(b)}};var y=l("Any",function(){return!0}),z=l("Nil",function(a){return null===a||void 0===a}),A=l("Str",function(a){return"string"==typeof a}),B=l("Num",function(a){return"number"==typeof a&&isFinite(a)&&!isNaN(a)}),C=l("Bool",function(a){return a===!0||a===!1}),D=l("Arr",function(a){return a instanceof Array}),E=l("Obj",function(a){return!z.is(a)&&"object"==typeof a&&!D.is(a)}),F=l("Func",function(a){return"function"==typeof a}),G=l("Err",function(a){return a instanceof Error}),H=l("Re",function(a){return a instanceof RegExp}),I=l("Dat",function(a){return a instanceof Date}),J=l("Type",function(a){return F.is(a)&&E.is(a.meta)});return p.of=function(a,b){a=A.is(a)?a.split(" "):a;var c={};return a.forEach(function(a){c[a]=a}),p(c,b)},u.is=function(a){return F.is(a)&&E.is(a.func)},{util:{mixin:d,format:e,getName:g,getKind:h,slice:x,shallowCopy:j,update:k},options:w,assert:c,fail:b,Any:y,Nil:z,Str:A,Num:B,Bool:C,Arr:D,Obj:E,Func:F,Err:G,Re:H,Dat:I,Type:J,irriducible:l,struct:m,enums:p,union:n,maybe:o,tuple:q,subtype:r,list:s,dict:t,func:u}});
//# sourceMappingURL=tcomb.min.js.map

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc