Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

superstruct

Package Overview
Dependencies
Maintainers
1
Versions
90
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superstruct - npm Package Compare versions

Comparing version 0.15.2 to 0.15.3

779

lib/index.cjs.d.ts

@@ -33,2 +33,6 @@ /**

/**
* Convert a union of type to an intersection.
*/
type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
/**
* Assign properties from one type to another, overwriting existing.

@@ -44,6 +48,11 @@ */

/**
* Check if a type is an exact match.
* Check if a type is a match for another whilst treating overlapping
* unions as a match.
*/
type IsMatch<T, G> = T extends G ? (G extends T ? T : never) : never;
/**
* Check if a type is an exact match.
*/
type IsExactMatch<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? T : never;
/**
* Check if a type is a record type.

@@ -152,3 +161,3 @@ */

] extends [
IsMatch<T, boolean>
IsExactMatch<T, boolean>
] ? null : T : T extends bigint | symbol | undefined | null | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? null : T extends Array<infer E> ? T extends IsTuple<T> ? null : Struct<E> : T extends object ? T extends IsRecord<T> ? null : {

@@ -158,8 +167,18 @@ [K in keyof T]: Describe<T[K]>;

/**
* A schema for tuple structs.
* Shorthand type for matching any `Struct`.
*/
type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;
};
type AnyStruct = Struct<any, any>;
/**
* Infer a tuple of types from a tuple of `Struct`s.
*
* This is used to recursively retrieve the type from `union` `intersection` and
* `tuple` structs.
*/
type InferStructTuple<Tuple extends AnyStruct[], Length extends number = Tuple["length"]> = Length extends Length ? number extends Length ? Tuple : _InferTuple<Tuple, Length, [
]> : never;
type _InferTuple<Tuple extends AnyStruct[], Length extends number, Accumulated extends unknown[], Index extends number = Accumulated["length"]> = Index extends Length ? Accumulated : _InferTuple<Tuple, Length, [
...Accumulated,
Infer<Tuple[Index]>
]>;
/**
* `Struct` objects encapsulate the validation logic for a specific type of

@@ -331,2 +350,6 @@ * values. Once constructed, you use the `assert`, `is` or `validate` helpers to

/**
* Ensure that a string, array, map or set is not empty.
*/
declare function nonempty<T extends string | any[] | Map<any, any> | Set<any>, S extends any>(struct: Struct<T, S>): Struct<T, S>;
/**
* Ensure that a string matches a regular expression.

@@ -361,2 +384,6 @@ */

/**
* Ensure that a value is a bigint.
*/
declare function bigint(): Struct<bigint, null>;
/**
* Ensure that a value is a boolean.

@@ -401,189 +428,6 @@ */

*/
declare function intersection<A>(Structs: TupleSchema<[
A
]>): Struct<A, null>;
declare function intersection<A, B>(Structs: TupleSchema<[
declare function intersection<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<A & B, null>;
declare function intersection<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<A & B & C, null>;
declare function intersection<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<A & B & C & D, null>;
declare function intersection<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<A & B & C & D & E, null>;
declare function intersection<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<A & B & C & D & E & F, null>;
declare function intersection<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<A & B & C & D & E & F & G, null>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<A & B & C & D & E & F & G & H, null>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<A & B & C & D & E & F & G & H & I, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<A & B & C & D & E & F & G & H & I & J, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<A & B & C & D & E & F & G & H & I & J & K, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q, null>;
...B
]): Struct<Infer<A> & UnionToIntersection<InferStructTuple<B>[number]>, null>;
/**

@@ -654,359 +498,9 @@ * Ensure that a value is an exact value, using `===` for comparison.

*/
declare function tuple<A>(Structs: TupleSchema<[
A
]>): Struct<[
A
], null>;
declare function tuple<A, B>(Structs: TupleSchema<[
declare function tuple<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<[
A,
B
...B
]): Struct<[
Infer<A>,
...InferStructTuple<B>
], null>;
declare function tuple<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<[
A,
B,
C
], null>;
declare function tuple<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<[
A,
B,
C,
D
], null>;
declare function tuple<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<[
A,
B,
C,
D,
E
], null>;
declare function tuple<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<[
A,
B,
C,
D,
E,
F
], null>;
declare function tuple<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<[
A,
B,
C,
D,
E,
F,
G
], null>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
], null>;
/**

@@ -1022,189 +516,6 @@ * Ensure that a value has a set of known properties of specific types.

*/
declare function union<A>(Structs: TupleSchema<[
A
]>): Struct<A, null>;
declare function union<A, B>(Structs: TupleSchema<[
declare function union<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<A | B, null>;
declare function union<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<A | B | C, null>;
declare function union<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<A | B | C | D, null>;
declare function union<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<A | B | C | D | E, null>;
declare function union<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<A | B | C | D | E | F, null>;
declare function union<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<A | B | C | D | E | F | G, null>;
declare function union<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<A | B | C | D | E | F | G | H, null>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<A | B | C | D | E | F | G | H | I, null>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<A | B | C | D | E | F | G | H | I | J, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<A | B | C | D | E | F | G | H | I | J | K, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q, null>;
...B
]): Struct<Infer<A> | InferStructTuple<B>[number], null>;
/**

@@ -1277,2 +588,2 @@ * Ensure that any value passes validation, without widening its type to `any`.

declare function struct<T>(name: string, validator: Validator): Struct<T, null>;
export { Failure, StructError, Struct, assert, create, mask, is, validate, Context, Infer, Describe, Result, Coercer, Validator, Refiner, coerce, defaulted, trimmed, empty, max, min, pattern, size, refine, any, array, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, deprecated, dynamic, lazy, omit, partial, pick, struct };
export { Failure, StructError, Struct, assert, create, mask, is, validate, Context, Infer, Describe, Result, Coercer, Validator, Refiner, coerce, defaulted, trimmed, empty, max, min, nonempty, pattern, size, refine, any, array, bigint, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, deprecated, dynamic, lazy, omit, partial, pick, struct };

@@ -33,2 +33,6 @@ /**

/**
* Convert a union of type to an intersection.
*/
type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
/**
* Assign properties from one type to another, overwriting existing.

@@ -44,6 +48,11 @@ */

/**
* Check if a type is an exact match.
* Check if a type is a match for another whilst treating overlapping
* unions as a match.
*/
type IsMatch<T, G> = T extends G ? (G extends T ? T : never) : never;
/**
* Check if a type is an exact match.
*/
type IsExactMatch<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? T : never;
/**
* Check if a type is a record type.

@@ -152,3 +161,3 @@ */

] extends [
IsMatch<T, boolean>
IsExactMatch<T, boolean>
] ? null : T : T extends bigint | symbol | undefined | null | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? null : T extends Array<infer E> ? T extends IsTuple<T> ? null : Struct<E> : T extends object ? T extends IsRecord<T> ? null : {

@@ -158,8 +167,18 @@ [K in keyof T]: Describe<T[K]>;

/**
* A schema for tuple structs.
* Shorthand type for matching any `Struct`.
*/
type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;
};
type AnyStruct = Struct<any, any>;
/**
* Infer a tuple of types from a tuple of `Struct`s.
*
* This is used to recursively retrieve the type from `union` `intersection` and
* `tuple` structs.
*/
type InferStructTuple<Tuple extends AnyStruct[], Length extends number = Tuple["length"]> = Length extends Length ? number extends Length ? Tuple : _InferTuple<Tuple, Length, [
]> : never;
type _InferTuple<Tuple extends AnyStruct[], Length extends number, Accumulated extends unknown[], Index extends number = Accumulated["length"]> = Index extends Length ? Accumulated : _InferTuple<Tuple, Length, [
...Accumulated,
Infer<Tuple[Index]>
]>;
/**
* `Struct` objects encapsulate the validation logic for a specific type of

@@ -331,2 +350,6 @@ * values. Once constructed, you use the `assert`, `is` or `validate` helpers to

/**
* Ensure that a string, array, map or set is not empty.
*/
declare function nonempty<T extends string | any[] | Map<any, any> | Set<any>, S extends any>(struct: Struct<T, S>): Struct<T, S>;
/**
* Ensure that a string matches a regular expression.

@@ -361,2 +384,6 @@ */

