Comparing version 1.0.0 to 1.1.0
@@ -239,7 +239,9 @@ /** | ||
const type = new Type(name, function(x, ctx) { | ||
if(types.some(function(type) { return type.is(x); })) { | ||
ctx = (ctx || []).concat(name); | ||
if(types.some(function(type) { | ||
return validate(x, type, ctx, true) === null; | ||
})) { | ||
return null; | ||
} | ||
ctx = ctx || []; | ||
return [new Failure(x, type, ctx.concat(name))]; | ||
return [new Failure(x, type, ctx)]; | ||
}); | ||
@@ -246,0 +248,0 @@ return type; |
{ | ||
"name": "notmytype", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Type-check your function inputs with syntax like T(s, T.string, buf, Buffer, strings, T.list(T.string))", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/ludios/notmytype", |
@@ -147,3 +147,3 @@ /** | ||
it('should succeed if x is a list of T', function() { | ||
it('should succeed if x is a list of numbers', function() { | ||
assert.strictEqual( | ||
@@ -154,2 +154,9 @@ f.list(f.number).validate([1, 2]), | ||
}); | ||
it('should succeed if x is a list of Dates', function() { | ||
assert.strictEqual( | ||
f.list(Date).validate([new Date(), new Date()]), | ||
null | ||
); | ||
}); | ||
}); | ||
@@ -209,3 +216,3 @@ | ||
it('should succeed if x is an instance of T', function() { | ||
it('should succeed if x is a number', function() { | ||
assert.strictEqual( | ||
@@ -216,2 +223,9 @@ f.maybe(f.number).validate(1), | ||
}); | ||
it('should succeed if x is an instance of Date', function() { | ||
assert.strictEqual( | ||
f.maybe(Date).validate(new Date()), | ||
null | ||
); | ||
}); | ||
}); | ||
@@ -255,3 +269,3 @@ | ||
it('should succeed if x is an instance of T', function() { | ||
it('should succeed if x is a tuple of string and number', function() { | ||
assert.strictEqual( | ||
@@ -386,3 +400,3 @@ f.tuple([f.string, f.number]).validate(['s', 1]), | ||
it('should succeed if x is an instance of T', function() { | ||
it('should succeed if x is an instance of string or number', function() { | ||
assert.strictEqual( | ||
@@ -394,2 +408,8 @@ f.union([f.string, f.number]).validate(1), | ||
it('should succeed if x is an instance of string or Date', function() { | ||
assert.strictEqual( | ||
f.union([f.string, Date]).validate(new Date()), | ||
null | ||
); | ||
}); | ||
}); | ||
@@ -396,0 +416,0 @@ |
@@ -57,3 +57,4 @@ "use strong"; | ||
assert.strictEqual(T(3, T.number, [new Buffer("hi")], T.list(Buffer))); | ||
assert.strictEqual(T([new Buffer("hi"), new Date()], T.list(T.union([Buffer, Date])))); | ||
}); | ||
}); |
28898
804