/** * Retrieves the entries of an object as an array of key-value pairs. * * @param obj - The object to retrieve the entries from. * @returns An array of key-value pairs representing the entries of the object. */ export function getEntries(obj: any): [string, any][] { const entries: [string, any][] = []; for (const key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { entries.push([key, obj[key]]); } } return entries; } /** * Checks if an object has a specific property. * * @param obj - The object to check. * @param prop - The property to check for. * @returns A boolean indicating whether the object has the property. */ export function hasOwn(obj: Record, prop: string): boolean { return Object.prototype.hasOwnProperty.call(obj, prop); } /** * Checks if an object is empty. * @param object - The object to check. * @returns True if the object is empty, false otherwise. */ export const isObjectEmpty = (object: any = {}) => Object.keys(object || {}).length === 0; /** * Delays the execution of a function by a specified number of milliseconds. * @param result - The result to be resolved after the delay. * @param milliseconds - The number of milliseconds to delay the execution. Default is 300 milliseconds. * @returns A promise that resolves to void after the specified delay. */ export const delay = (result: any, milliseconds = 300): Promise => { return new Promise((resolve) => { setTimeout(() => { resolve(result); }, milliseconds); }); }; export const hasValue = (value: any) => { if (value === null || value === undefined) { return false; } if (typeof value === 'string') { return !!value.length; } if (value === 0) { return true; } return !!value; };