Socket
Socket
Sign inDemoInstall

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.10.12 to 0.10.13

191

lib/index.cjs.d.ts

@@ -19,8 +19,3 @@ /**

});
} /**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
*/
}
/**

@@ -37,9 +32,6 @@ * `StructError` objects are thrown (or returned) by Superstruct when its

branch: Array<any>;
failures: () => Iterable<StructFailure>;
failures: () => Array<StructFailure>;
[key: string]: any;
constructor(failure: StructFailure, iterable: Iterable<StructFailure>);
} /**
* A `StructContext` contains information about the current value being
* validated as well as helper functions for failures and recursive validating.
*/
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
}
/**

@@ -55,6 +47,4 @@ * A `StructContext` contains information about the current value being

fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => Iterable<StructFailure>;
}; /**
* A `StructFailure` represents a single specific failure in validation.
*/
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
};
/**

@@ -69,48 +59,32 @@ * A `StructFailure` represents a single specific failure in validation.

[key: string]: any;
}; /**
};
/**
* A `StructResult` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>;
/**
* A `StructResult` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>; /**
* A type utility to extract the type from a `Struct` class.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0];
/**
* A type utility to extract the type from a `Struct` class.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0]; /**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T;
/**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T; /**
* Coerce a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T;
/**
* Coerce a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T; /**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T;
/**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T; /**
* Validate a value against a `Struct`, returning an error if invalid.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T]; /**
* Check a value against a `Struct`, returning an iterable of failures.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T];
/**
* Check a value against a `Struct`, returning an iterable of failures.
* Augment a `Struct` to add an additional coercion step to its input.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>;
/**
* Check a value against a `Struct`, returning an iterable of failures.
*/
/**
* Augment a `Struct` to add an additional coercion step to its input.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>; /**
* Augment a struct to coerce a default value for missing values.

@@ -121,9 +95,4 @@ *

*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>;
/**
* Augment a struct to coerce a default value for missing values.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>; /**
* Coerce a value to mask its properties to only that defined in the struct.

@@ -133,18 +102,7 @@ */

[key: string]: any;
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>; /**
* Check if a value is a plain object.
*/
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>;
/**
* Check if a value is a plain object.
*/
/**
* Check if a value is a plain object.
*/
/**
* Augment a string or array struct to constrain its length to zero.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>; /**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>;
/**

@@ -154,11 +112,7 @@ * Augment a string or array struct to constrain its length to being between a

*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>; /**
* Refine a string struct to match a specific regexp pattern.
*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>;
/**
* Refine a string struct to match a specific regexp pattern.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>; /**
* Augment a `Struct` to add an additional refinement to the validation.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>;
/**

@@ -171,17 +125,7 @@ * Augment a `Struct` to add an additional refinement to the validation.

[K in keyof T]: Struct<T[K]>;
}; /**
* Convert a validation result to an iterable of failures.
*/
};
/**
* Convert a validation result to an iterable of failures.
*/
/**
* Convert a validation result to an iterable of failures.
*/
/**
* Validate any value.
*/
declare function any(): Struct<any>; /**
* Validate that an array of values of a specific type.
*/
declare function any(): Struct<any>;
/**

@@ -195,8 +139,3 @@ * Validate that an array of values of a specific type.

*/
declare function boolean(): Struct<boolean>; /**
* Validate that `Date` values.
*
* Note: this also ensures that the value is *not* an invalid `Date` object,
* which can occur when parsing a date fails but still returns a `Date`.
*/
declare function boolean(): Struct<boolean>;
/**

@@ -208,11 +147,7 @@ * Validate that `Date` values.

*/
declare function date(): Struct<Date>; /**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
declare function date(): Struct<Date>;
/**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>; /**
* Validate that a value against a set of potential values.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>;
/**

@@ -226,5 +161,3 @@ * Validate that a value against a set of potential values.

*/
declare function func(): Struct<Function>; /**
* Validate that a value is an instance of a class.
*/
declare function func(): Struct<Function>;
/**

@@ -235,5 +168,3 @@ * Validate that a value is an instance of a class.

new (...args: any): any;
}>(Class: T): Struct<InstanceType<T>>; /**
* Validate that a value matches all of a set of structs.
*/
}>(Class: T): Struct<InstanceType<T>>;
/**

@@ -264,5 +195,3 @@ * Validate that a value matches all of a set of structs.

*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>; /**
* Validate that a value is a specific constant.
*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>;
/**

@@ -278,23 +207,15 @@ * Validate that a value is a specific constant.

*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>; /**
* Validate that a value always fails.
*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>;
/**
* Validate that a value always fails.
*/
declare function never(): Struct<never>; /**
* Augment a struct to make it accept `null` values.
*/
declare function never(): Struct<never>;
/**
* Augment a struct to make it accept `null` values.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>; /**
* Validate that a value is a number.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>;
/**
* Validate that a value is a number.
*/
declare function number(): Struct<number>; /**
* Type helper to Flatten the Union of optional and required properties.
*/
declare function number(): Struct<number>;
/**

@@ -305,5 +226,3 @@ * Type helper to Flatten the Union of optional and required properties.

[K in keyof U]: U[K];
} : never; /**
* Type helper to extract the optional keys of an object
*/
} : never;
/**

@@ -314,5 +233,3 @@ * Type helper to extract the optional keys of an object

[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T]; /**
* Type helper to extract the required keys of an object
*/
}[keyof T];
/**

@@ -323,6 +240,3 @@ * Type helper to extract the required keys of an object

[K in keyof T]: undefined extends T[K] ? never : K;
}[keyof T]; /**
* Type helper to create optional properties when the property value can be
* undefined (ie. when `optional()` is used to define a type)
*/
}[keyof T];
/**

@@ -336,5 +250,3 @@ * Type helper to create optional properties when the property value can be

[K in OptionalKeys<T>]?: T[K];
}>; /**
* Validate that an object with specific entry values.
*/
}>;
/**

@@ -350,5 +262,3 @@ * Validate that an object with specific entry values.

*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>; /**
* Validate that a partial object with specific entry values.
*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>;
/**

@@ -359,6 +269,3 @@ * Validate that a partial object with specific entry values.

[K in keyof V]?: StructType<V[K]>;
}>; /**
* Validate that a value is a record with specific key and
* value entries.
*/
}>;
/**

@@ -368,23 +275,15 @@ * Validate that a value is a record with specific key and

*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>; /**
* Validate that a set of values matches a specific type.
*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>;
/**
* Validate that a set of values matches a specific type.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>; /**
* Validate that a value is a string.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>;
/**
* Validate that a value is a string.
*/
declare function string(): Struct<string>; /**
* Define a `Struct` instance with a type and validation function.
*/
declare function string(): Struct<string>;
/**
* Define a `Struct` instance with a type and validation function.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>; /**
* Validate that a value is a tuple with entries of specific types.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>;
/**

@@ -416,5 +315,3 @@ * Validate that a value is a tuple with entries of specific types.

[K in keyof V]: StructType<V[K]>;
}>; /**
* Validate that a value is one of a set of types.
*/
}>;
/**

@@ -421,0 +318,0 @@ * Validate that a value is one of a set of types.

@@ -19,8 +19,3 @@ /**

});
} /**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
*/
}
/**

@@ -37,9 +32,6 @@ * `StructError` objects are thrown (or returned) by Superstruct when its

branch: Array<any>;
failures: () => Iterable<StructFailure>;
failures: () => Array<StructFailure>;
[key: string]: any;
constructor(failure: StructFailure, iterable: Iterable<StructFailure>);
} /**
* A `StructContext` contains information about the current value being
* validated as well as helper functions for failures and recursive validating.
*/
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
}
/**

@@ -55,6 +47,4 @@ * A `StructContext` contains information about the current value being

fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => Iterable<StructFailure>;
}; /**
* A `StructFailure` represents a single specific failure in validation.
*/
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
};
/**

@@ -69,48 +59,32 @@ * A `StructFailure` represents a single specific failure in validation.

[key: string]: any;
}; /**
};
/**
* A `StructResult` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>;
/**
* A `StructResult` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>; /**
* A type utility to extract the type from a `Struct` class.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0];
/**
* A type utility to extract the type from a `Struct` class.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0]; /**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T;
/**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T; /**
* Coerce a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T;
/**
* Coerce a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T; /**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T;
/**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T; /**
* Validate a value against a `Struct`, returning an error if invalid.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T]; /**
* Check a value against a `Struct`, returning an iterable of failures.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T];
/**
* Check a value against a `Struct`, returning an iterable of failures.
* Augment a `Struct` to add an additional coercion step to its input.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>;
/**
* Check a value against a `Struct`, returning an iterable of failures.
*/
/**
* Augment a `Struct` to add an additional coercion step to its input.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>; /**
* Augment a struct to coerce a default value for missing values.

@@ -121,9 +95,4 @@ *

*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>;
/**
* Augment a struct to coerce a default value for missing values.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>; /**
* Coerce a value to mask its properties to only that defined in the struct.

@@ -133,18 +102,7 @@ */

