import type { Thunkable } from '@xh/hoist/core'; /** * Get a cached value on an object, creating it if it does not yet exist. * * @param obj - object of interest. Must have writable properties. * @param key - key (property name) to cache value at in object. * @param fn - function to generate value if missing. * @returns value stored at key */ export declare function getOrCreate(obj: any, key: any, fn: () => V): V; /** * Return the first defined argument - intended to allow for multiple levels of fallback values or * expressions when evaluating function parameters or configuration object properties. */ export declare function withDefault(...args: T[]): T; /** * Recursively freeze an object, preventing future modifications. Only the specific declared * input types will be frozen. This avoids freezing other types of objects where this routine * could be problematic - e.g. application or library classes (such as `moment`!) which rely on * their internal state remaining mutable to function. */ export declare function deepFreeze | Array | Map | Set>(obj: T): Readonly; /** * Output a deep copy of an object or array up to a given depth, beyond which nested contents will * be replaced by a placeholder string. * * @param obj - source object to trim * @param depth - maximum depth within the object tree that will be returned. */ export declare function trimToDepth(obj: any, depth?: number): any; /** * Determine if an object/value can be parsed successfully into JSON. */ export declare function isJSON(obj: any): boolean; /** * Throw an exception if a condition evaluates as truthy. */ export declare function throwIf(condition: any, message: unknown): void; /** * Instantiate a singleton object of a class, and place a reference to the created * object in a static property on the class. * * This pattern is useful to allow gaining typed references to the singleton via import * and is used for creating the singleton HoistServices, AuthModel, and AppModel. * * @param clazz -- Class (i.e. Constructor) of singleton object to be created. */ export declare function createSingleton(clazz: new () => T): T; /** * Throw an exception if the provided object or collection is empty, as per lodash isEmpty(). * * @param obj - object or array to test. * @param exceptionMessage - error to throw if empty. */ export declare function ensureNotEmpty(obj: any, exceptionMessage?: string): void; /** * Throw an exception if an array contains any duplicate, non-unique items. * * @param arr - the array to test. * @param exceptionMessage - error to throw if non-unique values found. */ export declare function ensureUnique(arr: any[], exceptionMessage?: string): void; /** * Throw an exception if an array contains any items with non-unique values for the provided key. * * @param arr - the array to test. * @param uniqueKey - the property that must hold a unique value for each item. * @param exceptionMessage - error to throw if non-unique values found. */ export declare function ensureUniqueBy(arr: any[], uniqueKey: string, exceptionMessage?: string): void; /** * Returns the singular version of the plural word passed to it. */ export declare function singularize(s: string): string; /** * Returns the plural version of the singular word passed to it. * * @param s - the string to pluralize. * @param count - if provided, will pluralize to match this number * @param includeCount - include count in the output */ export declare function pluralize(s: string, count?: number, includeCount?: boolean): string; /** * Returns the number with an ordinal suffix (i.e. 1 becomes '1st', 11 becomes '11th'). * * @param n - the number to ordinalize */ export declare function ordinalize(n: number): string; /** * Remove when lodash adds Set/Map support. */ export declare function findIn(collection: Set | Map, fn: (it: T) => boolean): T; /** * A function to be passed to `array.filter()` that excludes consecutive items that match the * provided predicate. Matches that would ultimately appear at the start or end of the * filtered array are also removed. * * Useful for removing separators that have become extraneous when the items they were separating * have been removed. */ export declare function filterConsecutive(predicate: (it: T) => boolean): (it: T, idx: number, arr: T[]) => boolean; /** * Intersperse a separator between each item in an array. */ export declare function intersperse(arr: T[], separator: T): T[]; /** * Return value passed or the result of executing it, if it is a function. */ export declare function executeIfFunction(v: Thunkable): T; /** * Merge objects deeply. * * Use this for merging properties from various sources into a target object. * The target value will be mutated and returned. * * Note that this method has the same semantics as Lodash merge, with the important exception * that properties containing arrays will *not* be merged deeply. */ export declare function mergeDeep(object: T, source: S): T & S; export declare function mergeDeep(object: T, source1: S1, source2: S2): T & S1 & S2; export declare function mergeDeep(object: T, source1: S1, source2: S2, source3: S3): T & S1 & S2 & S3; export declare function mergeDeep(target: T, ...sources: S[]): T & S; /** * A string, or an object from which a name can be derived - via `displayName` (e.g. React * components) or `constructor.name` (e.g. class instances). Used for logging and tracing. */ export type NameSource = string | { displayName: string; } | { constructor: { name: string; }; }; /** Resolve a {@link NameSource} to a string, or null if unresolvable. */ export declare function parseNameSource(source: NameSource): string;