@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
88 lines (87 loc) • 3.77 kB
TypeScript
import { Dictionary, ObjectIterator, PropertyPath, ValueKeyIteratee } from 'lodash';
/**
* Deep merges the two objects and returns a new object with the merge result.
*
* @param lhs - One of the objects to be merged.
* @param rhs - Another object to be merged.
* @param arrayMergeStrategy - Strategy used to merge the array typed fields. Union strategy is used by default to avoid
* duplicated elements.
* @returns A Javascrip tobject with th emerged objects.
*/
export declare function deepMergeObjects<T1, T2>(lhs: Partial<T1>, rhs: Partial<T2>, arrayMergeStrategy?: (destinationArray: unknown[], sourceArray: unknown[]) => unknown[]): T1 & T2;
/**
* Creates an object composed of the `object` properties `predicate` returns
* truthy for. The predicate is invoked with two arguments: (value, key).
*
* @param object - The source object.
* @param predicate - The function invoked per property.
* @returns Returns the new object.
*/
export declare function pickBy<T>(object: Dictionary<T> | null | undefined, predicate: ValueKeyIteratee<T>): Dictionary<T>;
/**
* Creates an object with the same keys as object and values generated by running each own
* enumerable property of object through iteratee. The iteratee function is
* invoked with three arguments: (value, key, object).
*
* @param source - The object to iterate over.
* @param callback - The function invoked per iteration.
* @returns Returns the new mapped object.
*/
export declare function mapValues<T extends object, TResult>(source: T | null | undefined, callback: ObjectIterator<T, TResult>): {
[P in keyof T]: TResult;
};
/**
* Deeply compares two objects and returns true if they are equal.
*
* @param one - The first object to be compared.
* @param two - The second object to be compared.
* @returns True if the objects are equal, false otherwise.
*/
export declare function deepCompare(one: object, two: object): boolean;
/**
* Return the difference between two nested objects.
*
* @param one - The first object to be compared.
* @param two - The second object to be compared.
* @returns Two objects containing the fields that are different, each one with the values of one object.
*/
export declare function deepDifference(one: object, two: object): [object, object];
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
*
* @param object - The object to query.
* @param path - The path of the property to get.
* @returns - Returns the resolved value.
*/
export declare function getPathValue<T = object>(object: object, path: PropertyPath): T | undefined;
/**
* Sets the value at path of object. If a portion of path doesn't exist, it's create.
*
* @param object - The object to modify.
* @param path - The path of the property to set.
* @param value - The value to set.
* @returns - Returns object.
*/
export declare function setPathValue(object: object, path: PropertyPath, value?: unknown): object;
/**
* Removes the property at path of object.
*
* @param object - The object to modify.
* @param path - The path of the property to unset.
* @returns - Returns true if the property is deleted or not found, else false.
*/
export declare function unsetPathValue(object: object, path: PropertyPath): boolean;
/**
* Checks if value is an empty object, collection, map, or set.
*
* @param object - The value to check.
* @returns - Returns true if value is empty, else false.
*/
export declare function isEmpty(object: object): boolean;
/**
* Removes the undefined elements.
*
* @param object - The object whose undefined will be deleted.
* @returns A copy of the object with the undefined elements deleted.
*/
export declare function compact(object: object): object;