[key: string]: any;
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>; /**
* Check if a value is a plain object.
*/
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>;
/**
* Check if a value is a plain object.
*/
/**
* Check if a value is a plain object.
*/
/**
* Augment a string or array struct to constrain its length to zero.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>; /**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>;
/**

@@ -154,11 +112,7 @@ * Augment a string or array struct to constrain its length to being between a

*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>; /**
* Refine a string struct to match a specific regexp pattern.
*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>;
/**
* Refine a string struct to match a specific regexp pattern.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>; /**
* Augment a `Struct` to add an additional refinement to the validation.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>;
/**

@@ -171,17 +125,7 @@ * Augment a `Struct` to add an additional refinement to the validation.

[K in keyof T]: Struct<T[K]>;
}; /**
* Convert a validation result to an iterable of failures.
*/
};
/**
* Convert a validation result to an iterable of failures.
*/
/**
* Convert a validation result to an iterable of failures.
*/
/**
* Validate any value.
*/
declare function any(): Struct<any>; /**
* Validate that an array of values of a specific type.
*/
declare function any(): Struct<any>;
/**

@@ -195,8 +139,3 @@ * Validate that an array of values of a specific type.

*/
declare function boolean(): Struct<boolean>; /**
* Validate that `Date` values.
*
* Note: this also ensures that the value is *not* an invalid `Date` object,
* which can occur when parsing a date fails but still returns a `Date`.
*/
declare function boolean(): Struct<boolean>;
/**

@@ -208,11 +147,7 @@ * Validate that `Date` values.

*/
declare function date(): Struct<Date>; /**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
declare function date(): Struct<Date>;
/**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>; /**
* Validate that a value against a set of potential values.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>;
/**

@@ -226,5 +161,3 @@ * Validate that a value against a set of potential values.

*/
declare function func(): Struct<Function>; /**
* Validate that a value is an instance of a class.
*/
declare function func(): Struct<Function>;
/**

@@ -235,5 +168,3 @@ * Validate that a value is an instance of a class.

new (...args: any): any;
}>(Class: T): Struct<InstanceType<T>>; /**
* Validate that a value matches all of a set of structs.
*/
}>(Class: T): Struct<InstanceType<T>>;
/**

@@ -264,5 +195,3 @@ * Validate that a value matches all of a set of structs.

*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>; /**
* Validate that a value is a specific constant.
*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>;
/**

@@ -278,23 +207,15 @@ * Validate that a value is a specific constant.

*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>; /**
* Validate that a value always fails.
*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>;
/**
* Validate that a value always fails.
*/
declare function never(): Struct<never>; /**
* Augment a struct to make it accept `null` values.
*/
declare function never(): Struct<never>;
/**
* Augment a struct to make it accept `null` values.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>; /**
* Validate that a value is a number.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>;
/**
* Validate that a value is a number.
*/
declare function number(): Struct<number>; /**
* Type helper to Flatten the Union of optional and required properties.
*/
declare function number(): Struct<number>;
/**

@@ -305,5 +226,3 @@ * Type helper to Flatten the Union of optional and required properties.

[K in keyof U]: U[K];
} : never; /**
* Type helper to extract the optional keys of an object
*/
} : never;
/**

@@ -314,5 +233,3 @@ * Type helper to extract the optional keys of an object

[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T]; /**
* Type helper to extract the required keys of an object
*/
}[keyof T];
/**

@@ -323,6 +240,3 @@ * Type helper to extract the required keys of an object

[K in keyof T]: undefined extends T[K] ? never : K;
}[keyof T]; /**
* Type helper to create optional properties when the property value can be
* undefined (ie. when `optional()` is used to define a type)
*/
}[keyof T];
/**

@@ -336,5 +250,3 @@ * Type helper to create optional properties when the property value can be

[K in OptionalKeys<T>]?: T[K];
}>; /**
* Validate that an object with specific entry values.
*/
}>;
/**

@@ -350,5 +262,3 @@ * Validate that an object with specific entry values.

*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>; /**
* Validate that a partial object with specific entry values.
*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>;
/**

@@ -359,6 +269,3 @@ * Validate that a partial object with specific entry values.

[K in keyof V]?: StructType<V[K]>;
}>; /**
* Validate that a value is a record with specific key and
* value entries.
*/
}>;
/**

@@ -368,23 +275,15 @@ * Validate that a value is a record with specific key and

*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>; /**
* Validate that a set of values matches a specific type.
*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>;
/**
* Validate that a set of values matches a specific type.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>; /**
* Validate that a value is a string.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>;
/**
* Validate that a value is a string.
*/
declare function string(): Struct<string>; /**
* Define a `Struct` instance with a type and validation function.
*/
declare function string(): Struct<string>;
/**
* Define a `Struct` instance with a type and validation function.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>; /**
* Validate that a value is a tuple with entries of specific types.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>;
/**

@@ -416,5 +315,3 @@ * Validate that a value is a tuple with entries of specific types.

[K in keyof V]: StructType<V[K]>;
}>; /**
* Validate that a value is one of a set of types.
*/
}>;
/**

@@ -421,0 +318,0 @@ * Validate that a value is one of a set of types.

@@ -89,12 +89,22 @@ function _defineProperty(obj, key, value) {

*/
function toFailures(result, context) {
if (result === true) {
return [];
} else if (result === false) {
return [context.fail()];
function* toFailures(result, context) {
if (result === true) ; else if (result === false) {
yield context.fail();
} else {
return result;
yield* result;
}
}
/**
* Shifts (removes and returns) the first value from the `input` iterator.
* Like `Array.prototype.shift()` but for an `Iterator`.
*/
function iteratorShift(input) {
const {
done,
value
} = input.next();
return done ? undefined : value;
}
/**

@@ -131,3 +141,3 @@ * `Struct` objects encapsulate the schema for a specific data type (with

class StructError extends TypeError {
constructor(failure, iterable) {
constructor(failure, moreFailures) {
const {

@@ -142,6 +152,10 @@ path,

const message = `Expected a value of type \`${type}\`${path.length ? ` for \`${path.join('.')}\`` : ''} but received \`${JSON.stringify(value)}\`.`;
let failuresResult;
function* failures() {
yield failure;
yield* iterable;
function failures() {
if (!failuresResult) {
failuresResult = [failure, ...moreFailures];
}
return failuresResult;
}

@@ -198,7 +212,7 @@

const iterable = check(value, struct);
const [failure] = iterable;
const failures = check(value, struct);
const failure = iteratorShift(failures);
if (failure) {
const error = new StructError(failure, iterable);
const error = new StructError(failure, failures);
return [error, undefined];

@@ -240,3 +254,3 @@ } else {

const failures = toFailures(struct.validator(value, ctx), ctx);
const [failure] = failures;
const failure = iteratorShift(failures);

@@ -243,0 +257,0 @@ if (failure) {

@@ -31,5 +31,5 @@ /**

branch: Array<any>;
failures: () => Iterable<StructFailure>;
failures: () => Array<StructFailure>;
[key: string]: any;
constructor(failure: StructFailure, iterable: Iterable<StructFailure>);
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
}

@@ -46,3 +46,3 @@ /**

fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => Iterable<StructFailure>;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
};

@@ -49,0 +49,0 @@ /**

@@ -9,3 +9,8 @@ import { Struct, StructResult, StructFailure, StructContext } from './struct';

*/
export declare function toFailures(result: StructResult, context: StructContext): Iterable<StructFailure>;
export declare function toFailures(result: StructResult, context: StructContext): IterableIterator<StructFailure>;
/**
* Shifts (removes and returns) the first value from the `input` iterator.
* Like `Array.prototype.shift()` but for an `Iterator`.
*/
export declare function iteratorShift<T>(input: Iterator<T>): T | undefined;
//# sourceMappingURL=utils.d.ts.map

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

"description": "A simple, expressive way to validate data in JavaScript.",
"version": "0.10.12",
"version": "0.10.13",
"license": "MIT",

@@ -27,3 +27,3 @@ "repository": "git://github.com/ianstormtaylor/superstruct.git",

"@types/lodash": "^4.14.144",
"@types/mocha": "^7.0.2",
"@types/mocha": "^8.0.3",
"@types/node": "^14.0.6",

@@ -49,3 +49,3 @@ "@typescript-eslint/eslint-plugin": "^2.3.3",

"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^6.1.0",
"rollup-plugin-terser": "^7.0.2",
"rollup-plugin-ts": "^1.2.24",

@@ -52,0 +52,0 @@ "typescript": "^3.9.3"

@@ -19,8 +19,3 @@ /**

});
} /**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
*/
}
/**

@@ -37,9 +32,6 @@ * `StructError` objects are thrown (or returned) by Superstruct when its

branch: Array<any>;
failures: () => Iterable<StructFailure>;
failures: () => Array<StructFailure>;
[key: string]: any;
constructor(failure: StructFailure, iterable: Iterable<StructFailure>);
} /**
* A `StructContext` contains information about the current value being
* validated as well as helper functions for failures and recursive validating.
*/
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
}
/**

@@ -55,6 +47,4 @@ * A `StructContext` contains information about the current value being

fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => Iterable<StructFailure>;
}; /**
* A `StructFailure` represents a single specific failure in validation.
*/
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
};
/**

@@ -69,48 +59,32 @@ * A `StructFailure` represents a single specific failure in validation.

[key: string]: any;
}; /**
};
/**
* A `StructResult` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>;
/**
* A `StructResult` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>; /**
* A type utility to extract the type from a `Struct` class.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0];
/**
* A type utility to extract the type from a `Struct` class.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0]; /**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T;
/**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T; /**
* Coerce a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T;
/**
* Coerce a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T; /**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T;
/**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T; /**
* Validate a value against a `Struct`, returning an error if invalid.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T]; /**
* Check a value against a `Struct`, returning an iterable of failures.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T];
/**
* Check a value against a `Struct`, returning an iterable of failures.
* Augment a `Struct` to add an additional coercion step to its input.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>;
/**
* Check a value against a `Struct`, returning an iterable of failures.
*/
/**
* Augment a `Struct` to add an additional coercion step to its input.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>; /**
* Augment a struct to coerce a default value for missing values.

@@ -121,9 +95,4 @@ *

*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>;
/**
* Augment a struct to coerce a default value for missing values.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>; /**
* Coerce a value to mask its properties to only that defined in the struct.

@@ -133,18 +102,7 @@ */

