@alba-cars/common-modules
Version:
A package containing DTOs, validation classes and common modules and interfaces for Alba Cars
109 lines (108 loc) • 3.74 kB
TypeScript
import { Booleanish } from "../../global";
/**
* Deeply compares two objects for equality.
*
* @param obj1 - The first object to compare.
* @param obj2 - The second object to compare.
* @returns `true` if the objects are deeply equal, `false` otherwise.
*/
export declare const deepEqual: <T>(obj1: T, obj2: T) => boolean;
/**
* Checks if a value is a plain object (not an array or null)
*
* @template T
* @param {T} obj
* @returns {boolean}
*/
export declare const isPlainObject: <T>(obj: T) => boolean;
/**
* Checks if a value is a function
*
* @param {*} value
* @returns {boolean}
*/
export declare const isFunction: (value: any) => boolean;
type ComparatorFunction = (_a: any, _b: any) => number;
/**
* Function to sort an array by a specific key (for arrays of objects) or a comparator function
*
* @param {any[]} array
* @param {(string | ComparatorFunction)} key
* @returns {any[]}
*/
export declare const sortBy: (array: any[], key: string | ComparatorFunction) => any[];
export declare function generateRandomBase64(length: number): string;
export declare const formatValue: (n: number | string) => string;
interface TimeInput {
minutes?: number;
hours?: number;
seconds?: number;
}
/**
* Converts a time input to milliseconds
*/
export declare const timeAsMilliseconds: ({ minutes, hours, seconds }: TimeInput) => number;
/**
* Converts a time input to seconds
*/
export declare const timeAsSeconds: ({ minutes, hours, seconds }: TimeInput) => number;
/**
* Removes a key from an object or an array of objects (deeply)
*/
export declare function removeKeyFromObject(obj: any, keyToRemove: string): unknown;
/**
* Formats a number as a currency string (AED)
*/
export declare const currencyFormatter: ({ isDecimal, decimalPlaces }: {
isDecimal: boolean;
decimalPlaces: number;
}) => Intl.NumberFormat;
/**
* Safely parses a string or number into a number
*/
export declare const safeParseNumber: (value: string | number) => number;
/**
* Formats a number with commas
*/
export declare const formatNumberWithCommas: (value: string) => string;
/**
* Converts a single value or an array of values into an array
*/
export declare const makeArray: <T>(value: T | T[]) => T[];
/**
* Check if a value is empty (nullable or empty string)
*/
export declare const isEmpty: (value: any) => boolean;
/**
* Check if an object is an empty object
*/
export declare const isEmptyObject: (value: Record<string, any>) => boolean;
/**
* Check if a value is an empty array
*/
export declare const isEmptyArray: (value: any) => boolean;
/**
* Checks if a value is not empty (null, undefined, or empty string), not an empty object, and not an empty array
*/
export declare const hasValue: (value: any) => boolean;
/**
* Returns a pluralized string based on the value
* @example getPlural(1, 'item') => '1 item'
* @example getPlural(4, 'item') => '4 items'
* @example getPlural(2, 'person', 'people') => '2 people'
* @example getPlural(0, 'item') => '0 items'
*/
export declare const getPlural: (value: number, singular: string, plural?: string | null) => string;
/**
* Escapes special characters in a search term to prevent them from being interpreted as regex operators
*/
export declare const sanitizeRegexString: (input: string) => string;
/**
* Converts a value to a plain object by serializing to and from JSON
*/
export declare const toPlainObject: (value: unknown) => Record<string, any>;
/**
* Converts a Booleanish value (boolean | 'true' | '1' | 'false' | '0') to a boolean
*/
export declare const booleanize: (value: Booleanish) => boolean;
export {};