@akadenia/helpers
Version:
Akadenia helpers
77 lines (76 loc) • 3.95 kB
TypeScript
/**
*
* @function
* @param {any} object - The object to check if it is a pure object (not an array, date, or function)
* @returns {boolean} - Whether or not the provided object is a pure object
*/
export declare const isPureObject: (object: any) => boolean;
/**
* @function
* @param {string} str - The string of cookies to parse
* @returns {Object} - The object containing key-value pairs of the parsed cookies
*/
export declare const parseCookie: (str: string) => Object;
/**
* Filters an array of objects based on a specified property and value.
* @template T extends Record<string, any> - The type of objects in the array.
* @param {T[]} array - The array of objects to filter.
* @param {keyof T} propertyName - The name of the property to filter on.
* @param {T[keyof T]} propertyValue - The value of the property to filter on.
* @returns {T[]} - The filtered array of objects.
*/
export declare function filterObjectsByProperty<T extends Record<string, any>>(array: T[], propertyName: keyof T, propertyValue: T[keyof T]): T[];
/**
* Checks if the main object contains the sub object.
* @template T extends Record<string, any> - The type of the main object.
* @param {T} mainObject - The main object to check.
* @param {Partial<T>} subObject - The sub object to look for in the main object.
* @returns {boolean} - True if the main object contains the sub object, false otherwise.
*/
export declare function containsSubObject<T extends Record<string, any>>(mainObject: T, subObject: Partial<T>): boolean;
/**
* Finds the object containing the given sub object in the array.
* @template T extends Record<string, any> - The type of objects in the array.
* @param {T[]} array - The array of objects.
* @param {Partial<T>} subObject - The sub object used to search the array.
* @returns {T | null} - The object containing the given sub object or null.
*/
export declare function findObjectBySubObject<T extends Record<string, any>>(array: T[], subObject: Partial<T>): T | null;
/**
* Filters an array of objects based on the objects containing the given sub object
* @template T extends Record<string, any>
* @param {T[]} array - The array of objects
* @param {Partial<T>} subObject - The sub object used to search the array
* @returns {Object | null} - An array of objects containing the given sub object
*/
export declare function filterObjectsBySubObject<T extends Record<string, any>>(array: T[], subObject: Partial<T>): T[];
/**
* Checks if the object has the key with the value.
* @param {Object} object - The object to check
* @param {string} key - The key to check
* @param {any} value - The value to check
* @returns {boolean} - Whether or not the object has the key with the value
* @example
* const object = { a: 1, b: 2, c: 3 }
* objectPropHasValue(object, 'a', 1) // true
* objectPropHasValue(object, 'b', 3) // false
*/
export declare const objectPropHasValue: <ObjectType>({ object, propName, value, }: {
object: ObjectType;
propName: keyof ObjectType;
value: ObjectType[keyof ObjectType];
}) => boolean;
/**
* Finds the first entry in the array that satisfies the predicate.
* @template EntryType - The type of the entries in the array.
* @callback PredicateFunction - The predicate function to use to search the array.
* @param {EntryType} item - The entry in the array to search.
* @returns {boolean} - True if the entry satisfies the predicate, false otherwise.
* @param {EntryType[]} array - The array of entries to search.
* @param {PredicateFunction} predicate - The predicate function to use to search the array.
* @returns {EntryType | null} - The first entry that satisfies the predicate, or null if not found.
*/
export declare const findEntry: <EntryType>(array: EntryType[], predicate: (item: EntryType) => boolean) => EntryType | null;
export declare function convertArrayToMap<T extends object>(arrayData: T[], keyProp: keyof T): {
[key: string]: T;
};