[key: string]: any;
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>; /**
* Check if a value is a plain object.
*/
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>;
/**
* Check if a value is a plain object.
*/
/**
* Check if a value is a plain object.
*/
/**
* Augment a string or array struct to constrain its length to zero.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>; /**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>;
/**

@@ -154,11 +112,7 @@ * Augment a string or array struct to constrain its length to being between a

*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>; /**
* Refine a string struct to match a specific regexp pattern.
*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>;
/**
* Refine a string struct to match a specific regexp pattern.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>; /**
* Augment a `Struct` to add an additional refinement to the validation.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>;
/**

@@ -171,17 +125,7 @@ * Augment a `Struct` to add an additional refinement to the validation.

[K in keyof T]: Struct<T[K]>;
}; /**
* Convert a validation result to an iterable of failures.
*/
};
/**
* Convert a validation result to an iterable of failures.
*/
/**
* Convert a validation result to an iterable of failures.
*/
/**
* Validate any value.
*/
declare function any(): Struct<any>; /**
* Validate that an array of values of a specific type.
*/
declare function any(): Struct<any>;
/**

@@ -195,8 +139,3 @@ * Validate that an array of values of a specific type.

*/
declare function boolean(): Struct<boolean>; /**
* Validate that `Date` values.
*
* Note: this also ensures that the value is *not* an invalid `Date` object,
* which can occur when parsing a date fails but still returns a `Date`.
*/
declare function boolean(): Struct<boolean>;
/**

@@ -208,11 +147,7 @@ * Validate that `Date` values.

*/
declare function date(): Struct<Date>; /**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
declare function date(): Struct<Date>;
/**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>; /**
* Validate that a value against a set of potential values.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>;
/**

@@ -226,5 +161,3 @@ * Validate that a value against a set of potential values.

*/
declare function func(): Struct<Function>; /**
* Validate that a value is an instance of a class.
*/
declare function func(): Struct<Function>;
/**

@@ -235,5 +168,3 @@ * Validate that a value is an instance of a class.

new (...args: any): any;
}>(Class: T): Struct<InstanceType<T>>; /**
* Validate that a value matches all of a set of structs.
*/
}>(Class: T): Struct<InstanceType<T>>;
/**

@@ -264,5 +195,3 @@ * Validate that a value matches all of a set of structs.

*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>; /**
* Validate that a value is a specific constant.
*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>;
/**

@@ -278,23 +207,15 @@ * Validate that a value is a specific constant.

*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>; /**
* Validate that a value always fails.
*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>;
/**
* Validate that a value always fails.
*/
declare function never(): Struct<never>; /**
* Augment a struct to make it accept `null` values.
*/
declare function never(): Struct<never>;
/**
* Augment a struct to make it accept `null` values.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>; /**
* Validate that a value is a number.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>;
/**
* Validate that a value is a number.
*/
declare function number(): Struct<number>; /**
* Type helper to Flatten the Union of optional and required properties.
*/
declare function number(): Struct<number>;
/**

@@ -305,5 +226,3 @@ * Type helper to Flatten the Union of optional and required properties.

[K in keyof U]: U[K];
} : never; /**
* Type helper to extract the optional keys of an object
*/
} : never;
/**

@@ -314,5 +233,3 @@ * Type helper to extract the optional keys of an object

[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T]; /**
* Type helper to extract the required keys of an object
*/
}[keyof T];
/**

@@ -323,6 +240,3 @@ * Type helper to extract the required keys of an object

[K in keyof T]: undefined extends T[K] ? never : K;
}[keyof T]; /**
* Type helper to create optional properties when the property value can be
* undefined (ie. when `optional()` is used to define a type)
*/
}[keyof T];
/**

@@ -336,5 +250,3 @@ * Type helper to create optional properties when the property value can be

[K in OptionalKeys<T>]?: T[K];
}>; /**
* Validate that an object with specific entry values.
*/
}>;
/**

@@ -350,5 +262,3 @@ * Validate that an object with specific entry values.

*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>; /**
* Validate that a partial object with specific entry values.
*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>;
/**

@@ -359,6 +269,3 @@ * Validate that a partial object with specific entry values.

[K in keyof V]?: StructType<V[K]>;
}>; /**
* Validate that a value is a record with specific key and
* value entries.
*/
}>;
/**

@@ -368,23 +275,15 @@ * Validate that a value is a record with specific key and

*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>; /**
* Validate that a set of values matches a specific type.
*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>;
/**
* Validate that a set of values matches a specific type.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>; /**
* Validate that a value is a string.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>;
/**
* Validate that a value is a string.
*/
declare function string(): Struct<string>; /**
* Define a `Struct` instance with a type and validation function.
*/
declare function string(): Struct<string>;
/**
* Define a `Struct` instance with a type and validation function.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>; /**
* Validate that a value is a tuple with entries of specific types.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>;
/**

@@ -416,5 +315,3 @@ * Validate that a value is a tuple with entries of specific types.

[K in keyof V]: StructType<V[K]>;
}>; /**
* Validate that a value is one of a set of types.
*/
}>;
/**

@@ -421,0 +318,0 @@ * Validate that a value is one of a set of types.

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.Superstruct = {}));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Superstruct = {}));
}(this, (function (exports) { 'use strict';

@@ -95,12 +95,22 @@

*/
function toFailures(result, context) {
if (result === true) {
return [];
} else if (result === false) {
return [context.fail()];
function* toFailures(result, context) {
if (result === true) ; else if (result === false) {
yield context.fail();
} else {
return result;
yield* result;
}
}
/**
* Shifts (removes and returns) the first value from the `input` iterator.
* Like `Array.prototype.shift()` but for an `Iterator`.
*/
function iteratorShift(input) {
const {
done,
value
} = input.next();
return done ? undefined : value;
}
/**

@@ -137,3 +147,3 @@ * `Struct` objects encapsulate the schema for a specific data type (with

class StructError extends TypeError {
constructor(failure, iterable) {
constructor(failure, moreFailures) {
const {

@@ -148,6 +158,10 @@ path,

const message = `Expected a value of type \`${type}\`${path.length ? ` for \`${path.join('.')}\`` : ''} but received \`${JSON.stringify(value)}\`.`;
let failuresResult;
function* failures() {
yield failure;
yield* iterable;
function failures() {
if (!failuresResult) {
failuresResult = [failure, ...moreFailures];
}
return failuresResult;
}

@@ -204,7 +218,7 @@

const iterable = check(value, struct);
const [failure] = iterable;
const failures = check(value, struct);
const failure = iteratorShift(failures);
if (failure) {
const error = new StructError(failure, iterable);
const error = new StructError(failure, failures);
return [error, undefined];

@@ -246,3 +260,3 @@ } else {

const failures = toFailures(struct.validator(value, ctx), ctx);
const [failure] = failures;
const failure = iteratorShift(failures);

@@ -249,0 +263,0 @@ if (failure) {

@@ -19,8 +19,3 @@ /**

});
} /**
* `StructError` objects are thrown (or returned) by Superstruct when its
* validation fails. The error represents the first error encountered during
* validation. But they also have an `error.failures` property that holds
* information for all of the failures encountered.
*/
}
/**

@@ -37,9 +32,6 @@ * `StructError` objects are thrown (or returned) by Superstruct when its

branch: Array<any>;
failures: () => Iterable<StructFailure>;
failures: () => Array<StructFailure>;
[key: string]: any;
constructor(failure: StructFailure, iterable: Iterable<StructFailure>);
} /**
* A `StructContext` contains information about the current value being
* validated as well as helper functions for failures and recursive validating.
*/
constructor(failure: StructFailure, moreFailures: IterableIterator<StructFailure>);
}
/**

@@ -55,6 +47,4 @@ * A `StructContext` contains information about the current value being

fail: (props?: Partial<StructFailure>) => StructFailure;
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => Iterable<StructFailure>;
}; /**
* A `StructFailure` represents a single specific failure in validation.
*/
check: (value: any, struct: Struct<any> | Struct<never>, parent?: any, key?: string | number) => IterableIterator<StructFailure>;
};
/**

@@ -69,48 +59,32 @@ * A `StructFailure` represents a single specific failure in validation.

[key: string]: any;
}; /**
};
/**
* A `StructResult` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>;
/**
* A `StructResult` is returned from validation functions.
*/
type StructResult = boolean | Iterable<StructFailure>; /**
* A type utility to extract the type from a `Struct` class.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0];
/**
* A type utility to extract the type from a `Struct` class.
*/
type StructType<T extends Struct<any>> = Parameters<T["refiner"]>[0]; /**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T;
/**
* Assert that a value passes a `Struct`, throwing if it doesn't.
*/
declare function assert<T>(value: unknown, struct: Struct<T>): value is T; /**
* Coerce a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T;
/**
* Coerce a value with the coercion logic of `Struct` and validate it.
*/
declare function coerce<T>(value: unknown, struct: Struct<T>): T; /**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T;
/**
* Check if a value passes a `Struct`.
*/
declare function is<T>(value: unknown, struct: Struct<T>): value is T; /**
* Validate a value against a `Struct`, returning an error if invalid.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T]; /**
* Check a value against a `Struct`, returning an iterable of failures.
*/
declare function validate<T>(value: unknown, struct: Struct<T>, coercing?: boolean): [StructError, undefined] | [undefined, T];
/**
* Check a value against a `Struct`, returning an iterable of failures.
* Augment a `Struct` to add an additional coercion step to its input.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>;
/**
* Check a value against a `Struct`, returning an iterable of failures.
*/
/**
* Augment a `Struct` to add an additional coercion step to its input.
*/
declare function coercion<T>(struct: Struct<T>, coercer: Struct<T>["coercer"]): Struct<T>; /**
* Augment a struct to coerce a default value for missing values.

@@ -121,9 +95,4 @@ *

*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>;
/**
* Augment a struct to coerce a default value for missing values.
*
* Note: You must use `coerce(value, Struct)` on the value before validating it
* to have the value defaulted!
*/
declare function defaulted<T>(S: Struct<T>, fallback: any, strict?: true): Struct<T>; /**
* Coerce a value to mask its properties to only that defined in the struct.

@@ -133,18 +102,7 @@ */

