import { Maybe, Guard, Convert, CastSettings } from "./internal.js"; import { Collection, Primitive, PrimitiveValue, SimpleType, SimpleTypeOf, Struct } from "./types.js"; declare type CastSome[]> = T extends Guard[] ? Guard ? R : never> : T extends Cast[] ? Cast ? R : never> : never; export declare type TCastAll> = { [I in keyof T]: T[I] extends Cast ? V : never; }; export declare type TCastMap = T extends SimpleType ? SimpleTypeOf : T extends Cast ? R : T extends { [k in keyof T]: any; } ? { [k in keyof T]: TCastMap; } : unknown; export declare type Casted = T extends Cast ? R : unknown; export declare class Cast { private readonly _cast; protected static readonly castError: Error; protected static readonly defaults: CastSettings; constructor(_cast: (value: unknown, settings: CastSettings) => Maybe); private static get build(); static readonly asUnknown: Cast; static readonly asNever: Cast; private static unwrapArray; private static wrapArray; static lazy(fun: (s: CastSettings) => Cast): Cast; cast(value: unknown): Maybe; cast(value: unknown, settings: CastSettings): Maybe; config(config: Partial): Cast; static just(value: T): Cast; static nothing(error?: Error): Cast; static try(get: () => T): Cast; parse(json: string): Maybe; bind(next: (t: T, s: CastSettings) => Cast): Cast; compose(next: Cast): Cast; or(right: Convert): Convert; or(right: Cast): Cast; /** * Unions a list of casts by combining them with the `or` operator. * @param options An array of casts. * @returns The union of the given casts. */ static some[]>(...options: T): CastSome; /** * Creates a cast that outputs a collection by applying each cast in the given collection to the input value. * @param casts A collection of casts. * @returns A cast that outputs a collection of results, or nothing if any cast fails. */ static all>(casts: T): Convert>; static all>(casts: T): Cast>; /** * Creates a convert that outputs an array containing the successful results of applying each cast in the given collection to the input value. * @param casts An array of casts. * @returns A convert that outputs an array of successfully results */ static any(casts: Cast[]): Convert; if(condition: (input: T) => unknown): Cast; and(guard: Guard): Cast; merge(this: Cast<{}>, cast: Cast): Cast; map(next: (t: T) => R): Cast; else(other: R): Convert; elseThrow(getError?: (error: Error) => Error): Convert; get toMaybe(): Convert>; static get asPrimitiveValue(): Cast; static get asString(): Cast; static get asNumber(): Cast; static get asFinite(): Cast; static get asInteger(): Cast; static get asBigInt(): Cast; static get asBoolean(): Cast; static get asDate(): Cast; static get asArray(): Cast; static asConst(value: T): Cast; static asEnum(...options: T): Cast; private static makeCollectionOf; static asArrayOf(cast: Cast): Cast; static asStructOf(cast: Cast): Cast>; private static makeCollectionLike; /** * Given an object or tuple of casts, it produces a cast that outputs an object or tuple having the same shape as the given casts. * @param casts an object or tuple of casts * @returns a cast that produces an object or tuple matching the shape of the given casts */ static asCollectionLike>(casts: T): Cast>; /** * Produces a cast that filters out values from the input that could not be casted by the given cast. * @param cast the cast to use for filtering * @returns a cast that filters out values that could not be casted by the given cast */ static asArrayWhere(cast: Cast): Cast; /** * Creates a `Cast` based on a sample value. * @param alt a sample value * @returns a `Cast` based on the given sample value */ static as(alt: T): Cast>; get asPrimitiveValue(): Cast; get asString(): Cast; get asNumber(): Cast; get asFinite(): Cast; get asInteger(): Cast; get asBigInt(): Cast; get asBoolean(): Cast; get asDate(): Cast; get asArray(): Cast; asConst(value: T): Cast; asEnum(...options: T): Cast; asArrayOf(cast: Cast): Cast; asStructOf(cast: Cast): Cast>; asCollectionLike>(casts: T): Cast>; asArrayWhere(cast: Cast): Cast; as(alt: T): Cast>; } export {};