import type { Dictionary } from './types.js'; /** An object or array that `deleteProperty` can traverse */ export type InputObject = Dictionary | unknown[]; /** Behavior modifiers for `deleteProperty` */ export type DeletePropertyOptions = { /** * Remove any empty objects left in the path. * *Note:* this will remove any empty objects in the path even if the given property was not finally found */ cleanup?: boolean; /** Do not modify the given object directly, but return a modified copy */ immutable?: boolean; /** Only remove property if it is empty */ safe?: boolean; }; /** * Remove a property from an object or array by following a path of keys. * The removal behavior is configurable via the given options. * * @param input - The object or array to remove from * @param path - A dot-separated string (e.g. `'a.b.0.c'`) or an array of keys * (e.g. `['a', 'b', '0', 'c']`) * @param options - Optional behavior modifiers * @param options.cleanup - Also remove any ancestor levels that become empty after the deletion * @param options.immutable - Work on a `structuredClone` of `input` instead of mutating it * @param options.safe - Only remove the property if its current value is empty * * @returns An object with `removed` (whether anything was deleted) and `obj` * (the resulting object — the same reference as `input`, unless * `immutable` is set *and* a modification was made, in which case * `obj` is a new reference) * * @example * ```ts * // Object input * deleteProperty({ a: { b: 1 } }, 'a.b'); * // --> { removed: true, obj: { a: {} } } * * deleteProperty({ a: [10, 20, 30] }, 'a.1'); * // --> { removed: true, obj: { a: [10, 30] } } * * // Array input * deleteProperty([10, 20, 30], '1'); * // --> { removed: true, obj: [10, 30] } * * // Array path * deleteProperty({ a: { b: 1 } }, ['a', 'b']); * // --> { removed: true, obj: { a: {} } } * * // Options * deleteProperty({ a: { b: { c: 1 } } }, 'a.b.c', { cleanup: true }); * // --> { removed: true, obj: {} } * * deleteProperty({ a: { b: 1 } }, 'a.b', { safe: true }); * // --> { removed: false, obj: { a: { b: 1 } } } * ``` */ export declare function deleteProperty(input: InputObject, path: string | string[], options?: DeletePropertyOptions): { /** Whether anything was deleted */ removed: boolean; /** The resulting object — see `@returns` description for reference semantics */ obj: InputObject; }; export default deleteProperty;