import { Struct, Infer, Result, Context, Describe } from './struct'; import { Failure } from './error'; /** * Check if a value is a plain object. */ export declare function isObject(x: unknown): x is object; /** * Check if a value is a plain object. */ export declare function isPlainObject(x: unknown): x is { [key: string]: any; }; /** * Return a value as a printable string. */ export declare function print(value: any): string; /** * Shifts (removes and returns) the first value from the `input` iterator. * Like `Array.prototype.shift()` but for an `Iterator`. */ export declare function shiftIterator(input: Iterator): T | undefined; /** * Convert a single validation result to a failure. */ export declare function toFailure(result: string | boolean | Partial, context: Context, struct: Struct, value: any): Failure | undefined; /** * Convert a validation result to an iterable of failures. */ export declare function toFailures(result: Result, context: Context, struct: Struct, value: any): IterableIterator; /** * Check a value against a struct, traversing deeply into nested values, and * returning an iterator of failures or success. */ export declare function run(value: unknown, struct: Struct, options?: { path?: any[]; branch?: any[]; coerce?: boolean; mask?: boolean; }): IterableIterator<[Failure, undefined] | [undefined, T]>; /** * Convert a union of type to an intersection. */ export declare type UnionToIntersection = (U extends any ? (arg: U) => any : never) extends (arg: infer I) => void ? I : never; /** * Assign properties from one type to another, overwriting existing. */ export declare type Assign = Simplify>; /** * A schema for enum structs. */ export declare type EnumSchema = { [K in NonNullable]: K; }; /** * Check if a type is a match for another whilst treating overlapping * unions as a match. */ export declare type IsMatch = T extends G ? (G extends T ? T : never) : never; /** * Check if a type is an exact match. */ export declare type IsExactMatch = (() => G extends T ? 1 : 2) extends () => G extends U ? 1 : 2 ? T : never; /** * Check if a type is a record type. */ export declare type IsRecord = T extends object ? string extends keyof T ? T : never : never; /** * Check if a type is a tuple. */ export declare type IsTuple = T extends [any] ? T : T extends [any, any] ? T : T extends [any, any, any] ? T : T extends [any, any, any, any] ? T : T extends [any, any, any, any, any] ? T : never; /** * Check if a type is a union. */ export declare type IsUnion = (T extends any ? (U extends T ? false : true) : false) extends false ? never : T; /** * A schema for object structs. */ export declare type ObjectSchema = Record>; /** * Infer a type from an object struct schema. */ export declare type ObjectType = Simplify; }>>; /** * Omit properties from a type that extend from a specific type. */ export declare type OmitBy = Omit ? K : never; }[keyof T]>; /** * Normalize properties of a type that allow `undefined` to make them optional. */ export declare type Optionalize = OmitBy & Partial>; /** * Transform an object schema type to represent a partial. */ export declare type PartialObjectSchema = { [K in keyof S]: Struct | undefined>; }; /** * Pick properties from a type that extend from a specific type. */ export declare type PickBy = Pick ? K : never; }[keyof T]>; /** * Simplifies a type definition to its most basic representation. */ export declare type Simplify = T extends any[] | Date ? T : { [K in keyof T]: T[K]; } & {}; export declare type If = B extends true ? Then : Else; /** * A schema for any type of struct. */ export declare type StructSchema = [T] extends [string | undefined] ? [T] extends [IsMatch] ? null : [T] extends [IsUnion] ? EnumSchema : T : [T] extends [number | undefined] ? [T] extends [IsMatch] ? null : [T] extends [IsUnion] ? EnumSchema : T : [T] extends [boolean] ? [T] extends [IsExactMatch] ? null : T : T extends bigint | symbol | undefined | null | Function | Date | Error | RegExp | Map | WeakMap | Set | WeakSet | Promise ? null : T extends Array ? T extends IsTuple ? null : Struct : T extends object ? T extends IsRecord ? null : { [K in keyof T]: Describe; } : null; /** * A schema for tuple structs. */ export declare type TupleSchema = { [K in keyof T]: Struct; }; /** * Shorthand type for matching any `Struct`. */ export declare type AnyStruct = Struct; /** * 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 = Length extends Length ? number extends Length ? Tuple : _InferTuple : never; declare type _InferTuple = Index extends Length ? Accumulated : _InferTuple]>; export {}; //# sourceMappingURL=utils.d.ts.map