tiny-decoders
Advanced tools
Comparing version 11.0.0 to 12.0.0
@@ -35,2 +35,6 @@ export type Decoder<T, U = unknown> = (value: U) => T; | ||
optional?: boolean | undefined; | ||
tag?: { | ||
decoded: string; | ||
encoded: string; | ||
} | undefined; | ||
}; | ||
@@ -51,9 +55,49 @@ type FieldsMapping = Record<string, Decoder<any> | Field<any, FieldMeta>>; | ||
}): Decoder<InferFields<Mapping>>; | ||
export declare function field<Decoded, const Meta extends FieldMeta>(decoder: Decoder<Decoded>, meta: Meta): Field<Decoded, Meta>; | ||
type Values<T> = T[keyof T]; | ||
export declare function fieldsUnion<T extends Record<string, Decoder<unknown>>>(key: string, mapping: keyof T extends string ? keyof T extends never ? "fieldsUnion must have at least one member" : T : { | ||
[P in keyof T]: P extends number ? "fieldsUnion keys must be strings, not numbers" : T[P]; | ||
}): Decoder<Expand<Values<{ | ||
[P in keyof T]: T[P] extends Decoder<infer U, infer _> ? U : never; | ||
}>>>; | ||
export declare function field<Decoded, const Meta extends Omit<FieldMeta, "tag">>(decoder: Decoder<Decoded>, meta: Meta): Field<Decoded, Meta>; | ||
type InferFieldsUnion<MappingsUnion extends FieldsMapping> = MappingsUnion extends any ? InferFields<MappingsUnion> : never; | ||
type Variant<DecodedCommonField extends number | string | symbol> = Record<DecodedCommonField, Field<any, { | ||
tag: { | ||
decoded: string; | ||
encoded: string; | ||
}; | ||
}>> & Record<string, Decoder<any> | Field<any, FieldMeta>>; | ||
export declare function fieldsUnion<const DecodedCommonField extends keyof Variants[number], Variants extends readonly [ | ||
Variant<DecodedCommonField>, | ||
...ReadonlyArray<Variant<DecodedCommonField>> | ||
]>(decodedCommonField: DecodedCommonField, variants: Variants, { exact }?: { | ||
exact?: "allow extra" | "throw"; | ||
}): Decoder<InferFieldsUnion<Variants[number]>>; | ||
export declare function tag<const Decoded extends string>(decoded: Decoded): Field<Decoded, { | ||
tag: { | ||
decoded: string; | ||
encoded: string; | ||
}; | ||
}>; | ||
export declare function tag<const Decoded extends string, const Encoded extends string>(decoded: Decoded, options: { | ||
renameTagFrom: Encoded; | ||
}): Field<Decoded, { | ||
tag: { | ||
decoded: string; | ||
encoded: string; | ||
}; | ||
}>; | ||
export declare function tag<const Decoded extends string, const EncodedFieldName extends string>(decoded: Decoded, options: { | ||
renameFieldFrom: EncodedFieldName; | ||
}): Field<Decoded, { | ||
renameFrom: EncodedFieldName; | ||
tag: { | ||
decoded: string; | ||
encoded: string; | ||
}; | ||
}>; | ||
export declare function tag<const Decoded extends string, const Encoded extends string, const EncodedFieldName extends string>(decoded: Decoded, options: { | ||
renameTagFrom: Encoded; | ||
renameFieldFrom: EncodedFieldName; | ||
}): Field<Decoded, { | ||
renameFrom: EncodedFieldName; | ||
tag: { | ||
decoded: string; | ||
encoded: string; | ||
}; | ||
}>; | ||
export declare function tuple<T extends Array<unknown>>(mapping: [...{ | ||
@@ -121,2 +165,6 @@ [P in keyof T]: Decoder<T[P]>; | ||
} | { | ||
tag: "wrong tag"; | ||
expected: string; | ||
got: string; | ||
} | { | ||
tag: "array"; | ||
@@ -123,0 +171,0 @@ got: unknown; |
{ | ||
"name": "tiny-decoders", | ||
"version": "11.0.0", | ||
"version": "12.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
49163
1297