UNPKG

immutable-path

Version:

Immutable `get`, `set`, `has`, `unset` deep path operations libraray for object, array and `Map`.

42 lines 1.8 kB
export declare type Class = new (...args: any[]) => any; export declare type Source = Array<any> | Map<any, any> | Record<any, any>; export declare type Path = string | number | Array<string | number>; export declare type KeyOfMap<M> = M extends Map<infer K, unknown> ? K : never; /** @ignore */ export declare type ValueOfMap<M> = M extends Map<unknown, infer V> ? V : never; /** Object key or arrau index. */ export declare type Key<S> = keyof S | KeyOfMap<S>; /** @ignore */ export declare type Value<S, K extends Key<S>> = K extends keyof S ? S[K] : ValueOfMap<S>; /** Options */ export interface Options { /** * If an attribute for a non-existing object should be created, whether to create a `Map` instead of `object`. */ preferMap?: boolean; /** * Atomic classes are treated like a scalar, because MOST PROBABLY user did not intend to update a property of it. Instead they want to replace it. * @example * set([new Date()], "0.a", "x"); // => [{ a: "x" }] NOT [a Date with an attribute "x"] */ atomicClasses?: Class[]; } /** Unset options. */ export interface UnsetOptions extends Options { /** After unsetting a key/index if object/array/Map becomes empty, it is also unset in parent. */ unsetEmpty?: boolean; } /** * Returned value from this function is used as new value to be set. */ export declare type SetFunction<S extends Source, K extends Key<S>> = /** * qefjewoıh * @param value is the current value of given key/index. * @param key is the current key/index of value to be replaced. * @param source is the object/array/Map which has the key/index. * @param root is the root object/array/Map. * @returns new value to be set. */ (value: S[K], key: K, source: S, root: any) => S[K]; //# sourceMappingURL=types.d.ts.map