import { EntityEnum, EnumEntityType, IBaseEntityServiceResponse, IEntityFilterData, IEntityServiceResponse } from "../entities"; import { Modify } from "../misc"; export declare function groupByFunction(list: T[], keyGetter: (input: T) => K): Map; export declare function groupByOneToOneFunction(list: T[], keyGetter: (input: T) => K): Map; export declare function convertMapToObject(map: Map): { [key: string]: T; }; export type DiffEntry = { old: T; new: U; }; export type DiffObject, U extends Record> = { [K in Exclude]: DiffEntry; } & { [K in Exclude]: DiffEntry; } & { [K in Extract]: DiffEntry; }; export declare function getDifferingKeysWithValues, U extends Record>(obj1: T, obj2: U, keysToCompare?: (keyof T | keyof U)[]): DiffObject; export declare function removeSamePropertyValues(source: any, target: any): void; export declare function getChangedProperties(source: T, target: T): Partial; /** * Performs a deep equality comparison between two objects of the same type. * Recursively compares nested objects and handles null/undefined values. * * @template T - An object type extending `Record` * @param {T} obj1 - The first object to compare * @param {T} obj2 - The second object to compare * @returns {boolean} `true` if both objects are deeply equal, `false` otherwise * * @example * // Primitive values * compareObjects({ a: 1, b: "hello" }, { a: 1, b: "hello" }); // true * compareObjects({ a: 1 }, { a: 2 }); // false * * @example * // Nested objects * compareObjects( * { user: { name: "Alice", age: 30 } }, * { user: { name: "Alice", age: 30 } } * ); // true * * @example * // Mismatched keys * compareObjects({ a: 1, b: 2 }, { a: 1 }); // false * * @example * // null and undefined are treated as equal * compareObjects({ a: null }, { a: undefined }); // true */ export declare function compareObjects>(obj1: T, obj2: T): boolean; /** * Removes elements from the target array that are present in the source array. * * @template T - The type of elements in the arrays. * @param {T[]} source - The array containing elements to be excluded from the target array. * @param {T[]} target - The array from which elements will be filtered out. * @returns {T[]} A new array containing elements from the target array that are not present in the source array. * * @example * const source = [1, 2, 3]; * const target = [1, 2, 3, 4, 5, 6]; * const result = removeElementsFromArray(source, target); * console.log(result); // Output: [4, 5, 6] */ export declare function removeElementsFromArray(source: T[], target: T[]): T[]; /** * Returns a new array with elements from the target array that are not present in the source array. * * @template T - The type of elements in the arrays. * @param {T[]} source - The array containing elements to be excluded from the target array. * @param {T[]} target - The array from which elements will be filtered out. * @returns {T[]} A new array containing elements from the target array that are not present in the source array. * * @example * const source = [1, 2, 3]; * const target = [1, 2, 3, 4, 5, 6]; * const result = arrayDifference(source, target); * console.log(result); // Output: [4, 5, 6] */ export declare function arrayDifference(source: T[], target: T[]): T[]; /** * Returns a new array containing elements that are present in both the source and target arrays. * * @template T - The type of elements in the arrays. * @param {T[]} source - The first array to compare. * @param {T[]} target - The second array to compare. * @returns {T[]} A new array containing elements that are present in both the source and target arrays. * * @example * const source = [1, 2, 3]; * const target = [2, 3, 4]; * const result = arrayIntersection(source, target); * console.log(result); // Output: [2, 3] */ export declare function arrayIntersection(source: T[], target: T[]): T[]; /** * Returns a new array containing elements that are present in both the source and target arrays. * * @template T - The type of elements in the arrays. * @param {T[]} source - The first array to compare. * @param {T[]} target - The second array to compare. * @param {(a: T, b: T) => boolean} comparator - The function to determine if two elements are equal. * @returns {T[]} A new array containing elements that are present in both the source and target arrays. * * @example * const source = [{ id: 1, name: "John" }, { id: 2, name: "Jane" }]; * const target = [{ id: 2, name: "Jane" }, { id: 3, name: "Doe" }]; * const result = arrayIntersectionWith(source, target, (a, b) => a.id === b.id); * console.log(result); // Output: [{ id: 2, name: "Jane" }] */ export declare function arrayIntersectionWith(source: T[], target: T[], comparator: (a: T, b: T) => boolean): T[]; /** * Returns a new array containing elements that are present in either the source or target arrays. * * @template T - The type of elements in the arrays. * @param {T[]} source - The first array to compare. * @param {T[]} target - The second array to compare. * @returns {T[]} A new array containing elements that are present in either the source or target arrays. * * @example * const source = [1, 2, 3]; * const target = [2, 3, 4]; * const result = arrayUnion(source, target); * console.log(result); // Output: [1, 2, 3, 4] */ export declare function arrayUnion(source: T[], target: T[]): T[]; export declare function sumArray(array: T[], key: keyof T): number; /** * Compares existing and incoming arrays and returns the added, deleted, and present elements. * * @template T - The type of elements in the arrays. * @param {T[]} existing - The existing array. * @param {T[]} incoming - The incoming array. * @returns {{ added: T[]; deleted: T[]; present: T[] }} An object containing arrays of added, deleted, and present elements. * * @example * const existing = [1, 2, 3]; * const incoming = [2, 3, 4]; * const result = newRemoved(existing, incoming); * console.log(result); // Output: { added: [4], deleted: [1], present: [2, 3, 4] } */ export declare function newRemoved(existing: T[], incoming: T[]): { added: T[]; deleted: T[]; present: T[]; }; export declare function getEnumNames(enumType: object): string[]; export declare function getFilterByPermission>(permissionFilterConfig: { [key: string]: IEntityFilterData; }, propertyName: keyof T, userPermission: string, filterDto: IEntityFilterData, emptyValue?: any): { [propertyName]: any; }; export declare function getFilterByPermissionFn>(permissionFilterConfig: { [key: string]: () => Promise>; }, propertyName: keyof T, userPermission: string, filterDto: IEntityFilterData, emptyValue?: any): Promise<{ [propertyName]: any; }>; export declare function getPropertyFilterByPermissionFn>(permissionFilterConfig: { [key: string]: () => Promise>; }, propertyNames: (keyof T)[], userPermission: string, filterDto: IEntityFilterData, emptyValue?: any): Promise>; /** * Sets a property value on an object with proper TypeScript type safety. * * @template T - The type of the target object. * @template K - The type of the key, constrained to the keys of T. * @param {T} obj - The object on which the value should be set. * @param {K} key - The key of the property to update. * @param {T[K]} value - The new value to assign to the property. * * @example * interface User { * name: string; * age: number; * } * * const user: User = { name: 'Alice', age: 25 }; * setResponseValue(user, 'age', 30); * console.log(user); // Output: { name: 'Alice', age: 30 } */ export declare function setResponseValue(obj: T, key: K, value: T[K]): void; /** * Converts a numeric string into words following the Indian numbering system. * * @param {string} numStr - The number in string format. Can contain commas (e.g., "1,23,456"). * * @returns {string} The number expressed in words using the Indian format (e.g., Crores, Lakhs). * * @example * const ones = ["", "One", "Two", "Three", ..., "Nineteen"]; * const tens = ["", "", "Twenty", "Thirty", ..., "Ninety"]; * * numberToWordsIndian("1,23,456", ones, tens); * // Output: "One Lakh Twenty Three Thousand Four Hundred Fifty Six" */ export declare function numberToWordsIndian(numStr: string): string; /** * Converts a total number of minutes into a formatted "HH:MM" string. * * @param {number} totalMinutes - The total number of minutes to convert. * * @returns {string} A string representing the equivalent time in "HH:MM" format, * with hours and minutes padded to two digits. * * @example * minutesToHoursMinutes(75); // Output: "01:15" * minutesToHoursMinutes(5); // Output: "00:05" * minutesToHoursMinutes(135);// Output: "02:15" */ export declare function minutesToHoursMinutes(totalMinutes: number): string; export declare function createKeyLabelMap(): Record; export declare function transformDate(obj: T): Modify; export declare function getEntitiesFromSearchV2Response>(searchResponseV2: IBaseEntityServiceResponse>, entityEnumKey: E, EntityClass: new () => T): T[]; /** * Recursively searches for entities of a specific type within a nested `relatedEntities` structure. * * This function traverses the `relatedEntities` tree, looking for a target entity key. * When found, it collects all `baseEntities` for that key and instantiates them * as instances of the provided `EntityClass`. The function continues to traverse * all nested `relatedEntities` recursively, accumulating all matches. * * @template E - The enum type representing the target entity key (`EntityEnum`). * @template T - The corresponding entity type for the target key (`EnumEntityType`). * * @param relatedEntities - The nested `relatedEntities` structure, typically from a * `IBaseEntityServiceResponse`. Can be undefined, in which case an empty array is returned. * @param targetKey - The entity key (`EntityEnum`) to search for in the nested structure. * @param EntityClass - A constructor function for the entity type `T`. Used to * instantiate new objects from the raw base entity data. * * @returns An array of entities of type `T` found at any level of the nested structure. * If no entities are found, an empty array is returned. * * @example * ```ts * const billingEntities = findEntitiesAtAnyLevel( * projectUserMappingsOfCurrentUser.relatedEntities, * EntityEnum.BILLING, * BillingEntity * ); * * console.log(billingEntities); // [BillingEntity {...}, BillingEntity {...}] * ``` * * @note * - This function preserves the type of entities by mapping the raw objects to the provided `EntityClass`. * - It can handle deeply nested `relatedEntities` structures. */ export declare function findEntitiesFromSearchV2RelatedEntities>(relatedEntities: IEntityServiceResponse | undefined, targetKey: EntityEnum, EntityClass: new () => T): T[]; /** * Checks if two decimal numbers are approximately equal within a given tolerance. * * @param {number} firstValue - The first number to compare. * @param {number} secondValue - The second number to compare. * @param {number} allowedDifference - The maximum difference allowed for the numbers * to be considered equal. * * @returns {boolean} Returns `true` if the numbers are within the allowed difference; * otherwise, returns `false`. * * @example * areDecimalNumbersEqual(5483.86, 5483.87, 0.5); // true * areDecimalNumbersEqual(5483.86, 5484.5, 0.5); // false */ export declare function areDecimalNumbersEqual(firstValue: number, secondValue: number, allowedDifference?: number): boolean; /** * Formats a number into the Indian numbering system with commas. * * - Ensures **two decimal places**. * - Applies Indian digit grouping: last 3 digits, then groups of 2 (e.g., 1,23,456.00). * - Accepts both `number` and `string` input. * - Returns an empty string if the input is not a valid number. * * @param {number | string} amount - The number or numeric string to format. * @returns {string} The formatted number as a string in Indian number format. * * @example * formatIndianNumber(123456); // "1,23,456.00" * formatIndianNumber(1891250); // "18,91,250.00" * formatIndianNumber("21250"); // "21,250.00" * formatIndianNumber("abc"); // "" */ export declare function formatIndianNumber(amount: number | string): string; export declare function findDuplicateIds(ids: number[]): number[]; /** * Converts a string or number into a number with fixed decimal precision. * * @param value - The input value to convert. Can be a numeric string or a number. * @param placesAfterDecimal - Number of digits to keep after the decimal point (default: 2). * @returns The numeric value rounded to the specified number of decimal places. * @throws {Error} If the input cannot be converted to a valid number. * * @example * getDecimalNumberFromString("42.5678"); // 42.57 * getDecimalNumberFromString(42.5678, 3); // 42.568 * getDecimalNumberFromString("100"); // 100 * getDecimalNumberFromString("abc"); // throws Error("Invalid number: abc") */ export declare function getDecimalNumberFromString(value: string | number, placesAfterDecimal?: number): number; /** * Recursively checks if a specified property exists in an object or its nested objects. * Skips properties with array values and does not check their contents. * The property is considered present if it exists in the object and its value is not undefined. * * @template T - The type of the input object, constrained to be an object. * @param obj - The object to check for the property. Can be null or undefined. * @param propName - The name of the property to search for. * @returns True if the property exists in the object or any nested non-array object and is not undefined; false otherwise. * * @example * ```typescript * interface MyObject { * name?: string; * details?: { age?: number; tags?: string[] }; * } * * const obj: MyObject = { * name: "Alice", * details: { age: 30, tags: ["test"] } * }; * * console.log(hasProperty(obj, "name")); // true * console.log(hasProperty(obj, "age")); // true (nested in details) * console.log(hasProperty(obj, "tags")); // false (tags is an array, skipped) * console.log(hasProperty(obj, "unknown")); // false * ``` */ export declare function hasProperty(obj: T | null | undefined, propName: string): boolean; /** * Safely converts a given value (string or number) to a number. * * @template T - The input type, constrained to `string | number`. * @param value - The value to convert. Can be a number or a numeric string. * @returns The numeric representation of the input. * @throws {Error} If the input cannot be converted to a valid number. * * @example * convertToNumberType("42"); // 42 * convertToNumberType(3.14); // 3.14 * convertToNumberType("abc"); // throws Error("Invalid number: abc") */ export declare function convertToNumberType(value: T): number; /** * Converts an epoch timestamp (in seconds) into a formatted date-time string. * * @param {number} epoch - The epoch timestamp in seconds (number of seconds since 1970-01-01 00:00:00 UTC). * * @returns {string} The formatted date-time string in "yyyy-MM-dd HH:mm:ss" format. * * @example * epochToDateTime(1759211965); * // Returns: "2025-09-30 11:19:25" * * @example * epochToDateTime(0); * // Returns: "1970-01-01 05:30:00" // if your system timezone is IST (UTC+5:30) */ export declare function epochToDateTime(epoch: number): string; export declare function dateTimeToEpoch(dateInput: string | Date): number; /** * Checks whether the given object has no own enumerable properties. * * @template T - A generic object type with string keys * @param obj - The object to check * @returns `true` if the object has no keys, otherwise `false` * * @example * checkEmptyObj({}); // true * checkEmptyObj({ a: 1 }); // false */ export declare function checkEmptyObj>(obj: T): boolean; /** * Normalises the value of a given key in an array of objects. * * If the value is a string or number, it is converted into a decimal number * using `getDecimalNumberFromString`. Other value types are left unchanged. * * @template T * * @param {T[]} input - Array of objects to be normalised. * @param {keyof T} key - The object key whose value should be normalised. * * @returns {T[]} A new array with the specified key normalised. * * @example * getNormalisedFromKey([{ amount: "1,200.50" }], "amount"); * // Returns: [{ amount: 1200.5 }] */ export declare function getNormalisedFromKey(input: T[], key: keyof T): T[]; /** * Normalises the value of a given key in an array of objects * and returns the sum of the normalised values. * * Internally, this function first normalises the values using * `getNormalisedFromKey` and then sums them using `sumArray`. * * @template T * * @param {T[]} input - Array of objects whose values should be summed. * @param {keyof T} key - The object key to normalise and sum. * * @returns {number} The sum of the normalised values for the given key. * * @example * sumNormalised([{ amount: "100" }, { amount: "200.5" }], "amount"); * // Returns: 300.5 */ export declare function sumNormalised(input: T[], key: keyof T): number; /** * Checks whether a value is neither `null` nor `undefined`. * * Acts as a type guard so TypeScript can safely narrow the type * after filtering. * * Commonly used when working with optional relations or * optional properties to remove empty values. * * @template T * * @param {T | null | undefined} value * Value to check. * * @returns {value is T} * Returns `true` if the value is defined. * * @example * const roles = mappings * .map(m => m.role) * .filter(isDefined); * * // `roles` is inferred as RoleEntityModel[] */ export declare function isDefined(value: T | null | undefined): value is T; export declare function removeDuplicatesByKey(items: T[], key: K): T[]; /** * Extracts unique values from an array of objects by key. * Preserves the exact type of the key (string[] or number[]). */ export declare function getUniqueValuesByKey(items: T[], key: K): T[K][]; /** * Returns a new array containing only unique objects based on the provided key. * * The function preserves the first occurrence of each unique key value * and removes all subsequent duplicates from the array. * * Useful when relation mappings, joins, or flatMap operations produce * duplicate entities that should only appear once in the final result. * * Example: * getUniqueObjectsByKey(users, "id") * -> removes duplicate users having the same id. * * Example: * getUniqueObjectsByKey(projects, "clientId") * -> keeps only the first project for each unique clientId. */ export declare function getUniqueObjectsByKey(items: T[], key: K): T[]; export declare function sanitizeName(name: string): string;