import { ValueOf } from 'ts-essentials'; /** Convenience empty record type. */ export type Empty = Record; /** Checks whether two objects are deeply equal. */ export declare function isDeepEqual(arg1: unknown, arg2: unknown): boolean; /** Wraps an object, adding a freeze method. */ export declare function freezable(val: O, opts?: FreezableOptions): [O, Freezer]; export interface FreezableOptions { readonly allowList?: ReadonlyArray>; readonly onFreeze?: (obj: O) => void; } export type Freezer = () => void; export type TrimUndefined = T extends [] ? [] : T extends [infer H, ...infer R] ? TrimUndefined extends [] ? H extends undefined ? [] : [H] : T : never; /** ADT visitor type. */ export type Visit = (o: O, ...rest: TrimUndefined<[C]>) => V; /** * Generates a discriminated union type. * * Sample usage: * * ``` * type D = KindAmong<{ * fooN: {readonly n: number}; * barV: {readonly v: string}; * }>; * const d: D = {kind: 'fooN', n: 123}; * ``` */ export type KindAmong = ValueOf>; /** Convenience type representing a single discriminating branch. */ export interface HasKind { readonly kind: K; } type BranchValues = { [K in keyof O & string]: ValueOf> & HasKind; }; /** Asserts that the object matches the given branch. */ export declare function assertKind(obj: O, kind: K): asserts obj is O & HasKind; /** `KindAmong` visitor. */ export type WalkerFor = { readonly [K in O['kind'] as `on${Capitalize}`]: (o: O & HasKind, c: C) => V; }; /** Returns a visitor for `KindAmong` ADTs. */ export declare function walkWith(walker: WalkerFor): Visit; /** * Generates a "oneof" union type. This is similar to a discriminated union type * but the values remain nested within their separate fields. * * Sample usage: * * ``` * type J = JustOne<{ * fooN: {readonly n: number}; * barV: {readonly v: string}; * }>; * const j: J = {just: 'fooN', fooN: {n: 123}}; // Note the `fooN` key here. * ``` */ export type JustOne = ValueOf>; type Branches = { [B in keyof O]: Branch & { readonly [N in K]: B; }; }; type Branch = { readonly [B2 in keyof O as B2 extends B1 ? B2 : never]: O[B2]; }; /** * Convenience type filtering on a particular `just` value. This can be useful * to narrow `JustOne` types, for example: * * ``` * type One = JustOne<{foo: Foo; bar: Bar; baz: Baz}>; // foo, bar, or baz. * type Two = Exclude>; // bar or baz. * ``` */ export interface HasJust { readonly just: J; } /** Convenience type representing the discriminating branch of `JustOne`. */ export type IsJust = HasJust & { readonly [K in J]: V; }; /** Extracts a branch from `JustOne`, narrowing the type appropriately. */ export declare function getJust(obj: O, just: J): (J extends keyof O ? O[J] : never) | undefined; /** Wraps the argument into a `JustOne` compatible value. */ export declare function just(j: J, val: V): JustOne<{ [K in J]: V; }>; /** Asserts that the object matches the given branch. */ export declare function assertJust(obj: O, just: J): asserts obj is O & HasJust; /** Checks that the object matches the branch and returns its value. */ export declare function checkJust(obj: O, just: J): J extends keyof O ? O[J] : never; /** `JustOne` visitor. */ export type ExplorerFor = { readonly [J in O['just'] as `on${Capitalize}`]: (o: O extends IsJust ? V : never, c: C, j: J) => V; }; /** Returns a visitor for `JustOne` ADTs. */ export declare function exploreWith(explorer: ExplorerFor): Visit; /** * A limited depth version of `DeepWritable`. This is useful since in many cases * we want to keep the immutability of nested values and only allow modifying * the outer object's keys and collections. The optional second argument can be * used to allowlist fields for nested modification. */ export type Modifiable = { -readonly [P in keyof O]: O[P] extends ReadonlyMap ? Map : O[P] extends ReadonlySet ? Set : O[P] extends ReadonlyArray ? V[] : P extends K ? Modifiable : O[P]; }; /** * Marks properties in a type as present (required and non-nullable). The * `readonly`-ness of properties is preserved. */ export type MarkPresent = Omit & { [K in F]-?: NonNullable; }; /** * Fits data within a given length, potentially truncating it. This function is * relatively expensive and shouldn't be called on critical paths (i.e. prefer * guarding it with log-level enabled checks). */ export declare function contained(data: unknown, opts?: { readonly maxLength?: number; }): Contained; export interface Contained { /** Stringified size of the contained data. */ readonly size: number; /** Approximate loss, absent if lossless. */ readonly loss?: number; /** Potentially truncated data, fit to container. */ readonly data: unknown; } /** * Mutates the input in-place, deleting all (potentially nested) keys pointing * to `undefined` values. Note that `null` values are kept. Arrays and maps are * traversed. */ export declare function stripUndefinedValues(arg: unknown): void; /** Type-safe mapping over an object's values */ export declare function mapValues(obj: { readonly [P in K]: V; }, fn: (val: V, key: K) => W): { readonly [P in K]: W; }; export interface PrettyFormatterOptions { readonly stringThreshold?: number; readonly arrayThreshold?: number; readonly binaryArrayThreshold?: number; } /** Object pretty formatter */ export declare class PrettyFormatter { private readonly stringPadding; private readonly arrayPadding; private readonly binaryArrayPadding; private constructor(); static create(opts?: PrettyFormatterOptions): PrettyFormatter; format(arg: unknown): unknown; private formatString; private formatRelativeIndexable; private formatBuffer; } export {};