@plurid/plurid-functions
Version:
General Utility Functions for Plurid Applications
89 lines (88 loc) • 2.59 kB
TypeScript
import { InvertResult, RecursivePartial, NestedKeyOf, RecursiveOmit } from "../../data/interfaces";
export declare const isObject: (entity: any) => boolean;
/**
* http://blog.nicohaemhouts.com/2015/08/03/accessing-nested-javascript-objects-with-string-key/
*
* @param data
* @param path
* @param separator
*/
export declare const getNested: <T>(data: T, path: string, separator?: string) => any;
/**
* https://stackoverflow.com/a/52912610
*
* @param data
* @param update
* @param path
* @param separator
*/
export declare const updateNested: <T, U>(data: T, path: string, update: U, separator?: string) => T | undefined;
/**
* Creates a deep clone of the `data`.
*
* The default `type` is `json`, meant for deep cloning of json-like objects.
* The `any` `type` will handle a deep clone of `Function`, `Date`, and more.
*
* @param data
* @param type
*/
export declare const clone: <D>(data: D, type?: 'json' | 'any') => D;
/**
* Convert map to object.
*
* @param map
*/
export declare const mapToObject: <K, V>(map: Map<K, V>) => any;
/**
* Removes `undefined` or `null` values from key-value object.
*
* @param object
* @returns
*/
export declare const clean: (object: Record<string, any | undefined | null>, onlyUndefined?: boolean) => Record<string, any>;
/**
* Flips the keys and the values of the object.
* The values must be `string`s or `number`s.
*
* ```
* const a = {
* b: 'c',
* d: 'e',
* f: 1,
* g: true, // ignored
* } as const;
*
* flip(a) -> {
* c: 'b',
* e: 'd',
* 1: 'f',
* }
* ```
*
* @param obj
* @returns
*/
export declare const flip: <T extends Record<PropertyKey, PropertyKey>>(obj: T) => InvertResult<T>;
/**
* Merges `target` into `object`.
*
* The `resolvers` can be used to resolve any field within the `object`
* using dot-access syntax, e.g. `{ 'key1.key1.key3': () => value }`.
*
* @param object
* @param target
* @param resolvers
* @param trunk
* @returns
*/
export declare const merge: <O extends object = any, R = O>(object: O, target: RecursivePartial<O>, resolvers?: Partial<Record<NestedKeyOf<O>, any>>, trunk?: string) => R;
/**
* Check `target` equals `object` based on `object`s keys.
*
* @param object
* @param target
* @param trunk
* @returns
*/
export declare const equals: <O = any>(object: O, target: O, trunk?: string) => boolean;
export declare const omit: <O extends Record<string, any>, K extends NestedKeyOf<O> | NestedKeyOf<O>[]>(object: O, keys: K, trunk?: string) => any;