/** * @copyright Sister Software * @license AGPL-3.0 * @author Teffen Ellis, et al. * * Utility functions for working with objects. */ import type { PathBuilderLike } from "path-ts"; import type { JsonObject } from "type-fest"; type SetLike = { has(value: T): boolean; } | Iterable; /** * Type-utility for extracting the string keys of an object. * * @internal */ export type StringKeyOf = Extract; /** * @param input Source object. * @param scalarEnum Unconstrained scalar enum whose values present in `input` will be used as keys, such as an * enum-like object. * * @returns A subset of the source object with only properties present in `scalarEnum`. */ export declare function pick(input: O, scalarEnum: Record, transform?: (value: O[keyof O], key: keyof O, input: O) => O[keyof O]): Pick>; /** * @param input Source object. * @param setLike Set-like object whose members represent the subset of keys to pick. * * @returns A subset of the source object with only properties present in `scalarEnum`. */ export declare function pick(input: O, setLike: SetLike, transform?: (value: O[keyof O], key: keyof O, input: O) => O[keyof O]): Pick; /** * @param input Source object. * @param scalarEnum Enum-like object whose members represent the subset of keys to pick. * * @returns A subset of the source object with only properties present in `scalarEnum`. */ export declare function pick(input: O, scalarEnum: Record, transform?: (value: O[keyof O], key: keyof O, input: O) => O[keyof O]): Pick>; /** * @param input Source object. * @param constraints Unconstrained iterable of keys to pick, such as in array or Map. * * @returns A subset of the source object with only properties present in `constraints`. */ export declare function pick>(input: O, constraints: Iterable, transform?: (value: O[keyof O], key: keyof O, input: O) => O[keyof O]): Pick; /** * @param input Source object. * @param constraints Enum-like object whose members represent the subset of keys to pick. * * @returns A subset of the source object with only properties present in `constraints`. */ export declare function pick>(input: O, constraints: Record, transform?: (value: O[keyof O], key: keyof O, input: O) => O[keyof O]): Pick; /** * @param input Source object. * @param keys Unconstrained iterable of keys to pick, such as in array or Map. * * @returns A subset of the source object with only properties present in `keys`. */ export declare function pick(input: O, keys: Iterable, transform?: (value: O[keyof O], key: keyof O, input: O) => O[keyof O]): Pick>; /** * Type-predicate for checking if a value appears to be a record, i.e. an object that is not an array. * * @category Type Guard * @category Object */ export declare function isRecordLike(input: unknown): input is object; type Falsy = false | 0 | 0n | "" | null | undefined; /** * Typed counterpart to `Boolean` for collection filters. The runtime semantics are intentionally identical: all falsy * values are removed, while the overload narrows them out of the resulting element type. */ export declare function isPresent(input: T): input is Exclude; /** * Type-helper to remove nullability from an object's properties. * * @category Object */ export type NonNullableObject = { [P in keyof T]-?: NonNullable; } & NonNullable; /** * Given an object, returns a new object with all nullable properties removed. * * This is useful for cleaning up objects before serializing them to JSON. * * @category Object */ export declare function omitNullable(input: T): NonNullableObject; /** * Given serialized JSON, attempt to parse it. * * Non-throwing: invalid JSON — and any non-string input, `Buffer` included — returns the fallback (`null` unless one is * given). Callers that need a throw on corrupt input, or `JSON.parse`'s reviver parameter, use `JSON.parse` directly * behind a scoped lint disable. */ export declare function tryParsingJSON(input: unknown): T | null; export declare function tryParsingJSON(input: unknown, fallback: F): T | F; export declare class JSONParseError extends Error { constructor(message: string, options?: ErrorOptions); } /** * Parses JSON input or throws a `JSONParseError` if parsing fails. * * @param input - The JSON input to parse. * * @returns The parsed object. */ export declare function parseJSONStrict(input: PathBuilderLike): T; export type FlattenObjectKeys = Key extends string ? T[Key] extends JsonObject ? `${Key}.${FlattenObjectKeys}` : `${Key}` : never; /** * Flattens an object into a single-level object with dot-separated keys. */ export declare function flattenObject(obj: T, prefix?: string[], current?: Record): Record, unknown>; export {}; //# sourceMappingURL=objects.d.ts.map