/**
* Ensure that a value is a bigint.
*/
declare function bigint(): Struct<bigint, null>;
/**
* Ensure that a value is a boolean.

@@ -401,189 +428,6 @@ */

*/
declare function intersection<A>(Structs: TupleSchema<[
A
]>): Struct<A, null>;
declare function intersection<A, B>(Structs: TupleSchema<[
declare function intersection<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<A & B, null>;
declare function intersection<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<A & B & C, null>;
declare function intersection<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<A & B & C & D, null>;
declare function intersection<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<A & B & C & D & E, null>;
declare function intersection<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<A & B & C & D & E & F, null>;
declare function intersection<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<A & B & C & D & E & F & G, null>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<A & B & C & D & E & F & G & H, null>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<A & B & C & D & E & F & G & H & I, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<A & B & C & D & E & F & G & H & I & J, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<A & B & C & D & E & F & G & H & I & J & K, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q, null>;
...B
]): Struct<Infer<A> & UnionToIntersection<InferStructTuple<B>[number]>, null>;
/**

@@ -654,359 +498,9 @@ * Ensure that a value is an exact value, using `===` for comparison.

*/
declare function tuple<A>(Structs: TupleSchema<[
A
]>): Struct<[
A
], null>;
declare function tuple<A, B>(Structs: TupleSchema<[
declare function tuple<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<[
A,
B
...B
]): Struct<[
Infer<A>,
...InferStructTuple<B>
], null>;
declare function tuple<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<[
A,
B,
C
], null>;
declare function tuple<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<[
A,
B,
C,
D
], null>;
declare function tuple<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<[
A,
B,
C,
D,
E
], null>;
declare function tuple<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<[
A,
B,
C,
D,
E,
F
], null>;
declare function tuple<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<[
A,
B,
C,
D,
E,
F,
G
], null>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
], null>;
/**

@@ -1022,189 +516,6 @@ * Ensure that a value has a set of known properties of specific types.

*/
declare function union<A>(Structs: TupleSchema<[
A
]>): Struct<A, null>;
declare function union<A, B>(Structs: TupleSchema<[
declare function union<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<A | B, null>;
declare function union<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<A | B | C, null>;
declare function union<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<A | B | C | D, null>;
declare function union<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<A | B | C | D | E, null>;
declare function union<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<A | B | C | D | E | F, null>;
declare function union<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<A | B | C | D | E | F | G, null>;
declare function union<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<A | B | C | D | E | F | G | H, null>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<A | B | C | D | E | F | G | H | I, null>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<A | B | C | D | E | F | G | H | I | J, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<A | B | C | D | E | F | G | H | I | J | K, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q, null>;
...B
]): Struct<Infer<A> | InferStructTuple<B>[number], null>;
/**

@@ -1277,2 +588,2 @@ * Ensure that any value passes validation, without widening its type to `any`.

declare function struct<T>(name: string, validator: Validator): Struct<T, null>;
export { Failure, StructError, Struct, assert, create, mask, is, validate, Context, Infer, Describe, Result, Coercer, Validator, Refiner, coerce, defaulted, trimmed, empty, max, min, pattern, size, refine, any, array, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, deprecated, dynamic, lazy, omit, partial, pick, struct };
export { Failure, StructError, Struct, assert, create, mask, is, validate, Context, Infer, Describe, Result, Coercer, Validator, Refiner, coerce, defaulted, trimmed, empty, max, min, nonempty, pattern, size, refine, any, array, bigint, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, deprecated, dynamic, lazy, omit, partial, pick, struct };

77

lib/index.es.js

@@ -25,2 +25,9 @@ /**

super(msg);
this.value = void 0;
this.key = void 0;
this.type = void 0;
this.refinement = void 0;
this.path = void 0;
this.branch = void 0;
this.failures = void 0;
Object.assign(this, rest);

@@ -221,2 +228,9 @@ this.name = this.constructor.name;

constructor(props) {
this.TYPE = void 0;
this.type = void 0;
this.schema = void 0;
this.coercer = void 0;
this.validator = void 0;
this.refiner = void 0;
this.entries = void 0;
const {

@@ -579,2 +593,11 @@ type,

/**
* Ensure that a value is a bigint.
*/
function bigint() {
return define('bigint', value => {
return typeof value === 'bigint';
});
}
/**
* Ensure that a value is a boolean.

@@ -645,2 +668,6 @@ */

}
/**
* Ensure that a value matches all of a set of types.
*/
function intersection(Structs) {

@@ -849,3 +876,8 @@ return new Struct({

}
function tuple(Elements) {
/**
* Ensure that a value is a tuple of a specific length, and that each of its
* elements is of a specific type.
*/
function tuple(Structs) {
const Never = never();

@@ -858,6 +890,6 @@ return new Struct({

if (Array.isArray(value)) {
const length = Math.max(Elements.length, value.length);
const length = Math.max(Structs.length, value.length);
for (let i = 0; i < length; i++) {
yield [i, value[i], Elements[i] || Never];
yield [i, value[i], Structs[i] || Never];
}

@@ -900,2 +932,6 @@ }

}
/**
* Ensure that a value matches one of a set of types.
*/
function union(Structs) {

@@ -1017,17 +1053,15 @@ const description = Structs.map(s => s.type).join(' | ');

function empty(struct) {
const expected = "Expected an empty " + struct.type;
return refine(struct, 'empty', value => {
if (value instanceof Map || value instanceof Set) {
const {
size
} = value;
return size === 0 || expected + " but received one with a size of `" + size + "`";
} else {
const {
length
} = value;
return length === 0 || expected + " but received one with a length of `" + length + "`";
}
const size = getSize(value);
return size === 0 || "Expected an empty " + struct.type + " but received one with a size of `" + size + "`";
});
}
function getSize(value) {
if (value instanceof Map || value instanceof Set) {
return value.size;
} else {
return value.length;
}
}
/**

@@ -1037,2 +1071,3 @@ * Ensure that a number or date is below a threshold.

function max(struct, threshold, options = {}) {

@@ -1059,2 +1094,12 @@ const {

/**
* Ensure that a string, array, map or set is not empty.
*/
function nonempty(struct) {
return refine(struct, 'nonempty', value => {
const size = getSize(value);
return size > 0 || "Expected a nonempty " + struct.type + " but received an empty one";
});
}
/**
* Ensure that a string matches a regular expression.

@@ -1117,3 +1162,3 @@ */

export { Struct, StructError, any, array, assert, assign, boolean, coerce, create, date, defaulted, define, deprecated, dynamic, empty, enums, func, instance, integer, intersection, is, lazy, literal, map, mask, max, min, never, nullable, number, object, omit, optional, partial, pattern, pick, record, refine, regexp, set, size, string, struct, trimmed, tuple, type, union, unknown, validate };
export { Struct, StructError, any, array, assert, assign, bigint, boolean, coerce, create, date, defaulted, define, deprecated, dynamic, empty, enums, func, instance, integer, intersection, is, lazy, literal, map, mask, max, min, never, nonempty, nullable, number, object, omit, optional, partial, pattern, pick, record, refine, regexp, set, size, string, struct, trimmed, tuple, type, union, unknown, validate };
//# sourceMappingURL=index.es.js.map

@@ -19,2 +19,6 @@ import { Struct, Refiner } from '../struct';

/**
* Ensure that a string, array, map or set is not empty.
*/
export declare function nonempty<T extends string | any[] | Map<any, any> | Set<any>, S extends any>(struct: Struct<T, S>): Struct<T, S>;
/**
* Ensure that a string matches a regular expression.

@@ -21,0 +25,0 @@ */

import { Infer, Struct } from '../struct';
import { TupleSchema, ObjectSchema, ObjectType } from '../utils';
import { ObjectSchema, ObjectType, AnyStruct, InferStructTuple, UnionToIntersection } from '../utils';
/**

@@ -17,2 +17,6 @@ * Ensure that any value passes validation.

/**
* Ensure that a value is a bigint.
*/
export declare function bigint(): Struct<bigint, null>;
/**
* Ensure that a value is a boolean.

@@ -57,19 +61,3 @@ */

*/
export declare function intersection<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
export declare function intersection<A, B>(Structs: TupleSchema<[A, B]>): Struct<A & B, null>;
export declare function intersection<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A & B & C, null>;
export declare function intersection<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A & B & C & D, null>;
export declare function intersection<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A & B & C & D & E, null>;
export declare function intersection<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A & B & C & D & E & F, null>;
export declare function intersection<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A & B & C & D & E & F & G, null>;
export declare function intersection<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A & B & C & D & E & F & G & H, null>;
export declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A & B & C & D & E & F & G & H & I, null>;
export declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A & B & C & D & E & F & G & H & I & J, null>;
export declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A & B & C & D & E & F & G & H & I & J & K, null>;
export declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L, null>;
export declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M, null>;
export declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N, null>;
export declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O, null>;
export declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P, null>;
export declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q, null>;
export declare function intersection<A extends AnyStruct, B extends AnyStruct[]>(Structs: [A, ...B]): Struct<Infer<A> & UnionToIntersection<InferStructTuple<B>[number]>, null>;
/**

@@ -140,19 +128,3 @@ * Ensure that a value is an exact value, using `===` for comparison.

*/
export declare function tuple<A>(Structs: TupleSchema<[A]>): Struct<[A], null>;
export declare function tuple<A, B>(Structs: TupleSchema<[A, B]>): Struct<[A, B], null>;
export declare function tuple<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<[A, B, C], null>;
export declare function tuple<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<[A, B, C, D], null>;
export declare function tuple<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<[A, B, C, D, E], null>;
export declare function tuple<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<[A, B, C, D, E, F], null>;
export declare function tuple<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<[A, B, C, D, E, F, G], null>;
export declare function tuple<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<[A, B, C, D, E, F, G, H], null>;
export declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<[A, B, C, D, E, F, G, H, I], null>;
export declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<[A, B, C, D, E, F, G, H, I, J], null>;
export declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<[A, B, C, D, E, F, G, H, I, J, K], null>;
export declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L], null>;
export declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M], null>;
export declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N], null>;
export declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O], null>;
export declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P], null>;
export declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q], null>;
export declare function tuple<A extends AnyStruct, B extends AnyStruct[]>(Structs: [A, ...B]): Struct<[Infer<A>, ...InferStructTuple<B>], null>;
/**

@@ -168,19 +140,3 @@ * Ensure that a value has a set of known properties of specific types.

*/
export declare function union<A>(Structs: TupleSchema<[A]>): Struct<A, null>;
export declare function union<A, B>(Structs: TupleSchema<[A, B]>): Struct<A | B, null>;
export declare function union<A, B, C>(Structs: TupleSchema<[A, B, C]>): Struct<A | B | C, null>;
export declare function union<A, B, C, D>(Structs: TupleSchema<[A, B, C, D]>): Struct<A | B | C | D, null>;
export declare function union<A, B, C, D, E>(Structs: TupleSchema<[A, B, C, D, E]>): Struct<A | B | C | D | E, null>;
export declare function union<A, B, C, D, E, F>(Structs: TupleSchema<[A, B, C, D, E, F]>): Struct<A | B | C | D | E | F, null>;
export declare function union<A, B, C, D, E, F, G>(Structs: TupleSchema<[A, B, C, D, E, F, G]>): Struct<A | B | C | D | E | F | G, null>;
export declare function union<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[A, B, C, D, E, F, G, H]>): Struct<A | B | C | D | E | F | G | H, null>;
export declare function union<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I]>): Struct<A | B | C | D | E | F | G | H | I, null>;
export declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J]>): Struct<A | B | C | D | E | F | G | H | I | J, null>;
export declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K]>): Struct<A | B | C | D | E | F | G | H | I | J | K, null>;
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L, null>;
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M, null>;
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N, null>;
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O, null>;
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P, null>;
export declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q, null>;
export declare function union<A extends AnyStruct, B extends AnyStruct[]>(Structs: [A, ...B]): Struct<Infer<A> | InferStructTuple<B>[number], null>;
/**

@@ -187,0 +143,0 @@ * Ensure that any value passes validation, without widening its type to `any`.

@@ -41,2 +41,6 @@ import { Struct, Infer, Result, Context, Describe } from './struct';

/**
* Convert a union of type to an intersection.
*/
export declare type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
/**
* Assign properties from one type to another, overwriting existing.

@@ -52,6 +56,11 @@ */

