Comparing version 0.3.1 to 0.4.0
@@ -107,9 +107,9 @@ /** | ||
*/ | ||
export declare function Tuple<A>(a: Runtype<A>, strict?: boolean): Runtype<[A]>; | ||
export declare function Tuple<A, B>(a: Runtype<A>, b: Runtype<B>, strict?: boolean): Runtype<[A, B]>; | ||
export declare function Tuple<A, B, C>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>, strict?: boolean): Runtype<[A, B, C]>; | ||
export declare function Tuple<A, B, C, D>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>, d: Runtype<D>, strict?: boolean): Runtype<[A, B, C, D]>; | ||
export declare function Tuple<A, B, C, D, E>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>, d: Runtype<D>, e: Runtype<E>, strict?: boolean): Runtype<[A, B, C, D, E]>; | ||
export declare function Tuple<A, B, C, D, E, F>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>, d: Runtype<D>, e: Runtype<E>, f: Runtype<F>, strict?: boolean): Runtype<[A, B, C, D, E, F]>; | ||
export declare function Tuple<A, B, C, D, E, F, G>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>, d: Runtype<D>, e: Runtype<E>, f: Runtype<F>, g: Runtype<G>, strict?: boolean): Runtype<[A, B, C, D, E, F, G]>; | ||
export declare function Tuple<A>(a: Runtype<A>): Runtype<[A]>; | ||
export declare function Tuple<A, B>(a: Runtype<A>, b: Runtype<B>): Runtype<[A, B]>; | ||
export declare function Tuple<A, B, C>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>): Runtype<[A, B, C]>; | ||
export declare function Tuple<A, B, C, D>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>, d: Runtype<D>): Runtype<[A, B, C, D]>; | ||
export declare function Tuple<A, B, C, D, E>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>, d: Runtype<D>, e: Runtype<E>): Runtype<[A, B, C, D, E]>; | ||
export declare function Tuple<A, B, C, D, E, F>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>, d: Runtype<D>, e: Runtype<E>, f: Runtype<F>): Runtype<[A, B, C, D, E, F]>; | ||
export declare function Tuple<A, B, C, D, E, F, G>(a: Runtype<A>, b: Runtype<B>, c: Runtype<C>, d: Runtype<D>, e: Runtype<E>, f: Runtype<F>, g: Runtype<G>): Runtype<[A, B, C, D, E, F, G]>; | ||
/** | ||
@@ -116,0 +116,0 @@ * Construct a record runtype from runtypes for its values. |
@@ -92,20 +92,9 @@ "use strict"; | ||
function Tuple() { | ||
var args = []; | ||
var runtypes = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
runtypes[_i] = arguments[_i]; | ||
} | ||
var lastArg = args[args.length - 1]; | ||
var strict; | ||
var runtypes; | ||
if (exports.Boolean.guard(lastArg)) { | ||
strict = lastArg; | ||
runtypes = args.slice(0, args.length - 1); | ||
} | ||
else { | ||
strict = false; | ||
runtypes = args; | ||
} | ||
return runtype(function (x) { | ||
var xs = arr(exports.Always).coerce(x); | ||
if (strict ? xs.length !== runtypes.length : xs.length < runtypes.length) | ||
if (xs.length < runtypes.length) | ||
throw new ValidationError("Expected array of " + runtypes.length + " but was " + xs.length); | ||
@@ -112,0 +101,0 @@ for (var i = 0; i < runtypes.length; i++) |
{ | ||
"name": "runtypes", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "Runtime validation for static types", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -171,3 +171,2 @@ | ||
a: Runtype<A>, | ||
strict?: boolean | ||
): Runtype<[A]> | ||
@@ -177,3 +176,2 @@ export function Tuple<A, B>( | ||
b: Runtype<B>, | ||
strict?: boolean | ||
): Runtype<[A, B]> | ||
@@ -184,3 +182,2 @@ export function Tuple<A, B, C>( | ||
c: Runtype<C>, | ||
strict?: boolean | ||
): Runtype<[A, B, C]> | ||
@@ -192,3 +189,2 @@ export function Tuple<A, B, C, D>( | ||
d: Runtype<D>, | ||
strict?: boolean | ||
): Runtype<[A, B, C, D]> | ||
@@ -201,3 +197,2 @@ export function Tuple<A, B, C, D, E>( | ||
e: Runtype<E>, | ||
strict?: boolean | ||
): Runtype<[A, B, C, D, E]> | ||
@@ -211,3 +206,2 @@ export function Tuple<A, B, C, D, E, F>( | ||
f: Runtype<F>, | ||
strict?: boolean | ||
): Runtype<[A, B, C, D, E, F]> | ||
@@ -222,18 +216,7 @@ export function Tuple<A, B, C, D, E, F, G>( | ||
g: Runtype<G>, | ||
strict?: boolean | ||
): Runtype<[A, B, C, D, E, F, G]> | ||
export function Tuple(...args: any[]) { | ||
const lastArg = args[args.length - 1] | ||
let strict: boolean | ||
let runtypes: Runtype<{}>[] | ||
if (Boolean.guard(lastArg)) { | ||
strict = lastArg | ||
runtypes = args.slice(0, args.length - 1) | ||
} else { | ||
strict = false | ||
runtypes = args | ||
} | ||
export function Tuple(...runtypes: Runtype<any>[]) { | ||
return runtype(x => { | ||
const xs = arr(Always).coerce(x) | ||
if (strict ? xs.length !== runtypes.length : xs.length < runtypes.length) | ||
if (xs.length < runtypes.length) | ||
throw new ValidationError(`Expected array of ${runtypes.length} but was ${xs.length}`) | ||
@@ -240,0 +223,0 @@ for (let i = 0; i < runtypes.length; i++) |
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
64041
1616