tcomb
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "tcomb", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "JavaScript types and combinators", | ||
@@ -5,0 +5,0 @@ "main": "tcomb.js", |
@@ -15,3 +15,3 @@ # tcomb | ||
This library provides several type combinators and a built-in `assert` function you can use. When an assertion fails in the browser this function starts the debugger so you can inspect the stack and find what's wrong. Since after a type error many others are expected, the debugger starts only once. | ||
This library provides several type combinators and a built-in `assert` function you can use. When an assertion fails in the browser this function starts the debugger so you can inspect the stack and find what's wrong. The debugger starts only once after the first failed assert. | ||
@@ -119,7 +119,7 @@ ## Quick example | ||
1. `T` has signature `T(values, [mut])` where the arg `values` is the set of values occurred to have an instance of `T` (depends on the nature of `T`) and the optional boolean arg `mut` makes the instance mutable (default `false`) | ||
1. `T` has signature `T(values, [mut])` where `values` depends on the nature of `T` and the optional boolean arg `mut` makes the instance mutable (default `false`) | ||
2. `T` is idempotent: `new T(new T(values)) "equals" new T(values)` | ||
3. `T` owns a static function `T.is(x)` returning `true` if `x` is a instance of `T` | ||
**Note**: 2. implies that `T` can be used as the default JSON decoder | ||
**Note**: 2. implies that `T` can be used as a default JSON decoder | ||
@@ -130,3 +130,3 @@ ## Api | ||
Is used internally to define JavaScript native types: | ||
Used internally to define JavaScript native types: | ||
@@ -311,4 +311,4 @@ - Nil: `null` and `undefined` | ||
Args.is([1, 2]); // => true | ||
Args.is([1, 'a']); // => false, il secondo elemento non è un Num | ||
Args.is([1, 2, 3]); // => false, troppi elementi | ||
Args.is([1, 'a']); // => false, second element is not a Num | ||
Args.is([1, 2, 3]); // => false, too many elements | ||
@@ -329,8 +329,8 @@ update(instance, index, element, [mut]) | ||
// points of the first quadrant | ||
var Q1Point = subtype(Point, function (p) { | ||
// punti nel primo quadrante | ||
return p.x >= 0 && p.y >= 0; | ||
}); | ||
// uso del costruttore | ||
// constructor usage | ||
var p = new Q1Point({x: -1, y: -2}); // => fail! | ||
@@ -360,3 +360,3 @@ | ||
// uso del costruttore | ||
// costructor usage | ||
var path = new Path([ | ||
@@ -363,0 +363,0 @@ {x: 0, y: 0}, |
11
tcomb.js
@@ -17,5 +17,2 @@ (function (root, factory) { | ||
/* fa partire il debugger prima di lanciare un errore il debugger parte una | ||
volta sola perchè tipicamente dopo un fallimento ce ne possono essere | ||
molti altri e diventerebbe una noia */ | ||
var failed = false; | ||
@@ -31,3 +28,2 @@ | ||
/* se l'assert fallisce chiama fail(message) */ | ||
function assert(guard, message) { | ||
@@ -39,4 +35,2 @@ if (guard !== true) { | ||
/* rende immutabili le proprietà dirette di un oggetto o un array | ||
a meno che unless sia = true */ | ||
function freeze(obj_or_arr, unless) { | ||
@@ -49,5 +43,2 @@ if (unless !== true) { | ||
/* copia i campi di y in x. Se overwrite è falsy non è possibile | ||
sovrascrivere dei campi già presenti in x in modo da evitare | ||
fastidiosi bug */ | ||
function mixin(x, y, overwrite) { | ||
@@ -122,3 +113,2 @@ for (var k in y) { | ||
/* ignora l'argomento mut perchè i tipi primitivi di JavaScript sono sempre immutabili */ | ||
function Primitive(values) { | ||
@@ -277,3 +267,2 @@ assert(Primitive.is(values), 'bad ' + name); | ||
/* ignora l'argomento mut perchè gli enum sono stringhe JavaScript e quindi sempre immutabili */ | ||
function Enums(x) { | ||
@@ -280,0 +269,0 @@ assert(Enums.is(x), 'bad ' + (name || 'enum')); |
54554
655