/**
* Check if a type is an exact match.
* Check if a type is a match for another whilst treating overlapping
* unions as a match.
*/
export declare type IsMatch<T, G> = T extends G ? (G extends T ? T : never) : never;
/**
* Check if a type is an exact match.
*/
export declare type IsExactMatch<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? T : never;
/**
* Check if a type is a record type.

@@ -110,3 +119,3 @@ */

*/
export declare type StructSchema<T> = [T] extends [string | undefined] ? [T] extends [IsMatch<T, string | undefined>] ? null : [T] extends [IsUnion<T>] ? EnumSchema<T> : T : [T] extends [number | undefined] ? [T] extends [IsMatch<T, number | undefined>] ? null : [T] extends [IsUnion<T>] ? EnumSchema<T> : T : [T] extends [boolean] ? [T] extends [IsMatch<T, boolean>] ? null : T : T extends bigint | symbol | undefined | null | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? null : T extends Array<infer E> ? T extends IsTuple<T> ? null : Struct<E> : T extends object ? T extends IsRecord<T> ? null : {
export declare type StructSchema<T> = [T] extends [string | undefined] ? [T] extends [IsMatch<T, string | undefined>] ? null : [T] extends [IsUnion<T>] ? EnumSchema<T> : T : [T] extends [number | undefined] ? [T] extends [IsMatch<T, number | undefined>] ? null : [T] extends [IsUnion<T>] ? EnumSchema<T> : T : [T] extends [boolean] ? [T] extends [IsExactMatch<T, boolean>] ? null : T : T extends bigint | symbol | undefined | null | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? null : T extends Array<infer E> ? T extends IsTuple<T> ? null : Struct<E> : T extends object ? T extends IsRecord<T> ? null : {
[K in keyof T]: Describe<T[K]>;

@@ -120,2 +129,15 @@ } : null;

};
/**
* Shorthand type for matching any `Struct`.
*/
export declare type AnyStruct = Struct<any, any>;
/**
* Infer a tuple of types from a tuple of `Struct`s.
*
* This is used to recursively retrieve the type from `union` `intersection` and
* `tuple` structs.
*/
export declare type InferStructTuple<Tuple extends AnyStruct[], Length extends number = Tuple['length']> = Length extends Length ? number extends Length ? Tuple : _InferTuple<Tuple, Length, []> : never;
declare type _InferTuple<Tuple extends AnyStruct[], Length extends number, Accumulated extends unknown[], Index extends number = Accumulated['length']> = Index extends Length ? Accumulated : _InferTuple<Tuple, Length, [...Accumulated, Infer<Tuple[Index]>]>;
export {};
//# sourceMappingURL=utils.d.ts.map

@@ -5,3 +5,3 @@ {

"description": "A simple and composable way to validate data in JavaScript (and TypeScript).",
"version": "0.15.2",
"version": "0.15.3",
"license": "MIT",

@@ -22,2 +22,5 @@ "repository": "git://github.com/ianstormtaylor/superstruct.git",

],
"publishConfig": {
"registry": "https://registry.npmjs.org"
},
"devDependencies": {

@@ -31,6 +34,6 @@ "@babel/cli": "^7.6.3",

"@types/lodash": "^4.14.144",
"@types/mocha": "^8.0.3",
"@types/node": "^15.0.1",
"@typescript-eslint/eslint-plugin": "^4.8.2",
"@typescript-eslint/parser": "^4.8.2",
"@types/mocha": "^9.0.0",
"@types/node": "^16.7.1",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"babel-eslint": "^10.0.3",

@@ -40,3 +43,3 @@ "eslint": "^7.14.0",

"eslint-plugin-import": "^2.22.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-prettier": "^4.0.0",
"is-email": "^1.0.0",

@@ -46,3 +49,3 @@ "is-url": "^1.2.4",

"lodash": "^4.17.15",
"mocha": "^8.0.1",
"mocha": "^9.1.1",
"np": "^7.0.0",

@@ -110,3 +113,4 @@ "prettier": "^2.0.5",

"validator"
]
],
"dependencies": {}
}

