import * as JsArray from "./JsArray.js"; import * as JsFunction from "./JsFunction.js"; /** * An alias for an empty object. */ export type Empty = Record; /** * Produces a list of keyvalue tuples for an object. * * @example * * type Pairs = Entries<{ a: "a", b: "b" }>; // (["a", "a"] | ["b", "b"])[] */ export type Entries = T extends readonly unknown[] ? Exclude<{ [K in keyof T]: [K, T[K]]; }[number], undefined>[] : Exclude<{ [K in keyof T]: [K, T[K]]; }[keyof T], undefined>[]; /** * Given an object and a type, recursively pick properties of that type. If no * properties of that type exist an empty object is produced. * * @example * * type OnlyFunctions = PickDeep< * { a: 12; b: { c: () => void }; d: [true, () => number] }, * Function.t * >; * // { * // b: { * // c: () => void; * // }; * // d: { * // 1: () => number; * // }; * // } */ export type PickDeep = T extends U ? T : T extends ReadonlyArray ? { [K in JsArray.Index as Empty extends PickDeep ? never : K]: PickDeep; } : T extends object ? { [K in keyof T as Empty extends PickDeep ? never : K]: PickDeep; } : Empty; /** * Recursively make the properties of an object readonly. */ export type ReadonlyDeep = T extends JsFunction.t ? T : T extends object ? { readonly [K in keyof T]: ReadonlyDeep; } : T; /** * Produces a union of the nested values of an object. Functions are treated as * values instead of objects. * * @example * * class Foo { * readonly num = 12; * * bar() { * return "👍"; * } * } * * type Values = NestedValues<{ a: { b: "b" }, c: Foo }> // 12 | "b" | (() => string) */ export type NestedValues = T extends JsFunction.t ? T : T extends ReadonlyArray ? { [K in JsArray.Index]: NestedValues; }[JsArray.Index] : T extends object ? { [K in keyof T]: NestedValues; }[keyof T] : T; /** * Produces a union of values for an object. * * @example * * type Union = Values<{ a: "a", b: "b" }>; // "a" | "b" */ export type Values = T[keyof T]; /** * Returns the entries of an object with better type inference than * `Object.entries`. * * @example * * entries({ a: "a", b: "b" }); // (["a", "a"] | ["b", "b"])[] */ export declare function entries(record: T): Entries; /** * Gets a value from an object given a path to a property. Returns the original * value if the path is empty. Returns `undefined` if the object does not * contain the path. * * @example * * getIn({ a: { b: "b" } }, ["a", "b"]); // "b" */ export declare function getIn(value: T, [prop, ...path]: string[]): unknown; /** * Checks if an object contains a property and narrows its type to include that * property. */ export declare function has(value: object, property: Prop): value is Record; /** * Returns true if the value is of type `object`. Note that functions are of * type object. * * @example * * isObject({}); // true * isObject([]); // true * isObject(() => {}); // true * isObject(new Date()); // true * isObject(""); // false * isObject(null); // false */ export declare function isObject(value: unknown): value is object; /** * Returns the keys of an object with better type inference than `Object.keys`. */ export declare function keys(value: T): [keyof T]; /** * Returns a new object by recursively calling the callback function for each * value in the object. */ export declare function mapValues(value: T, callback: (...keyValue: Entries[number]) => R): { [Key in keyof T]: R; } | R[]; //# sourceMappingURL=JsObject.d.ts.map