Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tiny-decoders

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-decoders - npm Package Compare versions

Comparing version 15.1.0 to 16.0.0

47

index.d.ts

@@ -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

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