import type { FilterOut } from './array.js'; import * as diff from './diff.js'; import type { Split } from './string.js'; import type { $drain, Expand, UnionToTuple } from './types.js'; export declare function filterObject(object: O, predicate: (key: keyof O, value: O[keyof O]) => boolean): R; export declare function pick(object: T, ...keys: readonly K[]): Pick; export declare function pick(object: T, ...keys: readonly (readonly K[])[]): Pick; /** @see https://github.com/microsoft/TypeScript/issues/49656 */ export type Omit = { [P in keyof T as Exclude]: T[P]; }; export declare function omit(object: T, ...keys: readonly K[]): Omit; export declare function omit(object: T, ...keys: readonly (readonly K[])[]): Omit; export declare function assignWithDefaults, From extends Record>(to: To, from: From, defaults?: Partial): void; /** * Returns whether `value` is not a primitive. * * This function is only useful for the type check, * you can do `Object(v) === v` otherwise. */ export declare function isObject(value: unknown): value is object; export type DeepAssign = { [K in keyof To | keyof From]: K extends keyof To ? K extends keyof From ? To[K] extends object ? From[K] extends object ? Expand> : never : From[K] extends object ? never : From[K] : To[K] : From[K & keyof From]; }; export interface DeepAssignOptions { /** Whether to replace arrays instead of merging them */ replaceArrays?: boolean; /** Whether to allow unsafe override of the `constructor` property */ unsafeOverrideConstructor?: boolean; } /** * @deprecated * Use an options object instead, see {@link DeepAssignOptions} */ export declare function deepAssign(to: To, from: From, treatArraysAsPrimitives: boolean): DeepAssign; export declare function deepAssign(to: To, from: From, options?: DeepAssignOptions): DeepAssign; export type StructurallyEqual = diff.DeepRT['result'] extends 'equal' ? true : false; export declare function structurallyEqual(to: To, from: From): StructurallyEqual; /** * Entries of T */ export type EntriesTuple = UnionToTuple<{ [K in keyof T]: [K, T[K]]; }[keyof T]> & [unknown, unknown][]; /** * Entries of T */ export type Entries = ({ [K in keyof T]: [K, T[K]]; }[keyof T] & unknown[])[]; export declare function isJSON(str: string): boolean; export declare function resolveConstructors(object: object): string[]; export declare function getAllPrototypes(object: object): IterableIterator; /** * Allows you to convert an object with specific member types into a Map that will give you the correct type for the correct member */ export interface ConstMap>, K extends keyof any = keyof T, V = T[keyof T]> extends Map { get(key: TK): T[TK]; get(key: K): V; set(key: TK, value: T[TK]): this; set(key: K, value: V): this; has(key: keyof T | K): boolean; } export declare function map>>(items: T): Map; /** * Flatten an object structure into a set of "keys". * * @example * ```ts * type example = FlattenKeys<{ h: { s: { l: 1; v: 2 } } }>; * type result = "h" | "h.s" | "h.s.l" | "h.s.v"; * ``` */ export type FlattenKeys = { [K in keyof O & (string | number)]: O[K] extends Record ? K | `${K}.${$drain>}` : K; }[O extends readonly unknown[] ? keyof O & `${number}` : keyof O & (string | number)]; export type KeySeparator = '.' | '[' | ']'; type GetByPath = Path extends [ infer Key extends keyof Data | '__proto__', ...infer Rest extends (string | number)[] ] ? Key extends '__proto__' ? never : Rest extends [] ? Data[Key & keyof Data] : GetByPath : undefined; /** * Get a value using a path of property keys. * * @see {@link getByString} * * @example * ```ts * interface Duck { * taxonomy: { * genus: 'anas'; * species: 'platyrhynchos'; * }; * } * * type DuckSpecies = GetByString; // 'platyrhynchos' * ``` */ export type GetByString> = GetByPath, ''>>; /** * Get a value using a path of property keys. * * @example * Translation keys mapping to locale objects * ```ts * const locale = { * preference: { * theme: { * label: 'Theme' * } * } * } as const; * * const text = getByString(locale, 'preference.theme.label'); // 'Theme' * ``` * * @example * Arrays * ```ts * const pascal = { * triangle: [ * [1], * [1, 1], * [1, 2, 1], * [1, 3, 3, 1], * [1, 4, 6, 4, 1] * ] * } as const; * * const row3 = getByString(pascal, 'triangle[3]'); // readonly [1, 3, 3, 1] * const r4c3 = getByString(pascal, 'triangle[4][2]'); // 6 * ``` */ export declare function getByString>(object: T, path: P): GetByString; export declare function setByString>(object: T, path: P, value: V): V; export type JSONPrimitive = null | string | number | boolean; export interface JSONObject { [K: string]: JSONValue | undefined; } export type JSONValue = JSONPrimitive | JSONObject | JSONValue[]; /** * An object `T` with all of its functions bound to a `This` value */ export type Bound = T & { [k in keyof T]: T[k] extends (...args: any[]) => any ? (this: This, ...args: Parameters) => ReturnType : T[k]; }; /** * Binds a this value for all of the functions in an object (not recursive) */ export declare function bindFunctions(fns: T, thisValue: This): Bound; /** * Makes all properties in T mutable */ export type Mutable = { -readonly [P in keyof T]: T[P]; }; /** * Makes all properties in T readonly recursively */ export type ReadonlyRecursive = T extends object ? { readonly [K in keyof T]: ReadonlyRecursive; } : T; /** * Makes all properties in T mutable recursively */ export type MutableRecursive = T extends object ? { -readonly [P in keyof T]: MutableRecursive; } : T; /** * Makes properties with keys assignable to K in T required * @see https://stackoverflow.com/a/69328045/17637456 */ export type WithRequired = T & { [P in K]-?: T[P]; }; /** * Makes properties with keys assignable to K in T optional */ export type WithOptional = Pick, K> & Omit; export type ClassLike = abstract new (...args: any[]) => Instance; export type InstancesFor = T extends [] ? [] : T extends readonly [infer C extends ClassLike, ...infer Rest extends readonly ClassLike[]] ? [InstanceType, ...InstancesFor] : never; export type ConstructorsFor = T extends [] ? [] : T extends readonly [infer I, ...infer Rest extends readonly unknown[]] ? [new (...args: any[]) => I, ...ConstructorsFor] : never; export type Concrete = Pick & (new (...args: any[]) => InstanceType); /** * Extracts an object with properties assignable to P from an object T * @see https://stackoverflow.com/a/71532723/17637456 */ export type ExtractProperties = { [K in keyof T as T[K] extends infer Prop ? (Prop extends P ? K : never) : never]: T[K]; }; /** * Extract the keys of T which are required * @see https://stackoverflow.com/a/55247867/17637456 */ export type RequiredKeys = { [K in keyof T]-?: {} extends { [P in K]: T[K]; } ? never : K; }[keyof T]; /** * @see https://dev.to/tmhao2005/ts-useful-advanced-types-3k5e */ export type RequiredProperties = Omit & Required>; /** * @see https://dev.to/tmhao2005/ts-useful-advanced-types-3k5e */ export type DeepRequired = { [K in keyof T]-?: DeepRequired; }; /** * @see https://dev.to/tmhao2005/ts-useful-advanced-types-3k5e */ export type Optional = Omit & Partial; /** * @see https://dev.to/tmhao2005/ts-useful-advanced-types-3k5e */ export type NestedKeys = { [P in keyof T & (string | number)]: T[P] extends Date ? `${P}` : T[P] extends Record ? `${P}` | `${P}.${NestedKeys}` : `${P}`; }[keyof T & (string | number)]; /** * @see https://dev.to/tmhao2005/ts-useful-advanced-types-3k5e */ export type PartialRecursive = { [P in keyof T]?: T[P] extends (infer U)[] ? PartialRecursive[] : T[P] extends object | undefined ? PartialRecursive : T[P]; }; /** * Nothing in T */ export type Never = { [K in keyof T]?: never; }; /** * All of the properties in T or none of them */ export type AllOrNone = T | Never; export {};