@@ -33,2 +33,6 @@ /**

/**
* Convert a union of type to an intersection.
*/
type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
/**
* Assign properties from one type to another, overwriting existing.

@@ -44,6 +48,11 @@ */

/**
* Check if a type is an exact match.
* Check if a type is a match for another whilst treating overlapping
* unions as a match.
*/
type IsMatch<T, G> = T extends G ? (G extends T ? T : never) : never;
/**
* Check if a type is an exact match.
*/
type IsExactMatch<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? T : never;
/**
* Check if a type is a record type.

@@ -152,3 +161,3 @@ */

] extends [
IsMatch<T, boolean>
IsExactMatch<T, boolean>
] ? null : T : T extends bigint | symbol | undefined | null | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? null : T extends Array<infer E> ? T extends IsTuple<T> ? null : Struct<E> : T extends object ? T extends IsRecord<T> ? null : {

@@ -158,8 +167,18 @@ [K in keyof T]: Describe<T[K]>;

/**
* A schema for tuple structs.
* Shorthand type for matching any `Struct`.
*/
type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;
};
type AnyStruct = Struct<any, any>;
/**
* Infer a tuple of types from a tuple of `Struct`s.
*
* This is used to recursively retrieve the type from `union` `intersection` and
* `tuple` structs.
*/
type InferStructTuple<Tuple extends AnyStruct[], Length extends number = Tuple["length"]> = Length extends Length ? number extends Length ? Tuple : _InferTuple<Tuple, Length, [
]> : never;
type _InferTuple<Tuple extends AnyStruct[], Length extends number, Accumulated extends unknown[], Index extends number = Accumulated["length"]> = Index extends Length ? Accumulated : _InferTuple<Tuple, Length, [
...Accumulated,
Infer<Tuple[Index]>
]>;
/**
* `Struct` objects encapsulate the validation logic for a specific type of

@@ -331,2 +350,6 @@ * values. Once constructed, you use the `assert`, `is` or `validate` helpers to

/**
* Ensure that a string, array, map or set is not empty.
*/
declare function nonempty<T extends string | any[] | Map<any, any> | Set<any>, S extends any>(struct: Struct<T, S>): Struct<T, S>;
/**
* Ensure that a string matches a regular expression.

@@ -361,2 +384,6 @@ */

/**
* Ensure that a value is a bigint.
*/
declare function bigint(): Struct<bigint, null>;
/**
* Ensure that a value is a boolean.

@@ -401,189 +428,6 @@ */

*/
declare function intersection<A>(Structs: TupleSchema<[
A
]>): Struct<A, null>;
declare function intersection<A, B>(Structs: TupleSchema<[
declare function intersection<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<A & B, null>;
declare function intersection<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<A & B & C, null>;
declare function intersection<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<A & B & C & D, null>;
declare function intersection<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<A & B & C & D & E, null>;
declare function intersection<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<A & B & C & D & E & F, null>;
declare function intersection<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<A & B & C & D & E & F & G, null>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<A & B & C & D & E & F & G & H, null>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<A & B & C & D & E & F & G & H & I, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<A & B & C & D & E & F & G & H & I & J, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<A & B & C & D & E & F & G & H & I & J & K, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q, null>;
...B
]): Struct<Infer<A> & UnionToIntersection<InferStructTuple<B>[number]>, null>;
/**

@@ -654,359 +498,9 @@ * Ensure that a value is an exact value, using `===` for comparison.

*/
declare function tuple<A>(Structs: TupleSchema<[
A
]>): Struct<[
A
], null>;
declare function tuple<A, B>(Structs: TupleSchema<[
declare function tuple<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<[
A,
B
...B
]): Struct<[
Infer<A>,
...InferStructTuple<B>
], null>;
declare function tuple<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<[
A,
B,
C
], null>;
declare function tuple<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<[
A,
B,
C,
D
], null>;
declare function tuple<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<[
A,
B,
C,
D,
E
], null>;
declare function tuple<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<[
A,
B,
C,
D,
E,
F
], null>;
declare function tuple<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<[
A,
B,
C,
D,
E,
F,
G
], null>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
], null>;
/**

@@ -1022,189 +516,6 @@ * Ensure that a value has a set of known properties of specific types.

*/
declare function union<A>(Structs: TupleSchema<[
A
]>): Struct<A, null>;
declare function union<A, B>(Structs: TupleSchema<[
declare function union<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<A | B, null>;
declare function union<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<A | B | C, null>;
declare function union<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<A | B | C | D, null>;
declare function union<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<A | B | C | D | E, null>;
declare function union<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<A | B | C | D | E | F, null>;
declare function union<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<A | B | C | D | E | F | G, null>;
declare function union<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<A | B | C | D | E | F | G | H, null>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<A | B | C | D | E | F | G | H | I, null>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<A | B | C | D | E | F | G | H | I | J, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<A | B | C | D | E | F | G | H | I | J | K, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q, null>;
...B
]): Struct<Infer<A> | InferStructTuple<B>[number], null>;
/**

@@ -1277,2 +588,2 @@ * Ensure that any value passes validation, without widening its type to `any`.

declare function struct<T>(name: string, validator: Validator): Struct<T, null>;
export { Failure, StructError, Struct, assert, create, mask, is, validate, Context, Infer, Describe, Result, Coercer, Validator, Refiner, coerce, defaulted, trimmed, empty, max, min, pattern, size, refine, any, array, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, deprecated, dynamic, lazy, omit, partial, pick, struct };
export { Failure, StructError, Struct, assert, create, mask, is, validate, Context, Infer, Describe, Result, Coercer, Validator, Refiner, coerce, defaulted, trimmed, empty, max, min, nonempty, pattern, size, refine, any, array, bigint, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, deprecated, dynamic, lazy, omit, partial, pick, struct };

@@ -5,3 +5,3 @@ (function (global, factory) {

(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Superstruct = {}));
}(this, (function (exports) { 'use strict';
})(this, (function (exports) { 'use strict';

@@ -32,2 +32,9 @@ /**

super(msg);
this.value = void 0;
this.key = void 0;
this.type = void 0;
this.refinement = void 0;
this.path = void 0;
this.branch = void 0;
this.failures = void 0;
Object.assign(this, rest);

@@ -228,2 +235,9 @@ this.name = this.constructor.name;

constructor(props) {
this.TYPE = void 0;
this.type = void 0;
this.schema = void 0;
this.coercer = void 0;
this.validator = void 0;
this.refiner = void 0;
this.entries = void 0;
const {

@@ -586,2 +600,11 @@ type,

/**
* Ensure that a value is a bigint.
*/
function bigint() {
return define('bigint', value => {
return typeof value === 'bigint';
});
}
/**
* Ensure that a value is a boolean.

@@ -652,2 +675,6 @@ */

}
/**
* Ensure that a value matches all of a set of types.
*/
function intersection(Structs) {

@@ -856,3 +883,8 @@ return new Struct({

}
function tuple(Elements) {
/**
* Ensure that a value is a tuple of a specific length, and that each of its
* elements is of a specific type.
*/
function tuple(Structs) {
const Never = never();

@@ -865,6 +897,6 @@ return new Struct({

if (Array.isArray(value)) {
const length = Math.max(Elements.length, value.length);
const length = Math.max(Structs.length, value.length);
for (let i = 0; i < length; i++) {
yield [i, value[i], Elements[i] || Never];
yield [i, value[i], Structs[i] || Never];
}

@@ -907,2 +939,6 @@ }

}
/**
* Ensure that a value matches one of a set of types.
*/
function union(Structs) {

@@ -1024,17 +1060,15 @@ const description = Structs.map(s => s.type).join(' | ');

function empty(struct) {
const expected = "Expected an empty " + struct.type;
return refine(struct, 'empty', value => {
if (value instanceof Map || value instanceof Set) {
const {
size
} = value;
return size === 0 || expected + " but received one with a size of `" + size + "`";
} else {
const {
length
} = value;
return length === 0 || expected + " but received one with a length of `" + length + "`";
}
const size = getSize(value);
return size === 0 || "Expected an empty " + struct.type + " but received one with a size of `" + size + "`";
});
}
function getSize(value) {
if (value instanceof Map || value instanceof Set) {
return value.size;
} else {
return value.length;
}
}
/**

@@ -1044,2 +1078,3 @@ * Ensure that a number or date is below a threshold.

function max(struct, threshold, options = {}) {

@@ -1066,2 +1101,12 @@ const {

/**
* Ensure that a string, array, map or set is not empty.
*/
function nonempty(struct) {
return refine(struct, 'nonempty', value => {
const size = getSize(value);
return size > 0 || "Expected a nonempty " + struct.type + " but received an empty one";
});
}
/**
* Ensure that a string matches a regular expression.

@@ -1130,2 +1175,3 @@ */

exports.assign = assign;
exports.bigint = bigint;
exports.boolean = boolean;

@@ -1153,2 +1199,3 @@ exports.coerce = coerce;

exports.never = never;
exports.nonempty = nonempty;
exports.nullable = nullable;

@@ -1178,2 +1225,2 @@ exports.number = number;

})));
}));

