Comparing version 0.0.9 to 0.0.10
@@ -1,2 +0,2 @@ | ||
// tcomb 0.0.9 | ||
// tcomb 0.0.10 | ||
// https://github.com/gcanti/tcomb | ||
@@ -21,29 +21,44 @@ // (c) 2014 Giulio Canti <giulio.canti@gmail.com> | ||
// | ||
// assert | ||
// options | ||
// | ||
function assert(guard) { | ||
if (guard !== true) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
var message = args[0] ? print.apply(null, args) : 'assert(): failed'; | ||
assert.onFail(message); | ||
} | ||
} | ||
var failed = false; | ||
assert.failed = false; | ||
assert.onFail = function (message) { | ||
function onFail(message) { | ||
// start debugger only once | ||
if (!assert.failed) { | ||
if (!failed) { | ||
/*jshint debug: true*/ | ||
debugger; | ||
} | ||
assert.failed = true; | ||
failed = true; | ||
throw new Error(message); | ||
} | ||
var options = { | ||
onFail: onFail, | ||
update: null | ||
}; | ||
// | ||
// assert | ||
// | ||
function fail(message) { | ||
options.onFail(message); | ||
} | ||
function assert(guard) { | ||
if (guard !== true) { | ||
var args = slice.call(arguments, 1); | ||
var message = args[0] ? format.apply(null, args) : 'assert(): failed'; | ||
fail(message); | ||
} | ||
} | ||
// | ||
// utils | ||
// | ||
var slice = Array.prototype.slice; | ||
function freeze(obj_or_arr, unless) { | ||
@@ -56,90 +71,74 @@ if (unless !== true && Object.freeze) { | ||
function mixin(x, y, overwrite) { | ||
for (var k in y) { | ||
if (y.hasOwnProperty(k)) { | ||
function mixin(target, source, overwrite) { | ||
for (var k in source) { | ||
if (source.hasOwnProperty(k)) { | ||
if (!overwrite) { | ||
assert(!x.hasOwnProperty(k), 'mixin(): cannot overwrite property %s', k); | ||
assert(!target.hasOwnProperty(k), 'cannot overwrite property %s', k); | ||
} | ||
x[k] = y[k]; | ||
target[k] = source[k]; | ||
} | ||
} | ||
return x; | ||
return target; | ||
} | ||
function getName(type) { | ||
return type.meta && type.meta.name ? type.meta.name : type.name || 'Unknown'; | ||
function getName(type) { | ||
assert(Obj.is(type.meta), 'missing type meta hash'); | ||
return type.meta.name; | ||
} | ||
function print() { | ||
var args = Array.prototype.slice.call(arguments); | ||
var index = 0; | ||
return args[0].replace(/%([a-z%])/g, function(match, format) { | ||
if (match === '%%') return match; | ||
index++; | ||
var formatter = print.formatters[format]; | ||
var arg = args[index]; | ||
return formatter(arg); | ||
function format() { | ||
var args = slice.call(arguments); | ||
var len = args.length; | ||
var i = 1; | ||
var message = args[0]; | ||
var str = message.replace(/%([a-z%])/g, function(match, type) { | ||
if (match === '%%') { return '%'; } // handle escaping % | ||
if (i >= len) { return match; } // handle less arguments than placeholders | ||
var formatter = format.formatters[type]; | ||
if (!formatter) { return match; } // handle undefined formatters | ||
return formatter(args[i++]); | ||
}); | ||
if (i < len) { | ||
str += ' ' + args.slice(i).join(' '); // handle more arguments than placeholders | ||
} | ||
return str; | ||
} | ||
print.formatters = { | ||
format.formatters = { | ||
s: function (x) { return String(x); }, | ||
o: function (x) { return JSON.stringify(x); } | ||
j: function (x) { return JSON.stringify(x); } | ||
}; | ||
// array manipulation | ||
function isValidIndex(index, from, to) { | ||
return Num.is(index) && index >= from && index <= to; | ||
function coerce(type, values, mut) { | ||
return type.meta.ctor ? | ||
/*jshint newcap: false*/ | ||
new type(values, mut) : | ||
type(values, mut); | ||
} | ||
function append(arr, element) { | ||
assert(Arr.is(arr), 'append(): bad array'); | ||
var ret = arr.slice(); | ||
ret.push(element); | ||
return ret; | ||
function update() { | ||
assert(Func.is(options.update), 'options.update is missing'); | ||
/*jshint validthis:true*/ | ||
var Type = this; | ||
var args = slice.call(arguments); | ||
var values = options.update.apply(Type, args); | ||
return coerce(Type, values); | ||
} | ||
// | ||
// Any - because sometimes you really gonna need it | ||
// | ||
function prepend(arr, element) { | ||
assert(Arr.is(arr), 'prepend(): bad array'); | ||
var ret = arr.slice(); | ||
ret.unshift(element); | ||
return ret; | ||
function Any(values) { | ||
assert(!(this instanceof Any), 'cannot use new with Any'); | ||
return values; | ||
} | ||
function update(arr, index, element) { | ||
assert(Arr.is(arr), 'update(): bad array'); | ||
assert(isValidIndex(index, 0, arr.length - 1), 'update(): bad index'); | ||
var ret = arr.slice(); | ||
ret[index] = element; | ||
return ret; | ||
} | ||
Any.meta = { | ||
kind: 'any', | ||
name: 'Any', | ||
ctor: false | ||
}; | ||
function remove(arr, index) { | ||
assert(Arr.is(arr), 'remove(): bad array'); | ||
assert(isValidIndex(index, 0, arr.length - 1), 'remove(): bad index'); | ||
var ret = arr.slice(); | ||
ret.splice(index, 1); | ||
return ret; | ||
} | ||
function move(arr, from, to) { | ||
assert(Arr.is(arr), 'move(): bad array'); | ||
assert(isValidIndex(from, 0, arr.length - 1), 'move(): bad from'); | ||
assert(isValidIndex(to, 0, arr.length - 1), 'move(): bad to'); | ||
var ret = arr.slice(); | ||
if (from === to) { | ||
return ret; | ||
} | ||
var element = ret.splice(from, 1)[0]; | ||
ret.splice(to, 0, element); | ||
return ret; | ||
} | ||
function coerce(type, values, mut) { | ||
return type.meta.kind === 'struct' ? | ||
/*jshint newcap: false*/ | ||
new type(values, mut) : | ||
type(values, mut); | ||
} | ||
Any.is = function () { return true; }; | ||
@@ -200,2 +199,10 @@ // | ||
}); | ||
var Re = primitive('Re', function (x) { | ||
return x instanceof RegExp; | ||
}); | ||
var Dat = primitive('Dat', function (x) { | ||
return x instanceof Date; | ||
}); | ||
@@ -213,3 +220,2 @@ // | ||
assert(Obj.is(values), 'bad %s', name); | ||
assert(maybe(Bool).is(mut), 'bad mut'); | ||
@@ -238,16 +244,4 @@ for (var prop in props) { | ||
Struct.update = function (instance, updates, mut) { | ||
Struct.update = update; | ||
assert(Struct.is(instance)); | ||
assert(Obj.is(updates)); | ||
var v = {}; | ||
for (var prop in props) { | ||
if (props.hasOwnProperty(prop)) { | ||
v[prop] = updates.hasOwnProperty(prop) ? updates[prop] : instance[prop]; | ||
} | ||
} | ||
return new Struct(v, mut); | ||
}; | ||
return Struct; | ||
@@ -262,3 +256,3 @@ } | ||
name = name || print('union(%s)', types.map(getName).join(', ')); | ||
name = name || format('union(%s)', types.map(getName).join(', ')); | ||
@@ -296,3 +290,3 @@ function Union(values, mut) { | ||
name = name || print('maybe(%s)', getName(Type)); | ||
name = name || format('maybe(%s)', getName(Type)); | ||
@@ -308,3 +302,3 @@ function Maybe(values, mut) { | ||
name: name, | ||
ctor: false | ||
ctor: false // cannot use new with null | ||
}; | ||
@@ -328,4 +322,4 @@ | ||
function Enums(x) { | ||
assert(Enums.is(x), 'bad %s', name); | ||
assert(!(this instanceof Enums), 'cannot use new with %s', name); | ||
assert(Enums.is(x), 'bad %s', name); | ||
return x; | ||
@@ -363,3 +357,3 @@ } | ||
name = name || print('tuple(%s)', types.map(getName).join(', ')); | ||
name = name || format('tuple(%s)', types.map(getName).join(', ')); | ||
@@ -396,8 +390,3 @@ var len = types.length; | ||
Tuple.update = function (instance, index, element, mut) { | ||
var Type = types[index], | ||
value = Type.is(element) ? element : coerce(Type, element, mut), | ||
arr = update(instance, index, value); | ||
return freeze(arr, mut); | ||
}; | ||
Tuple.update = update; | ||
@@ -413,3 +402,3 @@ return Tuple; | ||
name = name || print('subtype(%s)', getName(Type)); | ||
name = name || format('subtype(%s)', getName(Type)); | ||
@@ -430,3 +419,3 @@ function Subtype(values, mut) { | ||
name: name, | ||
ctor: Type.ctor | ||
ctor: Type.meta.ctor | ||
}; | ||
@@ -447,3 +436,3 @@ | ||
name = name || print('list(%s)', getName(Type)); | ||
name = name || format('list(%s)', getName(Type)); | ||
@@ -474,30 +463,5 @@ function List(values, mut) { | ||
List.append = function (instance, element, mut) { | ||
var value = Type.is(element) ? element : coerce(Type, element, mut), | ||
arr = append(instance, value); | ||
return freeze(arr, mut); | ||
}; | ||
List.prepend = function (instance, element, mut) { | ||
var value = Type.is(element) ? element : coerce(Type, element, mut), | ||
arr = prepend(instance, value); | ||
return freeze(arr, mut); | ||
}; | ||
List.update = update; | ||
List.update = function (instance, index, element, mut) { | ||
var value = Type.is(element) ? element : coerce(Type, element, mut), | ||
arr = update(instance, index, value); | ||
return freeze(arr, mut); | ||
}; | ||
List.remove = function (instance, index, mut) { | ||
var arr = remove(instance, index); | ||
return freeze(arr, mut); | ||
}; | ||
List.move = function (instance, from, to, mut) { | ||
var arr = move(instance, from, to); | ||
return freeze(arr, mut); | ||
}; | ||
return List; | ||
@@ -513,3 +477,3 @@ } | ||
function g() { | ||
var args = Array.prototype.slice.call(arguments); | ||
var args = slice.call(arguments); | ||
if (args.length < f.length) args.length = f.length; // handle optional arguments | ||
@@ -542,13 +506,13 @@ | ||
return { | ||
options: options, | ||
assert: assert, | ||
freeze: freeze, | ||
mixin: mixin, | ||
append: append, | ||
prepend: prepend, | ||
update: update, | ||
remove: remove, | ||
move: move, | ||
print: print, | ||
format: format, | ||
coerce: coerce, | ||
getName: getName, | ||
Any: Any, | ||
Nil: Nil, | ||
@@ -562,2 +526,4 @@ Str: Str, | ||
Err: Err, | ||
Re: Re, | ||
Dat: Dat, | ||
@@ -564,0 +530,0 @@ struct: struct, |
@@ -1,2 +0,2 @@ | ||
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.t=b()}(this,function(){"use strict";function a(b){if(b!==!0){var c=Array.prototype.slice.call(arguments,1),d=c[0]?e.apply(null,c):"assert(): failed";a.onFail(d)}}function b(a,b){return b!==!0&&Object.freeze&&Object.freeze(a),a}function c(b,c,d){for(var e in c)c.hasOwnProperty(e)&&(d||a(!b.hasOwnProperty(e),"mixin(): cannot overwrite property %s",e),b[e]=c[e]);return b}function d(a){return a.meta&&a.meta.name?a.meta.name:a.name||"Unknown"}function e(){var a=Array.prototype.slice.call(arguments),b=0;return a[0].replace(/%([a-z%])/g,function(c,d){if("%%"===c)return c;b++;var f=e.formatters[d],g=a[b];return f(g)})}function f(a,b,c){return x.is(a)&&a>=b&&c>=a}function g(b,c){a(z.is(b),"append(): bad array");var d=b.slice();return d.push(c),d}function h(b,c){a(z.is(b),"prepend(): bad array");var d=b.slice();return d.unshift(c),d}function i(b,c,d){a(z.is(b),"update(): bad array"),a(f(c,0,b.length-1),"update(): bad index");var e=b.slice();return e[c]=d,e}function j(b,c){a(z.is(b),"remove(): bad array"),a(f(c,0,b.length-1),"remove(): bad index");var d=b.slice();return d.splice(c,1),d}function k(b,c,d){a(z.is(b),"move(): bad array"),a(f(c,0,b.length-1),"move(): bad from"),a(f(d,0,b.length-1),"move(): bad to");var e=b.slice();if(c===d)return e;var g=e.splice(c,1)[0];return e.splice(d,0,g),e}function l(a,b,c){return"struct"===a.meta.kind?new a(b,c):a(b,c)}function m(b,c){function d(c){return a(!(this instanceof d),"cannot use new with %s",b),a(d.is(c),"bad %s",b),c}return d.meta={kind:"primitive",name:b,ctor:!1},d.is=c,d}function n(c,d){function e(e,f){a(A.is(e),"bad %s",d),a(p(y).is(f),"bad mut");for(var g in c)if(c.hasOwnProperty(g)){var h=c[g],i=e[g];this[g]=h.is(i)?i:l(h,i,f)}b(this,f)}return d=d||"struct()",e.meta={kind:"struct",props:c,name:d,ctor:!0},e.is=function(a){return a instanceof e},e.update=function(b,d,f){a(e.is(b)),a(A.is(d));var g={};for(var h in c)c.hasOwnProperty(h)&&(g[h]=d.hasOwnProperty(h)?d[h]:b[h]);return new e(g,f)},e}function o(b,c){function f(b,d){a(B.is(f.dispatch),"unimplemented %s.dispatch()",c);var e=f.dispatch(b);return this instanceof f&&a(e.meta.ctor,"cannot use new with %s",c),l(e,b,d)}return c=c||e("union(%s)",b.map(d).join(", ")),f.meta={kind:"union",types:b,name:c,ctor:b.every(function(a){return a.meta.ctor})},f.is=function(a){return b.some(function(b){return b.is(a)})},f}function p(b,c){function f(d,e){return a(!(this instanceof f),"cannot use new with %s",c),v.is(d)?null:l(b,d,e)}return c=c||e("maybe(%s)",d(b)),f.meta={kind:"maybe",type:b,name:c,ctor:!1},f.is=function(a){return v.is(a)||b.is(a)},f}function q(b,c){function d(b){return a(!(this instanceof d),"cannot use new with %s",c),a(d.is(b),"bad %s",c),b}return c=c||"enums()",d.meta={kind:"enums",map:b,name:c,ctor:!1},d.is=function(a){return w.is(a)&&b.hasOwnProperty(a)},d}function r(c,f){function g(d,e){a(z.is(d),"bad %s",f);for(var g=[],i=0;h>i;i++){var j=c[i],k=d[i];g.push(j.is(k)?k:l(j,k,e))}return b(g,e)}f=f||e("tuple(%s)",c.map(d).join(", "));var h=c.length;return g.meta={kind:"tuple",types:c,name:f,ctor:!0},g.is=function(a){return z.is(a)&&a.length===h&&c.every(function(b,c){return b.is(a[c])})},g.update=function(a,d,e,f){var g=c[d],h=g.is(e)?e:l(g,e,f),j=i(a,d,h);return b(j,f)},g}function s(b,c,f){function g(d,e){this instanceof g&&a(g.meta.ctor,"cannot use new with %s",f);var h=l(b,d,e);return a(c(h),"bad %s",f),h}return f=f||e("subtype(%s)",d(b)),g.meta={kind:"subtype",type:b,predicate:c,name:f,ctor:b.ctor},g.is=function(a){return b.is(a)&&c(a)},g}function t(c,f){function m(d,e){a(z.is(d),"bad %s",f);for(var g=[],h=0,i=d.length;i>h;h++){var j=d[h];g.push(c.is(j)?j:l(c,j,e))}return b(g,e)}return f=f||e("list(%s)",d(c)),m.meta={kind:"list",type:c,name:f,ctor:!0},m.is=function(a){return z.is(a)&&a.every(c.is)},m.append=function(a,d,e){var f=c.is(d)?d:l(c,d,e),h=g(a,f);return b(h,e)},m.prepend=function(a,d,e){var f=c.is(d)?d:l(c,d,e),g=h(a,f);return b(g,e)},m.update=function(a,d,e,f){var g=c.is(e)?e:l(c,e,f),h=i(a,d,g);return b(h,f)},m.remove=function(a,c,d){var e=j(a,c);return b(e,d)},m.move=function(a,c,d,e){var f=k(a,c,d);return b(f,e)},m}function u(a,b,c,d){function e(){var d=Array.prototype.slice.call(arguments);d.length<b.length&&(d.length=b.length),d=a.is(d)?d:l(a,d);var e=b.apply(null,d);return c&&(e=c.is(e)?e:l(c,e)),e}return e.is=function(a){return a===e},e.meta={kind:"func",Arguments:a,f:b,Return:c,name:d},e}a.failed=!1,a.onFail=function(b){throw!a.failed,a.failed=!0,new Error(b)},e.formatters={s:function(a){return String(a)},o:function(a){return JSON.stringify(a)}};var v=m("Nil",function(a){return null===a||void 0===a}),w=m("Str",function(a){return"string"==typeof a}),x=m("Num",function(a){return"number"==typeof a&&isFinite(a)&&!isNaN(a)}),y=m("Bool",function(a){return a===!0||a===!1}),z=m("Arr",function(a){return a instanceof Array}),A=m("Obj",function(a){return!v.is(a)&&a.constructor===Object&&!z.is(a)}),B=m("Func",function(a){return"function"==typeof a}),C=m("Err",function(a){return a instanceof Error});return q.of=function(a,b){a=w.is(a)?a.split(" "):a;var c={};return a.forEach(function(a,b){c[a]=b}),q(c,b)},{assert:a,freeze:b,mixin:c,append:g,prepend:h,update:i,remove:j,move:k,print:e,getName:d,Nil:v,Str:w,Num:x,Bool:y,Arr:z,Obj:A,Func:B,Err:C,struct:n,enums:q,union:o,maybe:p,tuple:r,subtype:s,list:t,func:u}}); | ||
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.t=b()}(this,function(){"use strict";function a(a){throw t=!0,new Error(a)}function b(a){u.onFail(a)}function c(a){if(a!==!0){var c=v.call(arguments,1),d=c[0]?g.apply(null,c):"assert(): failed";b(d)}}function d(a,b){return b!==!0&&Object.freeze&&Object.freeze(a),a}function e(a,b,d){for(var e in b)b.hasOwnProperty(e)&&(d||c(!a.hasOwnProperty(e),"cannot overwrite property %s",e),a[e]=b[e]);return a}function f(a){return c(B.is(a.meta),"missing type meta hash"),a.meta.name}function g(){var a=v.call(arguments),b=a.length,c=1,d=a[0],e=d.replace(/%([a-z%])/g,function(d,e){if("%%"===d)return"%";if(c>=b)return d;var f=g.formatters[e];return f?f(a[c++]):d});return b>c&&(e+=" "+a.slice(c).join(" ")),e}function h(a,b,c){return a.meta.ctor?new a(b,c):a(b,c)}function i(){c(C.is(u.update),"options.update is missing");var a=this,b=v.call(arguments),d=u.update.apply(a,b);return h(a,d)}function j(a){return c(!(this instanceof j),"cannot use new with Any"),a}function k(a,b){function d(b){return c(!(this instanceof d),"cannot use new with %s",a),c(d.is(b),"bad %s",a),b}return d.meta={kind:"primitive",name:a,ctor:!1},d.is=b,d}function l(a,b){function e(e,f){c(B.is(e),"bad %s",b);for(var g in a)if(a.hasOwnProperty(g)){var i=a[g],j=e[g];this[g]=i.is(j)?j:h(i,j,f)}d(this,f)}return b=b||"struct()",e.meta={kind:"struct",props:a,name:b,ctor:!0},e.is=function(a){return a instanceof e},e.update=i,e}function m(a,b){function d(a,e){c(C.is(d.dispatch),"unimplemented %s.dispatch()",b);var f=d.dispatch(a);return this instanceof d&&c(f.meta.ctor,"cannot use new with %s",b),h(f,a,e)}return b=b||g("union(%s)",a.map(f).join(", ")),d.meta={kind:"union",types:a,name:b,ctor:a.every(function(a){return a.meta.ctor})},d.is=function(b){return a.some(function(a){return a.is(b)})},d}function n(a,b){function d(e,f){return c(!(this instanceof d),"cannot use new with %s",b),w.is(e)?null:h(a,e,f)}return b=b||g("maybe(%s)",f(a)),d.meta={kind:"maybe",type:a,name:b,ctor:!1},d.is=function(b){return w.is(b)||a.is(b)},d}function o(a,b){function d(a){return c(d.is(a),"bad %s",b),c(!(this instanceof d),"cannot use new with %s",b),a}return b=b||"enums()",d.meta={kind:"enums",map:a,name:b,ctor:!1},d.is=function(b){return x.is(b)&&a.hasOwnProperty(b)},d}function p(a,b){function e(e,f){c(A.is(e),"bad %s",b);for(var g=[],i=0;j>i;i++){var k=a[i],l=e[i];g.push(k.is(l)?l:h(k,l,f))}return d(g,f)}b=b||g("tuple(%s)",a.map(f).join(", "));var j=a.length;return e.meta={kind:"tuple",types:a,name:b,ctor:!0},e.is=function(b){return A.is(b)&&b.length===j&&a.every(function(a,c){return a.is(b[c])})},e.update=i,e}function q(a,b,d){function e(f,g){this instanceof e&&c(e.meta.ctor,"cannot use new with %s",d);var i=h(a,f,g);return c(b(i),"bad %s",d),i}return d=d||g("subtype(%s)",f(a)),e.meta={kind:"subtype",type:a,predicate:b,name:d,ctor:a.meta.ctor},e.is=function(c){return a.is(c)&&b(c)},e}function r(a,b){function e(e,f){c(A.is(e),"bad %s",b);for(var g=[],i=0,j=e.length;j>i;i++){var k=e[i];g.push(a.is(k)?k:h(a,k,f))}return d(g,f)}return b=b||g("list(%s)",f(a)),e.meta={kind:"list",type:a,name:b,ctor:!0},e.is=function(b){return A.is(b)&&b.every(a.is)},e.update=i,e}function s(a,b,c,d){function e(){var d=v.call(arguments);d.length<b.length&&(d.length=b.length),d=a.is(d)?d:h(a,d);var e=b.apply(null,d);return c&&(e=c.is(e)?e:h(c,e)),e}return e.is=function(a){return a===e},e.meta={kind:"func",Arguments:a,f:b,Return:c,name:d},e}var t=!1,u={onFail:a,update:null},v=Array.prototype.slice;g.formatters={s:function(a){return String(a)},j:function(a){return JSON.stringify(a)}},j.meta={kind:"any",name:"Any",ctor:!1},j.is=function(){return!0};var w=k("Nil",function(a){return null===a||void 0===a}),x=k("Str",function(a){return"string"==typeof a}),y=k("Num",function(a){return"number"==typeof a&&isFinite(a)&&!isNaN(a)}),z=k("Bool",function(a){return a===!0||a===!1}),A=k("Arr",function(a){return a instanceof Array}),B=k("Obj",function(a){return!w.is(a)&&a.constructor===Object&&!A.is(a)}),C=k("Func",function(a){return"function"==typeof a}),D=k("Err",function(a){return a instanceof Error}),E=k("Re",function(a){return a instanceof RegExp}),F=k("Dat",function(a){return a instanceof Date});return o.of=function(a,b){a=x.is(a)?a.split(" "):a;var c={};return a.forEach(function(a,b){c[a]=b}),o(c,b)},{options:u,assert:c,freeze:d,mixin:e,format:g,coerce:h,getName:f,Any:j,Nil:w,Str:x,Num:y,Bool:z,Arr:A,Obj:B,Func:C,Err:D,Re:E,Dat:F,struct:l,enums:o,union:m,maybe:n,tuple:p,subtype:q,list:r,func:s}}); | ||
//# sourceMappingURL=tcomb.min.js.map |
@@ -65,4 +65,3 @@ module.exports = function (grunt) { | ||
tasks: [ | ||
'rig', | ||
'test' | ||
'default' | ||
] | ||
@@ -83,4 +82,4 @@ } | ||
grunt.registerTask('test', ['mochaTest']); | ||
grunt.registerTask('default', ['rig', 'jshint', 'test', 'watch']); | ||
grunt.registerTask('build', ['rig', 'jshint', 'uglify']); | ||
grunt.registerTask('default', ['rig', 'test', 'watch']); | ||
grunt.registerTask('build', ['rig', 'jshint', 'test', 'uglify']); | ||
}; |
{ | ||
"name": "tcomb", | ||
"version": "0.0.9", | ||
"description": "JavaScript types and combinators", | ||
"version": "0.0.10", | ||
"description": "Runtime types checking for JavaScript ", | ||
"main": "build/tcomb.js", | ||
@@ -11,3 +11,3 @@ "scripts": { | ||
"start": "grunt", | ||
"coverage": "istanbul cover _mocha -- --ui bdd -R spec -t 5000" | ||
"coverage": "istanbul cover _mocha -- --ui bdd -R dot" | ||
}, | ||
@@ -41,2 +41,3 @@ "repository": { | ||
"combinators", | ||
"checking", | ||
"safety", | ||
@@ -43,0 +44,0 @@ "models", |
@@ -159,4 +159,3 @@ # tcomb | ||
- `guard` boolean condition | ||
- `message` optional string useful for debugging | ||
- `values...` optional values formatted by `message` ([visionmedia/debug](https://github.com/visionmedia/debug) style) | ||
- `message` optional string useful for debugging, formatted with values like [util.format in Node][1] | ||
@@ -171,19 +170,4 @@ Example | ||
**Customize failure behaviour** | ||
To customize failure behaviuor, see `options.onFail`. | ||
In production envs you don't want to leak failures to the user | ||
```javascript | ||
// override onFail hook | ||
assert.onFail = function (message) { | ||
try { | ||
// capture stack trace | ||
throw new Error(message); | ||
} catch (e) { | ||
// use you favourite JavaScript error logging service | ||
console.log(e.stack); | ||
} | ||
}; | ||
``` | ||
### struct(props, [name]) | ||
@@ -230,10 +214,2 @@ | ||
#### update(instance, updates, [mut]) | ||
Returns an instance with updated props, without modifying the original. | ||
```javascript | ||
Point.update(p, {x: 3}); // => new Point({x: 3, y: 2}) | ||
``` | ||
### union(types, [name]) | ||
@@ -315,5 +291,5 @@ | ||
Returns an enums of an array of keys, useful when you don't mind to define | ||
custom values form the enums. | ||
custom values for the enums. | ||
- `keys` array or string of keys | ||
- `keys` array (or string) of keys | ||
- `name` optional string useful for debugging | ||
@@ -429,14 +405,2 @@ | ||
#### Useful methods | ||
All of these methods return an instance without modifying the original. | ||
```javascript | ||
Path.append(path, element, [mut]); | ||
Path.prepend(path, element, [mut]); | ||
Path.update(path, index, element, [mut]); | ||
Path.remove(path, index, [mut]); | ||
Path.move(path, from, to, [mut]); | ||
``` | ||
### func(Arguments, f, [Return], [name]) | ||
@@ -462,9 +426,42 @@ | ||
## Roadmap | ||
### options | ||
- explore auto generated UI from domain models written with tcomb | ||
#### function `options.onFail` | ||
In production envs you don't want to leak failures to the user | ||
```javascript | ||
// override onFail hook | ||
options.onFail = function (message) { | ||
try { | ||
// capture stack trace | ||
throw new Error(message); | ||
} catch (e) { | ||
// use you favourite JavaScript error logging service | ||
console.log(e.stack); | ||
} | ||
}; | ||
``` | ||
#### function `options.update` | ||
TODO: better docs | ||
Add to structs, tuples and lists a static method `update` that returns a new instance | ||
without modifying the original. | ||
Example | ||
```javascript | ||
// see http://facebook.github.io/react/docs/update.html | ||
options.update = React.addons.update; | ||
var p1 = new Point({x: 0, y: 0}); | ||
var p2 = Point.update(p1, {x: {$set: 1}}); // => Point({x: 1, y: 0}) | ||
``` | ||
## IDEAS | ||
- explore generating UI based on domain models written with tcomb | ||
- explore auto validation of UI involving domain models written with tcomb | ||
- explore using tcomb with React.js | ||
- 100% test coverage | ||
- api docs | ||
@@ -475,8 +472,2 @@ ## Contribution | ||
### v0.0.9 | ||
- grunt build system | ||
- splitted source files | ||
- 70% test coverage | ||
## License (MIT) | ||
@@ -505,1 +496,3 @@ | ||
SOFTWARE. | ||
[1]: http://nodejs.org/api/util.html#util_util_format_format |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
9
0
38837
491
490