UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

87 lines (86 loc) 5.43 kB
/** Returns a value by the `path`. Works with array indexes, like a.b[0]. */ export declare function getInPath(obj: unknown, path: string): any; export declare function isDateObject(value: unknown): value is Date; /** Sets a value by path . Does not support array indexes. */ export declare function setInPath(obj: object, path: string, value: unknown, delimiter?: string): void; export declare function deleteInPath(obj: object, path: string, delimiter?: string): void; export declare function replaceKeyInMap<K, T>(map: Map<K, T | undefined>, a: K, b: K): void; export declare function replaceKeyInRecord<K extends keyof any, T>(record: Record<K, T>, a: K, b: K): void; export declare function isNil(obj: unknown): obj is null | undefined; export declare function isEqual(a: unknown, b: unknown): boolean; export declare function isEmpty(a: unknown): boolean; export declare function omit<T extends object, K extends PropertyKey[]>(object: T | null | undefined, ...fieldsToRemove: K): Pick<T, Exclude<keyof T, K[number]>>; export type CloneCustomizer = (value: unknown) => unknown | undefined; /** * Creates a deep copy of the specified object, including all nested objects and specifically handling Date, Map, and * Set fields. * * The customizer function can modify the cloning process for the object and its fields. If the customizer * returns 'undefined' for any input, the function falls back to the standard cloning logic. * * The cloning process is recursive, ensuring deep cloning of all objects. * * Note: This function does not support cloning objects with circular dependencies and will throw a system stack * overflow error if encountered. */ export declare function cloneDeep<R = unknown>(value: R, customizer?: CloneCustomizer): R; /** Creates a shallow clone of the object. */ export declare function cloneShallow<T>(value: T): T; export declare function deepMerge<T extends object, U extends object>(target: T, source: U): T & U; /** Returns true if the `value` is a defined object and is not an array. */ export declare function isPlainObject(value: unknown): value is object; /** Compares 2 values. 'null' and 'undefined' values are considered equal and are less than any other values. */ export declare function compareValues(v1: unknown, v2: unknown): number; /** Returns a new object with all top-level object fields re-mapped using `valueMapperFn`. */ export declare function mapValues<ResultType extends object = Record<string, unknown>, InputType extends Record<string, unknown> = Record<string, unknown>>(obj: InputType, valueMapperFn: (value: any, key: keyof InputType, obj: InputType) => unknown): ResultType; /** Groups elements of the array by key. See _.groupBy for details. */ export declare function groupBy<T, K extends PropertyKey>(array: T[], getKey: (item: T) => K): Record<K, T[]>; /** * Picks selected fields from the object and returns a new object with the fields selected. * The selected fields are assigned by reference (there is no cloning). */ export declare function pick<T extends object, K extends keyof T>(obj: T, keys: ReadonlyArray<K>): Pick<T, K>; /** Inverts the record: swaps keys and values. */ export declare function invert<K extends string | number, V extends string | number>(record: Record<K, V>): Record<V, K>; /** * Creates an array of numbers (positive and/or negative) progressing from start up to, but not including, end. * If end is less than start a zero-length range is created unless a negative step is specified. * * Same as lodash range but with an additional parameter: `maximumNumberOfItems`. */ export declare function range(start: number, end: number, step: number, maximumNumberOfItems?: number): number[]; /** Returns count of top level properties in object. */ export declare function countObjectKeys(obj: object | undefined | null): number; /** Returns object entries sorted by name. */ export declare function getSortedEntries<T>(record: Record<string, T>): Array<[string, T]>; /** Removes top level fields which are empty objects. May be used for value formatting. */ export declare function removeEmptyTopLevelRecords<T extends object>(record: T): Partial<T>; export declare function removeUndefinedValues<V>(tags: Record<string, V | undefined>): Record<string, V>; export declare function extractKey(line: string | undefined): string | null; /** Represents a line in a diff output */ export interface DiffLine { lineNumber: number; text: string; type: 'unchanged' | 'added' | 'removed' | 'changed'; } /** Result of computing a line-by-line diff between two objects */ export interface DiffResult { leftLines: Array<DiffLine>; rightLines: Array<DiffLine>; hasChanges: boolean; } /** * Computes a line-by-line diff between two objects. * Objects are serialized to JSON with sorted keys for consistent comparison. * @param before The previous/left object (can be undefined for new objects) * @param after The current/right object * @returns DiffResult with left and right lines and whether there are changes */ export declare function computeObjectDiff(before: unknown, after: unknown): DiffResult; /** * Formats an object as diff lines (all unchanged). * Useful for displaying a single object without comparison. * @param obj The object to format * @returns Array of DiffLine with all lines marked as unchanged */ export declare function formatObjectAsLines(obj: unknown): Array<DiffLine>;