@@ -33,2 +33,6 @@ /**

/**
* Convert a union of type to an intersection.
*/
type UnionToIntersection<U> = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never;
/**
* Assign properties from one type to another, overwriting existing.

@@ -44,6 +48,11 @@ */

/**
* Check if a type is an exact match.
* Check if a type is a match for another whilst treating overlapping
* unions as a match.
*/
type IsMatch<T, G> = T extends G ? (G extends T ? T : never) : never;
/**
* Check if a type is an exact match.
*/
type IsExactMatch<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? T : never;
/**
* Check if a type is a record type.

@@ -152,3 +161,3 @@ */

] extends [
IsMatch<T, boolean>
IsExactMatch<T, boolean>
] ? null : T : T extends bigint | symbol | undefined | null | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any> | Promise<any> ? null : T extends Array<infer E> ? T extends IsTuple<T> ? null : Struct<E> : T extends object ? T extends IsRecord<T> ? null : {

@@ -158,8 +167,18 @@ [K in keyof T]: Describe<T[K]>;

/**
* A schema for tuple structs.
* Shorthand type for matching any `Struct`.
*/
type TupleSchema<T> = {
[K in keyof T]: Struct<T[K]>;
};
type AnyStruct = Struct<any, any>;
/**
* Infer a tuple of types from a tuple of `Struct`s.
*
* This is used to recursively retrieve the type from `union` `intersection` and
* `tuple` structs.
*/
type InferStructTuple<Tuple extends AnyStruct[], Length extends number = Tuple["length"]> = Length extends Length ? number extends Length ? Tuple : _InferTuple<Tuple, Length, [
]> : never;
type _InferTuple<Tuple extends AnyStruct[], Length extends number, Accumulated extends unknown[], Index extends number = Accumulated["length"]> = Index extends Length ? Accumulated : _InferTuple<Tuple, Length, [
...Accumulated,
Infer<Tuple[Index]>
]>;
/**
* `Struct` objects encapsulate the validation logic for a specific type of

@@ -331,2 +350,6 @@ * values. Once constructed, you use the `assert`, `is` or `validate` helpers to

/**
* Ensure that a string, array, map or set is not empty.
*/
declare function nonempty<T extends string | any[] | Map<any, any> | Set<any>, S extends any>(struct: Struct<T, S>): Struct<T, S>;
/**
* Ensure that a string matches a regular expression.

@@ -361,2 +384,6 @@ */

/**
* Ensure that a value is a bigint.
*/
declare function bigint(): Struct<bigint, null>;
/**
* Ensure that a value is a boolean.

@@ -401,189 +428,6 @@ */

*/
declare function intersection<A>(Structs: TupleSchema<[
A
]>): Struct<A, null>;
declare function intersection<A, B>(Structs: TupleSchema<[
declare function intersection<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<A & B, null>;
declare function intersection<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<A & B & C, null>;
declare function intersection<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<A & B & C & D, null>;
declare function intersection<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<A & B & C & D & E, null>;
declare function intersection<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<A & B & C & D & E & F, null>;
declare function intersection<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<A & B & C & D & E & F & G, null>;
declare function intersection<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<A & B & C & D & E & F & G & H, null>;
declare function intersection<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<A & B & C & D & E & F & G & H & I, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<A & B & C & D & E & F & G & H & I & J, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<A & B & C & D & E & F & G & H & I & J & K, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P, null>;
declare function intersection<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<A & B & C & D & E & F & G & H & I & J & K & L & M & N & O & P & Q, null>;
...B
]): Struct<Infer<A> & UnionToIntersection<InferStructTuple<B>[number]>, null>;
/**

@@ -654,359 +498,9 @@ * Ensure that a value is an exact value, using `===` for comparison.

*/
declare function tuple<A>(Structs: TupleSchema<[
A
]>): Struct<[
A
], null>;
declare function tuple<A, B>(Structs: TupleSchema<[
declare function tuple<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<[
A,
B
...B
]): Struct<[
Infer<A>,
...InferStructTuple<B>
], null>;
declare function tuple<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<[
A,
B,
C
], null>;
declare function tuple<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<[
A,
B,
C,
D
], null>;
declare function tuple<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<[
A,
B,
C,
D,
E
], null>;
declare function tuple<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<[
A,
B,
C,
D,
E,
F
], null>;
declare function tuple<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<[
A,
B,
C,
D,
E,
F,
G
], null>;
declare function tuple<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
], null>;
declare function tuple<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
], null>;
/**

@@ -1022,189 +516,6 @@ * Ensure that a value has a set of known properties of specific types.

*/
declare function union<A>(Structs: TupleSchema<[
A
]>): Struct<A, null>;
declare function union<A, B>(Structs: TupleSchema<[
declare function union<A extends AnyStruct, B extends AnyStruct[]>(Structs: [
A,
B
]>): Struct<A | B, null>;
declare function union<A, B, C>(Structs: TupleSchema<[
A,
B,
C
]>): Struct<A | B | C, null>;
declare function union<A, B, C, D>(Structs: TupleSchema<[
A,
B,
C,
D
]>): Struct<A | B | C | D, null>;
declare function union<A, B, C, D, E>(Structs: TupleSchema<[
A,
B,
C,
D,
E
]>): Struct<A | B | C | D | E, null>;
declare function union<A, B, C, D, E, F>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F
]>): Struct<A | B | C | D | E | F, null>;
declare function union<A, B, C, D, E, F, G>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G
]>): Struct<A | B | C | D | E | F | G, null>;
declare function union<A, B, C, D, E, F, G, H>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H
]>): Struct<A | B | C | D | E | F | G | H, null>;
declare function union<A, B, C, D, E, F, G, H, I>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I
]>): Struct<A | B | C | D | E | F | G | H | I, null>;
declare function union<A, B, C, D, E, F, G, H, I, J>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J
]>): Struct<A | B | C | D | E | F | G | H | I | J, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K
]>): Struct<A | B | C | D | E | F | G | H | I | J | K, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P, null>;
declare function union<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q>(Structs: TupleSchema<[
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q
]>): Struct<A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q, null>;
...B
]): Struct<Infer<A> | InferStructTuple<B>[number], null>;
/**

@@ -1277,2 +588,2 @@ * Ensure that any value passes validation, without widening its type to `any`.

declare function struct<T>(name: string, validator: Validator): Struct<T, null>;
export { Failure, StructError, Struct, assert, create, mask, is, validate, Context, Infer, Describe, Result, Coercer, Validator, Refiner, coerce, defaulted, trimmed, empty, max, min, pattern, size, refine, any, array, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, deprecated, dynamic, lazy, omit, partial, pick, struct };
export { Failure, StructError, Struct, assert, create, mask, is, validate, Context, Infer, Describe, Result, Coercer, Validator, Refiner, coerce, defaulted, trimmed, empty, max, min, nonempty, pattern, size, refine, any, array, bigint, boolean, date, enums, func, instance, integer, intersection, literal, map, never, nullable, number, object, optional, record, regexp, set, string, tuple, type, union, unknown, assign, define, deprecated, dynamic, lazy, omit, partial, pick, struct };

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

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Superstruct={})}(this,(function(e){"use strict";class t extends TypeError{constructor(e,t){let n;const{message:r,...o}=e,{path:i}=e;super(0===i.length?r:"At path: "+i.join(".")+" -- "+r),Object.assign(this,o),this.name=this.constructor.name,this.failures=()=>{var r;return null!=(r=n)?r:n=[e,...t()]}}}function n(e){return"object"==typeof e&&null!=e}function r(e){if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function o(e){return"string"==typeof e?JSON.stringify(e):""+e}function i(e,t,n,r){if(!0===e)return;!1===e?e={}:"string"==typeof e&&(e={message:e});const{path:i,branch:c}=t,{type:a}=n,{refinement:s,message:u="Expected a value of type `"+a+"`"+(s?" with refinement `"+s+"`":"")+", but received: `"+o(r)+"`"}=e;return{value:r,type:a,refinement:s,key:i[i.length-1],path:i,branch:c,...e,message:u}}function*c(e,t,r,o){var c;n(c=e)&&"function"==typeof c[Symbol.iterator]||(e=[e]);for(const n of e){const e=i(n,t,r,o);e&&(yield e)}}function*a(e,t,r={}){const{path:o=[],branch:i=[e],coerce:c=!1,mask:s=!1}=r,u={path:o,branch:i};if(c&&(e=t.coercer(e,u),s&&"type"!==t.type&&n(t.schema)&&n(e)&&!Array.isArray(e)))for(const n in e)void 0===t.schema[n]&&delete e[n];let f=!0;for(const n of t.validator(e,u))f=!1,yield[n,void 0];for(let[r,l,d]of t.entries(e,u)){const t=a(l,d,{path:void 0===r?o:[...o,r],branch:void 0===r?i:[...i,l],coerce:c,mask:s});for(const o of t)o[0]?(f=!1,yield[o[0],void 0]):c&&(l=o[1],void 0===r?e=l:e instanceof Map?e.set(r,l):e instanceof Set?e.add(l):n(e)&&(e[r]=l))}if(f)for(const n of t.refiner(e,u))f=!1,yield[n,void 0];f&&(yield[void 0,e])}class s{constructor(e){const{type:t,schema:n,validator:r,refiner:o,coercer:i=(e=>e),entries:a=function*(){}}=e;this.type=t,this.schema=n,this.entries=a,this.coercer=i,this.validator=r?(e,t)=>c(r(e,t),t,this,e):()=>[],this.refiner=o?(e,t)=>c(o(e,t),t,this,e):()=>[]}assert(e){return u(e,this)}create(e){return f(e,this)}is(e){return d(e,this)}mask(e){return l(e,this)}validate(e,t={}){return p(e,this,t)}}function u(e,t){const n=p(e,t);if(n[0])throw n[0]}function f(e,t){const n=p(e,t,{coerce:!0});if(n[0])throw n[0];return n[1]}function l(e,t){const n=p(e,t,{coerce:!0,mask:!0});if(n[0])throw n[0];return n[1]}function d(e,t){return!p(e,t)[0]}function p(e,n,r={}){const o=a(e,n,r),i=function(e){const{done:t,value:n}=e.next();return t?void 0:n}(o);if(i[0]){return[new t(i[0],(function*(){for(const e of o)e[0]&&(yield e[0])})),void 0]}return[void 0,i[1]]}function y(e,t){return new s({type:e,schema:null,validator:t})}function v(){return y("never",(()=>!1))}function h(e){const t=e?Object.keys(e):[],r=v();return new s({type:"object",schema:e||null,*entries(o){if(e&&n(o)){const n=new Set(Object.keys(o));for(const r of t)n.delete(r),yield[r,o[r],e[r]];for(const e of n)yield[e,o[e],r]}},validator:e=>n(e)||"Expected an object, but received: "+o(e),coercer:e=>n(e)?{...e}:e})}function m(e){return new s({...e,validator:(t,n)=>void 0===t||e.validator(t,n),refiner:(t,n)=>void 0===t||e.refiner(t,n)})}function b(){return y("string",(e=>"string"==typeof e||"Expected a string, but received: "+o(e)))}function g(e){const t=Object.keys(e);return new s({type:"type",schema:e,*entries(r){if(n(r))for(const n of t)yield[n,r[n],e[n]]},validator:e=>n(e)||"Expected an object, but received: "+o(e)})}function w(){return y("unknown",(()=>!0))}function x(e,t,n){return new s({...e,coercer:(r,o)=>d(r,t)?e.coercer(n(r,o),o):e.coercer(r,o)})}function E(e,t,n){return new s({...e,*refiner(r,o){yield*e.refiner(r,o);const i=c(n(r,o),o,e,r);for(const e of i)yield{...e,refinement:t}}})}e.Struct=s,e.StructError=t,e.any=function(){return y("any",(()=>!0))},e.array=function(e){return new s({type:"array",schema:e,*entries(t){if(e&&Array.isArray(t))for(const[n,r]of t.entries())yield[n,r,e]},coercer:e=>Array.isArray(e)?e.slice():e,validator:e=>Array.isArray(e)||"Expected an array value, but received: "+o(e)})},e.assert=u,e.assign=function(...e){const t="type"===e[0].type,n=e.map((e=>e.schema)),r=Object.assign({},...n);return t?g(r):h(r)},e.boolean=function(){return y("boolean",(e=>"boolean"==typeof e))},e.coerce=x,e.create=f,e.date=function(){return y("date",(e=>e instanceof Date&&!isNaN(e.getTime())||"Expected a valid `Date` object, but received: "+o(e)))},e.defaulted=function(e,t,n={}){return x(e,w(),(e=>{const o="function"==typeof t?t():t;if(void 0===e)return o;if(!n.strict&&r(e)&&r(o)){const t={...e};let n=!1;for(const e in o)void 0===t[e]&&(t[e]=o[e],n=!0);if(n)return t}return e}))},e.define=y,e.deprecated=function(e,t){return new s({...e,refiner:(t,n)=>void 0===t||e.refiner(t,n),validator:(n,r)=>void 0===n||(t(n,r),e.validator(n,r))})},e.dynamic=function(e){return new s({type:"dynamic",schema:null,*entries(t,n){const r=e(t,n);yield*r.entries(t,n)},validator:(t,n)=>e(t,n).validator(t,n),coercer:(t,n)=>e(t,n).coercer(t,n)})},e.empty=function(e){const t="Expected an empty "+e.type;return E(e,"empty",(e=>{if(e instanceof Map||e instanceof Set){const{size:n}=e;return 0===n||t+" but received one with a size of `"+n+"`"}{const{length:n}=e;return 0===n||t+" but received one with a length of `"+n+"`"}}))},e.enums=function(e){const t={},n=e.map((e=>o(e))).join();for(const n of e)t[n]=n;return new s({type:"enums",schema:t,validator:t=>e.includes(t)||"Expected one of `"+n+"`, but received: "+o(t)})},e.func=function(){return y("func",(e=>"function"==typeof e||"Expected a function, but received: "+o(e)))},e.instance=function(e){return y("instance",(t=>t instanceof e||"Expected a `"+e.name+"` instance, but received: "+o(t)))},e.integer=function(){return y("integer",(e=>"number"==typeof e&&!isNaN(e)&&Number.isInteger(e)||"Expected an integer, but received: "+o(e)))},e.intersection=function(e){return new s({type:"intersection",schema:null,*entries(t,n){for(const r of e)yield*r.entries(t,n)},*validator(t,n){for(const r of e)yield*r.validator(t,n)},*refiner(t,n){for(const r of e)yield*r.refiner(t,n)}})},e.is=d,e.lazy=function(e){let t;return new s({type:"lazy",schema:null,*entries(n,r){null!=t||(t=e()),yield*t.entries(n,r)},validator:(n,r)=>(null!=t||(t=e()),t.validator(n,r)),coercer:(n,r)=>(null!=t||(t=e()),t.coercer(n,r))})},e.literal=function(e){const t=o(e),n=typeof e;return new s({type:"literal",schema:"string"===n||"number"===n||"boolean"===n?e:null,validator:n=>n===e||"Expected the literal `"+t+"`, but received: "+o(n)})},e.map=function(e,t){return new s({type:"map",schema:null,*entries(n){if(e&&t&&n instanceof Map)for(const[r,o]of n.entries())yield[r,r,e],yield[r,o,t]},coercer:e=>e instanceof Map?new Map(e):e,validator:e=>e instanceof Map||"Expected a `Map` object, but received: "+o(e)})},e.mask=l,e.max=function(e,t,n={}){const{exclusive:r}=n;return E(e,"max",(n=>r?n<t:n<=t||"Expected a "+e.type+" less than "+(r?"":"or equal to ")+t+" but received `"+n+"`"))},e.min=function(e,t,n={}){const{exclusive:r}=n;return E(e,"min",(n=>r?n>t:n>=t||"Expected a "+e.type+" greater than "+(r?"":"or equal to ")+t+" but received `"+n+"`"))},e.never=v,e.nullable=function(e){return new s({...e,validator:(t,n)=>null===t||e.validator(t,n),refiner:(t,n)=>null===t||e.refiner(t,n)})},e.number=function(){return y("number",(e=>"number"==typeof e&&!isNaN(e)||"Expected a number, but received: "+o(e)))},e.object=h,e.omit=function(e,t){const{schema:n}=e,r={...n};for(const e of t)delete r[e];return h(r)},e.optional=m,e.partial=function(e){const t=e instanceof s?{...e.schema}:{...e};for(const e in t)t[e]=m(t[e]);return h(t)},e.pattern=function(e,t){return E(e,"pattern",(n=>t.test(n)||"Expected a "+e.type+" matching `/"+t.source+'/` but received "'+n+'"'))},e.pick=function(e,t){const{schema:n}=e,r={};for(const e of t)r[e]=n[e];return h(r)},e.record=function(e,t){return new s({type:"record",schema:null,*entries(r){if(n(r))for(const n in r){const o=r[n];yield[n,n,e],yield[n,o,t]}},validator:e=>n(e)||"Expected an object, but received: "+o(e)})},e.refine=E,e.regexp=function(){return y("regexp",(e=>e instanceof RegExp))},e.set=function(e){return new s({type:"set",schema:null,*entries(t){if(e&&t instanceof Set)for(const n of t)yield[n,n,e]},coercer:e=>e instanceof Set?new Set(e):e,validator:e=>e instanceof Set||"Expected a `Set` object, but received: "+o(e)})},e.size=function(e,t,n=t){const r="Expected a "+e.type,o=t===n?"of `"+t+"`":"between `"+t+"` and `"+n+"`";return E(e,"size",(e=>{if("number"==typeof e||e instanceof Date)return t<=e&&e<=n||r+" "+o+" but received `"+e+"`";if(e instanceof Map||e instanceof Set){const{size:i}=e;return t<=i&&i<=n||r+" with a size "+o+" but received one with a size of `"+i+"`"}{const{length:i}=e;return t<=i&&i<=n||r+" with a length "+o+" but received one with a length of `"+i+"`"}}))},e.string=b,e.struct=function(e,t){return console.warn("superstruct@0.11 - The `struct` helper has been renamed to `define`."),y(e,t)},e.trimmed=function(e){return x(e,b(),(e=>e.trim()))},e.tuple=function(e){const t=v();return new s({type:"tuple",schema:null,*entries(n){if(Array.isArray(n)){const r=Math.max(e.length,n.length);for(let o=0;o<r;o++)yield[o,n[o],e[o]||t]}},validator:e=>Array.isArray(e)||"Expected an array, but received: "+o(e)})},e.type=g,e.union=function(e){const t=e.map((e=>e.type)).join(" | ");return new s({type:"union",schema:null,coercer:(t,n)=>(e.find((e=>{const[n]=e.validate(t,{coerce:!0});return!n}))||w()).coercer(t,n),validator(n,r){const i=[];for(const t of e){const[...e]=a(n,t,r),[o]=e;if(!o[0])return[];for(const[t]of e)t&&i.push(t)}return["Expected the value to satisfy a union of `"+t+"`, but received: "+o(n),...i]}})},e.unknown=w,e.validate=p,Object.defineProperty(e,"__esModule",{value:!0})}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Superstruct={})}(this,(function(e){"use strict";class t extends TypeError{constructor(e,t){let n;const{message:r,...i}=e,{path:o}=e;super(0===o.length?r:"At path: "+o.join(".")+" -- "+r),this.value=void 0,this.key=void 0,this.type=void 0,this.refinement=void 0,this.path=void 0,this.branch=void 0,this.failures=void 0,Object.assign(this,i),this.name=this.constructor.name,this.failures=()=>{var r;return null!=(r=n)?r:n=[e,...t()]}}}function n(e){return"object"==typeof e&&null!=e}function r(e){if("[object Object]"!==Object.prototype.toString.call(e))return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function i(e){return"string"==typeof e?JSON.stringify(e):""+e}function o(e,t,n,r){if(!0===e)return;!1===e?e={}:"string"==typeof e&&(e={message:e});const{path:o,branch:c}=t,{type:a}=n,{refinement:s,message:u="Expected a value of type `"+a+"`"+(s?" with refinement `"+s+"`":"")+", but received: `"+i(r)+"`"}=e;return{value:r,type:a,refinement:s,key:o[o.length-1],path:o,branch:c,...e,message:u}}function*c(e,t,r,i){var c;n(c=e)&&"function"==typeof c[Symbol.iterator]||(e=[e]);for(const n of e){const e=o(n,t,r,i);e&&(yield e)}}function*a(e,t,r={}){const{path:i=[],branch:o=[e],coerce:c=!1,mask:s=!1}=r,u={path:i,branch:o};if(c&&(e=t.coercer(e,u),s&&"type"!==t.type&&n(t.schema)&&n(e)&&!Array.isArray(e)))for(const n in e)void 0===t.schema[n]&&delete e[n];let f=!0;for(const n of t.validator(e,u))f=!1,yield[n,void 0];for(let[r,d,l]of t.entries(e,u)){const t=a(d,l,{path:void 0===r?i:[...i,r],branch:void 0===r?o:[...o,d],coerce:c,mask:s});for(const i of t)i[0]?(f=!1,yield[i[0],void 0]):c&&(d=i[1],void 0===r?e=d:e instanceof Map?e.set(r,d):e instanceof Set?e.add(d):n(e)&&(e[r]=d))}if(f)for(const n of t.refiner(e,u))f=!1,yield[n,void 0];f&&(yield[void 0,e])}class s{constructor(e){this.TYPE=void 0,this.type=void 0,this.schema=void 0,this.coercer=void 0,this.validator=void 0,this.refiner=void 0,this.entries=void 0;const{type:t,schema:n,validator:r,refiner:i,coercer:o=(e=>e),entries:a=function*(){}}=e;this.type=t,this.schema=n,this.entries=a,this.coercer=o,this.validator=r?(e,t)=>c(r(e,t),t,this,e):()=>[],this.refiner=i?(e,t)=>c(i(e,t),t,this,e):()=>[]}assert(e){return u(e,this)}create(e){return f(e,this)}is(e){return l(e,this)}mask(e){return d(e,this)}validate(e,t={}){return p(e,this,t)}}function u(e,t){const n=p(e,t);if(n[0])throw n[0]}function f(e,t){const n=p(e,t,{coerce:!0});if(n[0])throw n[0];return n[1]}function d(e,t){const n=p(e,t,{coerce:!0,mask:!0});if(n[0])throw n[0];return n[1]}function l(e,t){return!p(e,t)[0]}function p(e,n,r={}){const i=a(e,n,r),o=function(e){const{done:t,value:n}=e.next();return t?void 0:n}(i);if(o[0]){return[new t(o[0],(function*(){for(const e of i)e[0]&&(yield e[0])})),void 0]}return[void 0,o[1]]}function y(e,t){return new s({type:e,schema:null,validator:t})}function v(){return y("never",(()=>!1))}function h(e){const t=e?Object.keys(e):[],r=v();return new s({type:"object",schema:e||null,*entries(i){if(e&&n(i)){const n=new Set(Object.keys(i));for(const r of t)n.delete(r),yield[r,i[r],e[r]];for(const e of n)yield[e,i[e],r]}},validator:e=>n(e)||"Expected an object, but received: "+i(e),coercer:e=>n(e)?{...e}:e})}function m(e){return new s({...e,validator:(t,n)=>void 0===t||e.validator(t,n),refiner:(t,n)=>void 0===t||e.refiner(t,n)})}function b(){return y("string",(e=>"string"==typeof e||"Expected a string, but received: "+i(e)))}function g(e){const t=Object.keys(e);return new s({type:"type",schema:e,*entries(r){if(n(r))for(const n of t)yield[n,r[n],e[n]]},validator:e=>n(e)||"Expected an object, but received: "+i(e)})}function w(){return y("unknown",(()=>!0))}function x(e,t,n){return new s({...e,coercer:(r,i)=>l(r,t)?e.coercer(n(r,i),i):e.coercer(r,i)})}function E(e){return e instanceof Map||e instanceof Set?e.size:e.length}function j(e,t,n){return new s({...e,*refiner(r,i){yield*e.refiner(r,i);const o=c(n(r,i),i,e,r);for(const e of o)yield{...e,refinement:t}}})}e.Struct=s,e.StructError=t,e.any=function(){return y("any",(()=>!0))},e.array=function(e){return new s({type:"array",schema:e,*entries(t){if(e&&Array.isArray(t))for(const[n,r]of t.entries())yield[n,r,e]},coercer:e=>Array.isArray(e)?e.slice():e,validator:e=>Array.isArray(e)||"Expected an array value, but received: "+i(e)})},e.assert=u,e.assign=function(...e){const t="type"===e[0].type,n=e.map((e=>e.schema)),r=Object.assign({},...n);return t?g(r):h(r)},e.bigint=function(){return y("bigint",(e=>"bigint"==typeof e))},e.boolean=function(){return y("boolean",(e=>"boolean"==typeof e))},e.coerce=x,e.create=f,e.date=function(){return y("date",(e=>e instanceof Date&&!isNaN(e.getTime())||"Expected a valid `Date` object, but received: "+i(e)))},e.defaulted=function(e,t,n={}){return x(e,w(),(e=>{const i="function"==typeof t?t():t;if(void 0===e)return i;if(!n.strict&&r(e)&&r(i)){const t={...e};let n=!1;for(const e in i)void 0===t[e]&&(t[e]=i[e],n=!0);if(n)return t}return e}))},e.define=y,e.deprecated=function(e,t){return new s({...e,refiner:(t,n)=>void 0===t||e.refiner(t,n),validator:(n,r)=>void 0===n||(t(n,r),e.validator(n,r))})},e.dynamic=function(e){return new s({type:"dynamic",schema:null,*entries(t,n){const r=e(t,n);yield*r.entries(t,n)},validator:(t,n)=>e(t,n).validator(t,n),coercer:(t,n)=>e(t,n).coercer(t,n)})},e.empty=function(e){return j(e,"empty",(t=>{const n=E(t);return 0===n||"Expected an empty "+e.type+" but received one with a size of `"+n+"`"}))},e.enums=function(e){const t={},n=e.map((e=>i(e))).join();for(const n of e)t[n]=n;return new s({type:"enums",schema:t,validator:t=>e.includes(t)||"Expected one of `"+n+"`, but received: "+i(t)})},e.func=function(){return y("func",(e=>"function"==typeof e||"Expected a function, but received: "+i(e)))},e.instance=function(e){return y("instance",(t=>t instanceof e||"Expected a `"+e.name+"` instance, but received: "+i(t)))},e.integer=function(){return y("integer",(e=>"number"==typeof e&&!isNaN(e)&&Number.isInteger(e)||"Expected an integer, but received: "+i(e)))},e.intersection=function(e){return new s({type:"intersection",schema:null,*entries(t,n){for(const r of e)yield*r.entries(t,n)},*validator(t,n){for(const r of e)yield*r.validator(t,n)},*refiner(t,n){for(const r of e)yield*r.refiner(t,n)}})},e.is=l,e.lazy=function(e){let t;return new s({type:"lazy",schema:null,*entries(n,r){null!=t||(t=e()),yield*t.entries(n,r)},validator:(n,r)=>(null!=t||(t=e()),t.validator(n,r)),coercer:(n,r)=>(null!=t||(t=e()),t.coercer(n,r))})},e.literal=function(e){const t=i(e),n=typeof e;return new s({type:"literal",schema:"string"===n||"number"===n||"boolean"===n?e:null,validator:n=>n===e||"Expected the literal `"+t+"`, but received: "+i(n)})},e.map=function(e,t){return new s({type:"map",schema:null,*entries(n){if(e&&t&&n instanceof Map)for(const[r,i]of n.entries())yield[r,r,e],yield[r,i,t]},coercer:e=>e instanceof Map?new Map(e):e,validator:e=>e instanceof Map||"Expected a `Map` object, but received: "+i(e)})},e.mask=d,e.max=function(e,t,n={}){const{exclusive:r}=n;return j(e,"max",(n=>r?n<t:n<=t||"Expected a "+e.type+" less than "+(r?"":"or equal to ")+t+" but received `"+n+"`"))},e.min=function(e,t,n={}){const{exclusive:r}=n;return j(e,"min",(n=>r?n>t:n>=t||"Expected a "+e.type+" greater than "+(r?"":"or equal to ")+t+" but received `"+n+"`"))},e.never=v,e.nonempty=function(e){return j(e,"nonempty",(t=>E(t)>0||"Expected a nonempty "+e.type+" but received an empty one"))},e.nullable=function(e){return new s({...e,validator:(t,n)=>null===t||e.validator(t,n),refiner:(t,n)=>null===t||e.refiner(t,n)})},e.number=function(){return y("number",(e=>"number"==typeof e&&!isNaN(e)||"Expected a number, but received: "+i(e)))},e.object=h,e.omit=function(e,t){const{schema:n}=e,r={...n};for(const e of t)delete r[e];return h(r)},e.optional=m,e.partial=function(e){const t=e instanceof s?{...e.schema}:{...e};for(const e in t)t[e]=m(t[e]);return h(t)},e.pattern=function(e,t){return j(e,"pattern",(n=>t.test(n)||"Expected a "+e.type+" matching `/"+t.source+'/` but received "'+n+'"'))},e.pick=function(e,t){const{schema:n}=e,r={};for(const e of t)r[e]=n[e];return h(r)},e.record=function(e,t){return new s({type:"record",schema:null,*entries(r){if(n(r))for(const n in r){const i=r[n];yield[n,n,e],yield[n,i,t]}},validator:e=>n(e)||"Expected an object, but received: "+i(e)})},e.refine=j,e.regexp=function(){return y("regexp",(e=>e instanceof RegExp))},e.set=function(e){return new s({type:"set",schema:null,*entries(t){if(e&&t instanceof Set)for(const n of t)yield[n,n,e]},coercer:e=>e instanceof Set?new Set(e):e,validator:e=>e instanceof Set||"Expected a `Set` object, but received: "+i(e)})},e.size=function(e,t,n=t){const r="Expected a "+e.type,i=t===n?"of `"+t+"`":"between `"+t+"` and `"+n+"`";return j(e,"size",(e=>{if("number"==typeof e||e instanceof Date)return t<=e&&e<=n||r+" "+i+" but received `"+e+"`";if(e instanceof Map||e instanceof Set){const{size:o}=e;return t<=o&&o<=n||r+" with a size "+i+" but received one with a size of `"+o+"`"}{const{length:o}=e;return t<=o&&o<=n||r+" with a length "+i+" but received one with a length of `"+o+"`"}}))},e.string=b,e.struct=function(e,t){return console.warn("superstruct@0.11 - The `struct` helper has been renamed to `define`."),y(e,t)},e.trimmed=function(e){return x(e,b(),(e=>e.trim()))},e.tuple=function(e){const t=v();return new s({type:"tuple",schema:null,*entries(n){if(Array.isArray(n)){const r=Math.max(e.length,n.length);for(let i=0;i<r;i++)yield[i,n[i],e[i]||t]}},validator:e=>Array.isArray(e)||"Expected an array, but received: "+i(e)})},e.type=g,e.union=function(e){const t=e.map((e=>e.type)).join(" | ");return new s({type:"union",schema:null,coercer:(t,n)=>(e.find((e=>{const[n]=e.validate(t,{coerce:!0});return!n}))||w()).coercer(t,n),validator(n,r){const o=[];for(const t of e){const[...e]=a(n,t,r),[i]=e;if(!i[0])return[];for(const[t]of e)t&&o.push(t)}return["Expected the value to satisfy a union of `"+t+"`, but received: "+i(n),...o]}})},e.unknown=w,e.validate=p,Object.defineProperty(e,"__esModule",{value:!0})}));

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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