[key: string]: any;
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>; /**
* Check if a value is a plain object.
*/
}, V extends Record<string, Struct<any>>>(S: Struct<T, V>): Struct<T>;
/**
* Check if a value is a plain object.
*/
/**
* Check if a value is a plain object.
*/
/**
* Augment a string or array struct to constrain its length to zero.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>; /**
* Augment a string or array struct to constrain its length to being between a
* minimum and maximum size.
*/
declare function empty<T extends string | any[]>(S: Struct<T>): Struct<T>;
/**

@@ -154,11 +112,7 @@ * Augment a string or array struct to constrain its length to being between a

*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>; /**
* Refine a string struct to match a specific regexp pattern.
*/
declare function length<T extends string | any[]>(S: Struct<T>, min: number, max: number): Struct<T>;
/**
* Refine a string struct to match a specific regexp pattern.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>; /**
* Augment a `Struct` to add an additional refinement to the validation.
*/
declare function pattern<T extends string>(S: Struct<T>, regexp: RegExp): Struct<T>;
/**

@@ -171,17 +125,7 @@ * Augment a `Struct` to add an additional refinement to the validation.

[K in keyof T]: Struct<T[K]>;
}; /**
* Convert a validation result to an iterable of failures.
*/
};
/**
* Convert a validation result to an iterable of failures.
*/
/**
* Convert a validation result to an iterable of failures.
*/
/**
* Validate any value.
*/
declare function any(): Struct<any>; /**
* Validate that an array of values of a specific type.
*/
declare function any(): Struct<any>;
/**

@@ -195,8 +139,3 @@ * Validate that an array of values of a specific type.

*/
declare function boolean(): Struct<boolean>; /**
* Validate that `Date` values.
*
* Note: this also ensures that the value is *not* an invalid `Date` object,
* which can occur when parsing a date fails but still returns a `Date`.
*/
declare function boolean(): Struct<boolean>;
/**

@@ -208,11 +147,7 @@ * Validate that `Date` values.

*/
declare function date(): Struct<Date>; /**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
declare function date(): Struct<Date>;
/**
* Validate that a value dynamically, determing which struct to use at runtime.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>; /**
* Validate that a value against a set of potential values.
*/
declare function dynamic<T>(fn: (value: unknown, ctx: StructContext) => Struct<T>): Struct<T>;
/**

@@ -226,5 +161,3 @@ * Validate that a value against a set of potential values.

*/
declare function func(): Struct<Function>; /**
* Validate that a value is an instance of a class.
*/
declare function func(): Struct<Function>;
/**

@@ -235,5 +168,3 @@ * Validate that a value is an instance of a class.

new (...args: any): any;
}>(Class: T): Struct<InstanceType<T>>; /**
* Validate that a value matches all of a set of structs.
*/
}>(Class: T): Struct<InstanceType<T>>;
/**

@@ -264,5 +195,3 @@ * Validate that a value matches all of a set of structs.

*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>; /**
* Validate that a value is a specific constant.
*/
declare function lazy<T>(fn: () => Struct<T>): Struct<T>;
/**

@@ -278,23 +207,15 @@ * Validate that a value is a specific constant.

*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>; /**
* Validate that a value always fails.
*/
declare function map<K, V>(Key: Struct<K>, Value: Struct<V>): Struct<Map<K, V>>;
/**
* Validate that a value always fails.
*/
declare function never(): Struct<never>; /**
* Augment a struct to make it accept `null` values.
*/
declare function never(): Struct<never>;
/**
* Augment a struct to make it accept `null` values.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>; /**
* Validate that a value is a number.
*/
declare function nullable<T>(S: Struct<T>): Struct<T | null>;
/**
* Validate that a value is a number.
*/
declare function number(): Struct<number>; /**
* Type helper to Flatten the Union of optional and required properties.
*/
declare function number(): Struct<number>;
/**

@@ -305,5 +226,3 @@ * Type helper to Flatten the Union of optional and required properties.

[K in keyof U]: U[K];
} : never; /**
* Type helper to extract the optional keys of an object
*/
} : never;
/**

@@ -314,5 +233,3 @@ * Type helper to extract the optional keys of an object

[K in keyof T]: undefined extends T[K] ? K : never;
}[keyof T]; /**
* Type helper to extract the required keys of an object
*/
}[keyof T];
/**

@@ -323,6 +240,3 @@ * Type helper to extract the required keys of an object

[K in keyof T]: undefined extends T[K] ? never : K;
}[keyof T]; /**
* Type helper to create optional properties when the property value can be
* undefined (ie. when `optional()` is used to define a type)
*/
}[keyof T];
/**

@@ -336,5 +250,3 @@ * Type helper to create optional properties when the property value can be

[K in OptionalKeys<T>]?: T[K];
}>; /**
* Validate that an object with specific entry values.
*/
}>;
/**

@@ -350,5 +262,3 @@ * Validate that an object with specific entry values.

*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>; /**
* Validate that a partial object with specific entry values.
*/
declare function optional<T>(S: Struct<T>): Struct<T | undefined>;
/**

@@ -359,6 +269,3 @@ * Validate that a partial object with specific entry values.

[K in keyof V]?: StructType<V[K]>;
}>; /**
* Validate that a value is a record with specific key and
* value entries.
*/
}>;
/**

@@ -368,23 +275,15 @@ * Validate that a value is a record with specific key and

*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>; /**
* Validate that a set of values matches a specific type.
*/
declare function record<K extends string | number, V>(Key: Struct<K>, Value: Struct<V>): Struct<Record<K, V>>;
/**
* Validate that a set of values matches a specific type.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>; /**
* Validate that a value is a string.
*/
declare function set<T>(Element: Struct<T>): Struct<Set<T>>;
/**
* Validate that a value is a string.
*/
declare function string(): Struct<string>; /**
* Define a `Struct` instance with a type and validation function.
*/
declare function string(): Struct<string>;
/**
* Define a `Struct` instance with a type and validation function.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>; /**
* Validate that a value is a tuple with entries of specific types.
*/
declare function struct<T>(name: string, validator: Struct<T>["validator"]): Struct<T, null>;
/**

@@ -416,5 +315,3 @@ * Validate that a value is a tuple with entries of specific types.

[K in keyof V]: StructType<V[K]>;
}>; /**
* Validate that a value is one of a set of types.
*/
}>;
/**

@@ -421,0 +318,0 @@ * Validate that a value is one of a set of types.

@@ -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=e||self).Superstruct={})}(this,(function(e){"use strict";function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var a=null!=arguments[n]?arguments[n]:{};n%2?r(Object(a),!0).forEach((function(r){t(e,r,a[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):r(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function o(e,t,r){return(o=c()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var a=new(Function.bind.apply(e,n));return r&&u(a,r.prototype),a}).apply(null,arguments)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return o(e,arguments,a(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)})(e)}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function s(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return f(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}function l(e,t){return!0===e?[]:!1===e?[t.fail()]:e}var p=regeneratorRuntime.mark(m),d=function(e){var t=e.type,r=e.schema,n=e.coercer,a=void 0===n?function(e){return e}:n,u=e.validator,c=void 0===u?function(){return[]}:u,o=e.refiner,i=void 0===o?function(){return[]}:o;this.type=t,this.schema=r,this.coercer=a,this.validator=c,this.refiner=i},y=function(e){var t,r;function n(t,r){var a,u=regeneratorRuntime.mark(p),c=t.path,o=t.value,i=t.type,f=t.branch,s=function(e,t){if(null==e)return{};var r,n,a={},u=Object.keys(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(t,["path","value","type","branch"]),l="Expected a value of type `"+i+"`"+(c.length?" for `"+c.join(".")+"`":"")+" but received `"+JSON.stringify(o)+"`.";function p(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t;case 2:return e.delegateYield(r,"t0",3);case 3:case"end":return e.stop()}}),u)}return(a=e.call(this,l)||this).value=o,Object.assign(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(a),s),a.type=i,a.path=c,a.branch=f,a.failures=p,a.stack=(new Error).stack,a.__proto__=n.prototype,a}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n}(i(TypeError));function b(e,t){var r=h(e,t);if(r[0])throw r[0]}function v(e,t){var r=t.coercer(e);return b(r,t),r}function h(e,t,r){void 0===r&&(r=!1),r&&(e=t.coercer(e));var n=m(e,t),a=n[0];return a?[new y(a,n),void 0]:[void 0,e]}function m(e,t,r,a){var u,c,o,i;return regeneratorRuntime.wrap((function(f){for(;;)switch(f.prev=f.next){case 0:if(void 0===r&&(r=[]),void 0===a&&(a=[]),u=t.type,c={value:e,type:u,branch:a,path:r,fail:function(t){return void 0===t&&(t={}),n({value:e,type:u,path:r,branch:[].concat(a,[e])},t)},check:function(e,t,n,u){return m(e,t,void 0!==n?[].concat(r,[u]):r,void 0!==n?[].concat(a,[n]):a)}},o=l(t.validator(e,c),c),!(i=o[0])){f.next=12;break}return f.next=9,i;case 9:return f.delegateYield(o,"t0",10);case 10:f.next=13;break;case 12:return f.delegateYield(l(t.refiner(e,c),c),"t1",13);case 13:case"end":return f.stop()}}),p)}function g(e,t){var r=e.coercer;return new d(n(n({},e),{},{coercer:function(e){return r(t(e))}}))}function k(e){if("[object Object]"!==Object.prototype.toString.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function x(e,t,r){var a=e.refiner;return new d(n(n({},e),{},{type:t,refiner:regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(l(a(t,n),n),"t0",1);case 1:return e.delegateYield(l(r(t,n),n),"t1",2);case 2:case"end":return e.stop()}}),e)}))}))}function w(){return j("never",(function(){return!1}))}function j(e,t){return new d({type:e,validator:t,schema:null})}function O(e){return"string"==typeof e?'"'+e.replace(/"/g,'"')+'"':""+e}function R(e){var t=Object.keys(e);return function(r){if("object"!=typeof r||null==r)return r;for(var n,a={},u=new Set(Object.keys(r)),c=s(t);!(n=c()).done;){var o=n.value;u.delete(o);var i=e[o],f=r[o];a[o]=v(f,i)}for(var l,p=s(u);!(l=p()).done;){var d=l.value;a[d]=r[d]}return a}}e.Struct=d,e.StructError=y,e.any=function(){return j("any",(function(){return!0}))},e.array=function(e){return new d({type:"Array<"+(e?e.type:"unknown")+">",schema:e,coercer:function(t){return e&&Array.isArray(t)?t.map((function(t){return v(t,e)})):t},validator:regeneratorRuntime.mark((function t(r,n){var a,u,c,o,i;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Array.isArray(r)){t.next=4;break}return t.next=3,n.fail();case 3:return t.abrupt("return");case 4:if(!e){t.next=11;break}a=s(r.entries());case 6:if((u=a()).done){t.next=11;break}return c=u.value,o=c[0],i=c[1],t.delegateYield(n.check(i,e,r,o),"t0",9);case 9:t.next=6;break;case 11:case"end":return t.stop()}}),t)}))})},e.assert=b,e.boolean=function(){return j("boolean",(function(e){return"boolean"==typeof e}))},e.coerce=v,e.coercion=g,e.date=function(){return j("Date",(function(e){return e instanceof Date&&!isNaN(e.getTime())}))},e.defaulted=function(e,t,r){return g(e,(function(e){var a="function"==typeof t?t():t;if(void 0===e)return a;if(!0!==r&&k(e)&&k(a)){var u=n({},e),c=!1;for(var o in a)void 0===u[o]&&(u[o]=a[o],c=!0);if(c)return u}return e}))},e.dynamic=function(e){return j("Dynamic<...>",(function(t,r){return r.check(t,e(t,r))}))},e.empty=function(e){return x(e,e.type+" & Empty",(function(e){return 0===e.length}))},e.enums=function(e){return j("Enum<"+e.map(O)+">",(function(t){return e.includes(t)}))},e.func=function(){return j("Function",(function(e){return"function"==typeof e}))},e.instance=function(e){return j("InstanceOf<"+e.name+">",(function(t){return t instanceof e}))},e.intersection=function(e){return j(e.map((function(e){return e.type})).join(" & "),regeneratorRuntime.mark((function t(r,n){var a,u,c;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=s(e);case 1:if((u=a()).done){t.next=6;break}return c=u.value,t.delegateYield(n.check(r,c),"t0",4);case 4:t.next=1;break;case 6:case"end":return t.stop()}}),t)})))},e.is=function(e,t){return!h(e,t)[0]},e.lazy=function(e){var t;return j("Lazy<...>",(function(r,n){return t||(t=e()),n.check(r,t)}))},e.length=function(e,t,r){return x(e,e.type+" & Length<"+t+","+r+">",(function(e){return t<e.length&&e.length<r}))},e.literal=function(e){return j("Literal<"+O(e)+">",(function(t){return t===e}))},e.map=function(e,t){return j("Map<"+e.type+","+t.type+">",regeneratorRuntime.mark((function r(n,a){var u,c,o,i,f;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(n instanceof Map){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:u=s(n.entries());case 5:if((c=u()).done){r.next=11;break}return o=c.value,i=o[0],f=o[1],r.delegateYield(a.check(i,e,n,i),"t0",8);case 8:return r.delegateYield(a.check(f,t,n,i),"t1",9);case 9:r.next=5;break;case 11:case"end":return r.stop()}}),r)})))},e.masked=function(e){return g(e,(function(t){if(!k(t))return t;var r={};for(var n in e.schema)r[n]=t[n];return r}))},e.never=w,e.nullable=function(e){return new d({type:e.type+" | null",schema:e.schema,validator:function(t,r){return null===t||r.check(t,e)}})},e.number=function(){return j("number",(function(e){return"number"==typeof e&&!isNaN(e)}))},e.object=function(e){var t=e?Object.keys(e):[],r=w();return new d({type:e?"Object<{"+t.join(",")+"}>":"Object",schema:e||null,coercer:e?R(e):function(e){return e},validator:regeneratorRuntime.mark((function n(a,u){var c,o,i,f,l,p,d,y,b,v;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("object"==typeof a&&null!=a){n.next=4;break}return n.next=3,u.fail();case 3:return n.abrupt("return");case 4:if(!e){n.next=22;break}c=new Set(Object.keys(a)),o=s(t);case 7:if((i=o()).done){n.next=15;break}return f=i.value,c.delete(f),l=e[f],p=a[f],n.delegateYield(u.check(p,l,a,f),"t0",13);case 13:n.next=7;break;case 15:d=s(c);case 16:if((y=d()).done){n.next=22;break}return b=y.value,v=a[b],n.delegateYield(u.check(v,r,a,b),"t1",20);case 20:n.next=16;break;case 22:case"end":return n.stop()}}),n)}))})},e.optional=function(e){return new d({type:e.type+"?",schema:e.schema,validator:function(t,r){return void 0===t||r.check(t,e)}})},e.partial=function(e){e instanceof d&&(e=e.schema);var t=Object.keys(e),r=w();return new d({type:"Partial<{"+t.join(",")+"}>",schema:e,coercer:R(e),validator:regeneratorRuntime.mark((function n(a,u){var c,o,i,f,l,p,d,y,b,v;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("object"==typeof a&&null!=a){n.next=4;break}return n.next=3,u.fail();case 3:return n.abrupt("return");case 4:c=new Set(Object.keys(a)),o=s(t);case 6:if((i=o()).done){n.next=16;break}if(f=i.value,c.delete(f),f in a){n.next=11;break}return n.abrupt("continue",14);case 11:return l=e[f],p=a[f],n.delegateYield(u.check(p,l,a,f),"t0",14);case 14:n.next=6;break;case 16:d=s(c);case 17:if((y=d()).done){n.next=23;break}return b=y.value,v=a[b],n.delegateYield(u.check(v,r,a,b),"t1",21);case 21:n.next=17;break;case 23:case"end":return n.stop()}}),n)}))})},e.pattern=function(e,t){return x(e,e.type+" & Pattern<"+t.source+">",(function(e){return t.test(e)}))},e.record=function(e,t){return j("Record<"+e.type+","+t.type+">",regeneratorRuntime.mark((function r(n,a){var u,c;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("object"==typeof n&&null!=n){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:r.t0=regeneratorRuntime.keys(n);case 5:if((r.t1=r.t0()).done){r.next=12;break}return u=r.t1.value,c=n[u],r.delegateYield(a.check(u,e,n,u),"t2",9);case 9:return r.delegateYield(a.check(c,t,n,u),"t3",10);case 10:r.next=5;break;case 12:case"end":return r.stop()}}),r)})))},e.refinement=x,e.set=function(e){return j("Set<"+e.type+">",(function(t,r){if(!(t instanceof Set))return!1;for(var n,a=s(t);!(n=a()).done;){var u=n.value;if(r.check(u,e)[0])return!1}return!0}))},e.string=function(){return j("string",(function(e){return"string"==typeof e}))},e.struct=j,e.tuple=function(e){var t=w();return j("["+e.map((function(e){return e.type})).join(",")+"]",regeneratorRuntime.mark((function r(n,a){var u,c,o,i,f,l,p,d;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(Array.isArray(n)){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:u=s(e.entries());case 5:if((c=u()).done){r.next=11;break}return o=c.value,i=o[0],f=o[1],l=n[i],r.delegateYield(a.check(l,f,n,i),"t0",9);case 9:r.next=5;break;case 11:if(!(n.length>e.length)){r.next=15;break}return p=e.length,d=n[p],r.delegateYield(a.check(d,t,n,p),"t1",15);case 15:case"end":return r.stop()}}),r)})))},e.type=function(e){var t=Object.keys(e);return j("Type<{"+t.join(",")+"}>",regeneratorRuntime.mark((function r(n,a){var u,c,o,i,f;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("object"==typeof n&&null!=n){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:u=s(t);case 5:if((c=u()).done){r.next=12;break}return o=c.value,i=e[o],f=n[o],r.delegateYield(a.check(f,i,n,o),"t0",10);case 10:r.next=5;break;case 12:case"end":return r.stop()}}),r)})))},e.union=function(e){return j(""+e.map((function(e){return e.type})).join(" | "),regeneratorRuntime.mark((function t(r,n){var a,u,c,o;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=s(e);case 1:if((u=a()).done){t.next=8;break}if(c=u.value,o=n.check(r,c),0!==o.slice(0).length){t.next=6;break}return t.abrupt("return");case 6:t.next=1;break;case 8:return t.next=10,n.fail();case 10:case"end":return t.stop()}}),t)})))},e.validate=h,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";function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function r(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function n(e){for(var n=1;n<arguments.length;n++){var a=null!=arguments[n]?arguments[n]:{};n%2?r(Object(a),!0).forEach((function(r){t(e,r,a[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):r(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function a(e){return(a=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function o(e,t,r){return(o=c()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var a=new(Function.bind.apply(e,n));return r&&u(a,r.prototype),a}).apply(null,arguments)}function i(e){var t="function"==typeof Map?new Map:void 0;return(i=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return o(e,arguments,a(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),u(n,e)})(e)}function f(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function s(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return f(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(e,t):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=e[Symbol.iterator]()).next.bind(r)}var l=regeneratorRuntime.mark(p);function p(e,t){return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(!0!==e){r.next=3;break}r.next=9;break;case 3:if(!1!==e){r.next=8;break}return r.next=6,t.fail();case 6:r.next=9;break;case 8:return r.delegateYield(e,"t0",9);case 9:case"end":return r.stop()}}),l)}function d(e){var t=e.next(),r=t.done,n=t.value;return r?void 0:n}var b=regeneratorRuntime.mark(k),y=function(e){var t=e.type,r=e.schema,n=e.coercer,a=void 0===n?function(e){return e}:n,u=e.validator,c=void 0===u?function(){return[]}:u,o=e.refiner,i=void 0===o?function(){return[]}:o;this.type=t,this.schema=r,this.coercer=a,this.validator=c,this.refiner=i},v=function(e){var t,r;function n(t,r){var a,u,c=t.path,o=t.value,i=t.type,f=t.branch,s=function(e,t){if(null==e)return{};var r,n,a={},u=Object.keys(e);for(n=0;n<u.length;n++)r=u[n],t.indexOf(r)>=0||(a[r]=e[r]);return a}(t,["path","value","type","branch"]),l="Expected a value of type `"+i+"`"+(c.length?" for `"+c.join(".")+"`":"")+" but received `"+JSON.stringify(o)+"`.";return(a=e.call(this,l)||this).value=o,Object.assign(function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(a),s),a.type=i,a.path=c,a.branch=f,a.failures=function(){return u||(u=[t].concat(r)),u},a.stack=(new Error).stack,a.__proto__=n.prototype,a}return r=e,(t=n).prototype=Object.create(r.prototype),t.prototype.constructor=t,t.__proto__=r,n}(i(TypeError));function h(e,t){var r=g(e,t);if(r[0])throw r[0]}function m(e,t){var r=t.coercer(e);return h(r,t),r}function g(e,t,r){void 0===r&&(r=!1),r&&(e=t.coercer(e));var n=k(e,t),a=d(n);return a?[new v(a,n),void 0]:[void 0,e]}function k(e,t,r,a){var u,c,o,i;return regeneratorRuntime.wrap((function(f){for(;;)switch(f.prev=f.next){case 0:if(void 0===r&&(r=[]),void 0===a&&(a=[]),u=t.type,c={value:e,type:u,branch:a,path:r,fail:function(t){return void 0===t&&(t={}),n({value:e,type:u,path:r,branch:[].concat(a,[e])},t)},check:function(e,t,n,u){return k(e,t,void 0!==n?[].concat(r,[u]):r,void 0!==n?[].concat(a,[n]):a)}},o=p(t.validator(e,c),c),!(i=d(o))){f.next=12;break}return f.next=9,i;case 9:return f.delegateYield(o,"t0",10);case 10:f.next=13;break;case 12:return f.delegateYield(p(t.refiner(e,c),c),"t1",13);case 13:case"end":return f.stop()}}),b)}function x(e,t){var r=e.coercer;return new y(n(n({},e),{},{coercer:function(e){return r(t(e))}}))}function w(e){if("[object Object]"!==Object.prototype.toString.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function j(e,t,r){var a=e.refiner;return new y(n(n({},e),{},{type:t,refiner:regeneratorRuntime.mark((function e(t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(p(a(t,n),n),"t0",1);case 1:return e.delegateYield(p(r(t,n),n),"t1",2);case 2:case"end":return e.stop()}}),e)}))}))}function O(){return R("never",(function(){return!1}))}function R(e,t){return new y({type:e,validator:t,schema:null})}function S(e){return"string"==typeof e?'"'+e.replace(/"/g,'"')+'"':""+e}function P(e){var t=Object.keys(e);return function(r){if("object"!=typeof r||null==r)return r;for(var n,a={},u=new Set(Object.keys(r)),c=s(t);!(n=c()).done;){var o=n.value;u.delete(o);var i=e[o],f=r[o];a[o]=m(f,i)}for(var l,p=s(u);!(l=p()).done;){var d=l.value;a[d]=r[d]}return a}}e.Struct=y,e.StructError=v,e.any=function(){return R("any",(function(){return!0}))},e.array=function(e){return new y({type:"Array<"+(e?e.type:"unknown")+">",schema:e,coercer:function(t){return e&&Array.isArray(t)?t.map((function(t){return m(t,e)})):t},validator:regeneratorRuntime.mark((function t(r,n){var a,u,c,o,i;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(Array.isArray(r)){t.next=4;break}return t.next=3,n.fail();case 3:return t.abrupt("return");case 4:if(!e){t.next=11;break}a=s(r.entries());case 6:if((u=a()).done){t.next=11;break}return c=u.value,o=c[0],i=c[1],t.delegateYield(n.check(i,e,r,o),"t0",9);case 9:t.next=6;break;case 11:case"end":return t.stop()}}),t)}))})},e.assert=h,e.boolean=function(){return R("boolean",(function(e){return"boolean"==typeof e}))},e.coerce=m,e.coercion=x,e.date=function(){return R("Date",(function(e){return e instanceof Date&&!isNaN(e.getTime())}))},e.defaulted=function(e,t,r){return x(e,(function(e){var a="function"==typeof t?t():t;if(void 0===e)return a;if(!0!==r&&w(e)&&w(a)){var u=n({},e),c=!1;for(var o in a)void 0===u[o]&&(u[o]=a[o],c=!0);if(c)return u}return e}))},e.dynamic=function(e){return R("Dynamic<...>",(function(t,r){return r.check(t,e(t,r))}))},e.empty=function(e){return j(e,e.type+" & Empty",(function(e){return 0===e.length}))},e.enums=function(e){return R("Enum<"+e.map(S)+">",(function(t){return e.includes(t)}))},e.func=function(){return R("Function",(function(e){return"function"==typeof e}))},e.instance=function(e){return R("InstanceOf<"+e.name+">",(function(t){return t instanceof e}))},e.intersection=function(e){return R(e.map((function(e){return e.type})).join(" & "),regeneratorRuntime.mark((function t(r,n){var a,u,c;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=s(e);case 1:if((u=a()).done){t.next=6;break}return c=u.value,t.delegateYield(n.check(r,c),"t0",4);case 4:t.next=1;break;case 6:case"end":return t.stop()}}),t)})))},e.is=function(e,t){return!g(e,t)[0]},e.lazy=function(e){var t;return R("Lazy<...>",(function(r,n){return t||(t=e()),n.check(r,t)}))},e.length=function(e,t,r){return j(e,e.type+" & Length<"+t+","+r+">",(function(e){return t<e.length&&e.length<r}))},e.literal=function(e){return R("Literal<"+S(e)+">",(function(t){return t===e}))},e.map=function(e,t){return R("Map<"+e.type+","+t.type+">",regeneratorRuntime.mark((function r(n,a){var u,c,o,i,f;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(n instanceof Map){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:u=s(n.entries());case 5:if((c=u()).done){r.next=11;break}return o=c.value,i=o[0],f=o[1],r.delegateYield(a.check(i,e,n,i),"t0",8);case 8:return r.delegateYield(a.check(f,t,n,i),"t1",9);case 9:r.next=5;break;case 11:case"end":return r.stop()}}),r)})))},e.masked=function(e){return x(e,(function(t){if(!w(t))return t;var r={};for(var n in e.schema)r[n]=t[n];return r}))},e.never=O,e.nullable=function(e){return new y({type:e.type+" | null",schema:e.schema,validator:function(t,r){return null===t||r.check(t,e)}})},e.number=function(){return R("number",(function(e){return"number"==typeof e&&!isNaN(e)}))},e.object=function(e){var t=e?Object.keys(e):[],r=O();return new y({type:e?"Object<{"+t.join(",")+"}>":"Object",schema:e||null,coercer:e?P(e):function(e){return e},validator:regeneratorRuntime.mark((function n(a,u){var c,o,i,f,l,p,d,b,y,v;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("object"==typeof a&&null!=a){n.next=4;break}return n.next=3,u.fail();case 3:return n.abrupt("return");case 4:if(!e){n.next=22;break}c=new Set(Object.keys(a)),o=s(t);case 7:if((i=o()).done){n.next=15;break}return f=i.value,c.delete(f),l=e[f],p=a[f],n.delegateYield(u.check(p,l,a,f),"t0",13);case 13:n.next=7;break;case 15:d=s(c);case 16:if((b=d()).done){n.next=22;break}return y=b.value,v=a[y],n.delegateYield(u.check(v,r,a,y),"t1",20);case 20:n.next=16;break;case 22:case"end":return n.stop()}}),n)}))})},e.optional=function(e){return new y({type:e.type+"?",schema:e.schema,validator:function(t,r){return void 0===t||r.check(t,e)}})},e.partial=function(e){e instanceof y&&(e=e.schema);var t=Object.keys(e),r=O();return new y({type:"Partial<{"+t.join(",")+"}>",schema:e,coercer:P(e),validator:regeneratorRuntime.mark((function n(a,u){var c,o,i,f,l,p,d,b,y,v;return regeneratorRuntime.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if("object"==typeof a&&null!=a){n.next=4;break}return n.next=3,u.fail();case 3:return n.abrupt("return");case 4:c=new Set(Object.keys(a)),o=s(t);case 6:if((i=o()).done){n.next=16;break}if(f=i.value,c.delete(f),f in a){n.next=11;break}return n.abrupt("continue",14);case 11:return l=e[f],p=a[f],n.delegateYield(u.check(p,l,a,f),"t0",14);case 14:n.next=6;break;case 16:d=s(c);case 17:if((b=d()).done){n.next=23;break}return y=b.value,v=a[y],n.delegateYield(u.check(v,r,a,y),"t1",21);case 21:n.next=17;break;case 23:case"end":return n.stop()}}),n)}))})},e.pattern=function(e,t){return j(e,e.type+" & Pattern<"+t.source+">",(function(e){return t.test(e)}))},e.record=function(e,t){return R("Record<"+e.type+","+t.type+">",regeneratorRuntime.mark((function r(n,a){var u,c;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("object"==typeof n&&null!=n){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:r.t0=regeneratorRuntime.keys(n);case 5:if((r.t1=r.t0()).done){r.next=12;break}return u=r.t1.value,c=n[u],r.delegateYield(a.check(u,e,n,u),"t2",9);case 9:return r.delegateYield(a.check(c,t,n,u),"t3",10);case 10:r.next=5;break;case 12:case"end":return r.stop()}}),r)})))},e.refinement=j,e.set=function(e){return R("Set<"+e.type+">",(function(t,r){if(!(t instanceof Set))return!1;for(var n,a=s(t);!(n=a()).done;){var u=n.value;if(r.check(u,e)[0])return!1}return!0}))},e.string=function(){return R("string",(function(e){return"string"==typeof e}))},e.struct=R,e.tuple=function(e){var t=O();return R("["+e.map((function(e){return e.type})).join(",")+"]",regeneratorRuntime.mark((function r(n,a){var u,c,o,i,f,l,p,d;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(Array.isArray(n)){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:u=s(e.entries());case 5:if((c=u()).done){r.next=11;break}return o=c.value,i=o[0],f=o[1],l=n[i],r.delegateYield(a.check(l,f,n,i),"t0",9);case 9:r.next=5;break;case 11:if(!(n.length>e.length)){r.next=15;break}return p=e.length,d=n[p],r.delegateYield(a.check(d,t,n,p),"t1",15);case 15:case"end":return r.stop()}}),r)})))},e.type=function(e){var t=Object.keys(e);return R("Type<{"+t.join(",")+"}>",regeneratorRuntime.mark((function r(n,a){var u,c,o,i,f;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("object"==typeof n&&null!=n){r.next=4;break}return r.next=3,a.fail();case 3:return r.abrupt("return");case 4:u=s(t);case 5:if((c=u()).done){r.next=12;break}return o=c.value,i=e[o],f=n[o],r.delegateYield(a.check(f,i,n,o),"t0",10);case 10:r.next=5;break;case 12:case"end":return r.stop()}}),r)})))},e.union=function(e){return R(""+e.map((function(e){return e.type})).join(" | "),regeneratorRuntime.mark((function t(r,n){var a,u,c,o;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a=s(e);case 1:if((u=a()).done){t.next=8;break}if(c=u.value,o=n.check(r,c),0!==o.slice(0).length){t.next=6;break}return t.abrupt("return");case 6:t.next=1;break;case 8:return t.next=10,n.fail();case 10:case"end":return t.stop()}}),t)})))},e.validate=g,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

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