tiny-decoders
Advanced tools
Comparing version 15.1.0 to 16.0.0
@@ -1,9 +0,18 @@ | ||
export type Decoder<T, U = unknown> = (value: U) => T; | ||
export type Infer<T extends Decoder<any>> = ReturnType<T>; | ||
export type Decoder<T, U = unknown> = (value: U) => DecoderResult<T>; | ||
export type DecoderResult<T> = { | ||
tag: "DecoderError"; | ||
error: DecoderError; | ||
} | { | ||
tag: "Valid"; | ||
value: T; | ||
}; | ||
export type Infer<T extends Decoder<any>> = Extract<ReturnType<T>, { | ||
tag: "Valid"; | ||
}>["value"]; | ||
type Expand<T> = T extends infer O ? { | ||
[K in keyof O]: O[K]; | ||
} : never; | ||
export declare function boolean(value: unknown): boolean; | ||
export declare function number(value: unknown): number; | ||
export declare function string(value: unknown): string; | ||
export declare function boolean(value: unknown): DecoderResult<boolean>; | ||
export declare function number(value: unknown): DecoderResult<number>; | ||
export declare function string(value: unknown): DecoderResult<string>; | ||
export declare function stringUnion<const T extends readonly [string, ...Array<string>]>(variants: T): Decoder<T[number]>; | ||
@@ -116,4 +125,8 @@ export declare function array<T>(decoder: Decoder<T>): Decoder<Array<T>>; | ||
export declare function nullable<T, U>(decoder: Decoder<T>, defaultValue: U): Decoder<T | U>; | ||
export declare function chain<T, U>(decoder: Decoder<T>, next: Decoder<U, T>): Decoder<U>; | ||
export type DecoderErrorVariant = { | ||
export declare function map<T, U>(decoder: Decoder<T>, transform: (value: T) => U): Decoder<U>; | ||
export declare function flatMap<T, U>(decoder: Decoder<T>, transform: (value: T) => DecoderResult<U>): Decoder<U>; | ||
export type DecoderError = { | ||
path: Array<number | string>; | ||
orExpected?: "null or undefined" | "null" | "undefined"; | ||
} & ({ | ||
tag: "custom"; | ||
@@ -165,20 +178,4 @@ message: string; | ||
got: unknown; | ||
}; | ||
type Key = number | string; | ||
export declare class DecoderError extends TypeError { | ||
path: Array<Key>; | ||
variant: DecoderErrorVariant; | ||
nullable: boolean; | ||
optional: boolean; | ||
constructor({ key, ...params }: { | ||
message: string; | ||
value: unknown; | ||
key?: Key | undefined; | ||
} | (DecoderErrorVariant & { | ||
key?: Key | undefined; | ||
})); | ||
static MISSING_VALUE: symbol; | ||
static at(error: unknown, key?: Key): DecoderError; | ||
format(options?: ReprOptions): string; | ||
} | ||
}); | ||
export declare function format(error: DecoderError, options?: ReprOptions): string; | ||
export type ReprOptions = { | ||
@@ -185,0 +182,0 @@ depth?: number | undefined; |
{ | ||
"name": "tiny-decoders", | ||
"version": "15.1.0", | ||
"version": "16.0.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "author": "Simon Lydell", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53644
1417