UNPKG

@slck/utils

Version:

utils library - Utility functions for common development.

162 lines (161 loc) 5.15 kB
import { EndpointConfig, ErrorType, GenericObjectType, UnCapitalizeObjectKeys } from './generics'; /** * verifies object is null or undefined, if 'yes' return true. * @param value type any * @returns boolean */ export declare const isNullOrUndefined: (value: any) => boolean; /** * * @param value * @returns */ export declare const isDate: (value: any) => boolean; /** * * @param value * @returns */ export declare const isObject: (value: any) => boolean; /** * Add leading '0' to the either to month or day * @param value type number * @returns number or string */ export declare const leadZeroForMonthOrDay: (value: number) => number | string; /** * * @param value * @returns */ export declare const objectNonShadowCopy: (value: any) => any; /** * Calculate number of days, hours, minutes and seconds remaining for given seconds * @param value type 'number' * @returns an object consists number of days, hours, minutes and seconds remaining */ export declare const daysTimeFromSeconds: (seconds: number) => { days: number; hours: number; minutes: number; seconds: number; }; /** * * @param value * @returns */ export declare const remainingDaysHoursFormTwoDates: (startDate: Date, finish: Date) => { days: number; hours: number; minutes: number; seconds: number; } | null; /** * * @param value * @returns */ export declare const remainingDaysHoursFormSeconds: (seconds: number) => { days: number; hours: number; minutes: number; seconds: number; } | null; /** * verifies object length equals to 0, if 'yes' return true. * @param value type any * @returns boolean */ export declare const isEmpty: (value: any) => boolean; export declare const hasValidLength: (value: any) => boolean; /** * verifies object is null or undefined and length equals to 0, if 'yes' return true. * @param value type any * @returns boolean */ export declare const isNullOrUndefinedEmpty: (value: any) => boolean; /** * verifies object is empty & it's props, if 'yes' return true. * @param value type any * @returns boolean */ export declare const isEmptyInDepth: (value?: any) => boolean; /** * * @param obj * @returns camelCase notation object */ export declare const toCamelCaseKeys: <T extends object>(obj: T) => UnCapitalizeObjectKeys<T> | UnCapitalizeObjectKeys<T[]>; export declare const camelCaseKeysHelper: <T extends object>(obj: T) => UnCapitalizeObjectKeys<T>; /** difference between two objects * return an array object with differed property its source object * and its destination object values respectively */ export declare const objectDifferenceByProps: (sourceObject: any, destinationObject: any) => { property: string; destinationValue: object | string | number | Date; sourceValue: object | string | number | Date; }[]; export declare const genericObjectTypeFn: <T extends string, U>(key: T, rValue: U) => GenericObjectType<T, U>; /** * * @param arr1 * @param arr2 * @returns { result: boolean; error: ErrorType } */ export declare const compareObjectArraysWithTypeSafe: <T extends object>(arr1: T[], arr2: T[]) => { result: boolean; error: ErrorType; }; /** * @description bring the element to the first by searchWith * @param items Type of array * @param key key of the object inside the array * @param searchWith search key either string, number or boolean * @param isConvertStringToLowerCase by default is true * @returns modified object array */ export declare const shiftToFristWith: <T>(items: T[], key: keyof T, searchWith: string | number | boolean, isConvertStringToLowerCase?: boolean) => T[]; /** * @description Return `true` if the property values match in the collection of objects. * @param object T * @param collection T[] * @param prop key of T * @returns boolean */ export declare const checkObjectPropValueExistsInCollection: <T>(object: T, collection: T[], prop: keyof T) => boolean; /** * * @param minutes number of minutes * @param unitOfHours like 'h', 'hrs' * @param unitOfminutes like 'min', 'm' * @returns */ export declare const convertMinutesToTimeText: (minutes: number, unitOfHours: string, unitOfminutes: string) => string; /** * * @param text * @param seperator * @returns */ export declare const convertFirstLetterToUpper: (text: string, seperator?: string) => string; /** * * @param data is a collection of T * @param childrenKey children key property in K * @param valueKey value key which used for split or run logic * @param valueKeyForTree value to holds the conversion value from valueKey * @param delimiter string spearator * @returns a collection of K */ export declare const constructTreeRecursively: <T, K>(data: T[], childrenKey: keyof K, valueKey: keyof T, valueKeyForTree: keyof K, delimiter?: string) => K[]; export declare const addSpacesToCamelCase: (input: string) => string; export declare const isEndpointConfig: (value: any) => value is EndpointConfig; export declare const trimObjectValues: (obj: any, seen?: WeakSet<object>) => any; /** * * @param date * @returns */ export declare const hasValidDateFn: (date: string | Date) => boolean;