UNPKG

ameliance-scripts

Version:
274 lines (213 loc) 10.1 kB
declare function getLocalStorage<T>(appName: string, store: string, key: string, initValue?: T): any; declare function setLocalStorage<T>(appName: string, store: string, group: string, value: T): void; declare const lab_getLocalStorage: typeof getLocalStorage; declare const lab_setLocalStorage: typeof setLocalStorage; declare namespace lab { export { lab_getLocalStorage as getLocalStorage, lab_setLocalStorage as setLocalStorage }; } declare function join$1(...args: unknown[]): string; declare function returnError$1(error: unknown, appName?: string, wrapperCount?: number, deep?: number): string; declare namespace returnError1 { export { returnError$1 as returnError }; } type ReturnError = { status: number; message: string; }; declare function returnError(error: unknown, status?: number, appName?: string, wrapperCount?: number, deep?: number): ReturnError; type returnError2_ReturnError = ReturnError; declare const returnError2_returnError: typeof returnError; declare namespace returnError2 { export { type returnError2_ReturnError as ReturnError, returnError2_returnError as returnError }; } declare const legacy_returnError1: typeof returnError1; declare const legacy_returnError2: typeof returnError2; declare namespace legacy { export { join$1 as join, legacy_returnError1 as returnError1, legacy_returnError2 as returnError2 }; } declare function addId<T>(array: T[], ids?: string[]): (T & { id: string; })[] | (T & { id: number; })[]; type ClassNameReturn = { className: string; }; declare function className(...args: unknown[]): ClassNameReturn; declare function clearLocalStorageAndReload(): void; declare function createHTMLElem(parent: HTMLElement | DocumentFragment, elementType: string, params?: { class?: string; id?: string; attributes?: string[]; }, text?: string): HTMLElement; type ValueType = 'string' | 'number' | 'boolean' | 'date' | 'array' | 'object' | 'null' | 'undefined' | 'function' | 'symbol' | 'bigint'; /** * Determine the type of a value. * * Returns one of the following: * - 'string' if value is a string * - 'number' if value is a number * - 'boolean' if value is a boolean * - 'date' if value is a Date * - 'array' if value is an array * - 'object' if value is a plain object * - 'null' if value is null * - 'undefined' if value is undefined * - 'function' if value is a function * - 'symbol' if value is a symbol * - 'bigint' if value is a bigint * * @param value - the value to determine the type of * @returns - the type of the value */ declare function getValueType(value: unknown): ValueType; /** * Determine the type of a value. * * If the value is a string, will return one of the following: * - 'date' if the string can be parsed as a Date * - 'number' if the string can be parsed as a number * - 'boolean' if the string is either 'true' or 'false' * * Will return one of the following for other types: * - 'null' if null * - 'undefined' if undefined * - 'number' if number * - 'boolean' if boolean * - 'symbol' if symbol * - 'bigint' if bigint * - 'function' if function * - 'array' if Array * - 'object' if plain object * * Otherwise will return 'string' * * @param value - the value to determine the type of * @returns - the type of the value */ declare function detectValueType(value: unknown): ValueType; type ReturnErrorHandler = { status?: number; code?: string; message: string; }; type ErrorHandler = { error: unknown; status?: number; code?: string; message?: string; title?: string; errorDepth?: number; showConsoleError?: boolean; wrapperCount?: number; }; declare function errorHandler({ error, status, code, message, title, errorDepth, showConsoleError, wrapperCount, }: ErrorHandler): ReturnErrorHandler; declare function escapeHtml(unsafe: string): string; declare const getChangedProperties: <T extends object>(originalObject: Partial<T>, updatedObject: Partial<T>) => Partial<T>; type ArrItem$4 = string | number; declare function getCommonValues(...arrays: ArrItem$4[][]): ArrItem$4[]; declare function getCurrentDateInMs(): number; declare function getCurrentTimeWithOffset(millisecondsOffset: number): string; type ArrItem$3 = string | number; declare function getDifferentValues(...arrays: ArrItem$3[][]): ArrItem$3[]; declare function getElemByKey<E, V>(array: E[], key: keyof E, value: V): E | null; declare function getFormattedDate(dateString: string, dateStyle?: Intl.DateTimeFormatOptions['dateStyle'], format?: string): string; declare function getIndexByKey<E, V>(array: E[], key: keyof E, value: V): number; type ArrItem$2 = string | number; declare function getIndexesOfNonEmptyElements(array: ArrItem$2[]): ArrItem$2[]; /** * Like {@link getMatch}, but returns `null` instead of throwing if `code` is not found in `values`. * * @param code - The code to look up in `values`. * @param values - An object with one or more case values. * @returns The value associated with `code` if it exists, otherwise `values._` if it exists, otherwise `null`. */ declare function getMatchSoft<C extends PropertyKey, M>(code: C | undefined | null, values: Partial<Record<C, M>> & { _?: M; }): M | null; /** * A utility function to get a value from an object based on a given key. * * This function is useful when you need to get a value from an object based on a * dynamic key, while also providing a default value if the key is not present * in the object. * * @example * const options = { * apple: 'red', * banana: 'yellow', * _: 'unknown', * }; * * const color = getMatch('apple', options); // red * const unknownColor = getMatch('orange', options); // unknown * * @param code The key to look up in the object * @param values The object containing the values * @returns The value associated with the key, or the default value if the key is not present */ declare function getMatch<C extends PropertyKey, M>(code: C | undefined | null, values: Partial<Record<C, M>> & { _: M; }): M; declare function getObjKeyByValue<T>(object: Record<string, T>, value: T): string | undefined; declare function getRandomHEXColor(): string; declare function getRandomNumber(min: number, max: number): number; declare function getRandomRGBColor(): number[]; declare const getScrollDirection: () => "UP" | "DOWN"; declare function getToday(): string; declare function groupBy<T, K extends string | number>(array: T[], key?: K, length?: number): [string, T[]][]; type HideType = 'left' | 'right' | 'middle'; declare function hideEmail(email: string, hideType?: HideType): string | null; type Primitive = string | number | boolean; type InterpolationValues = { [key: string]: Primitive | InterpolationValues; }; declare function interpolate(template: string, values: InterpolationValues, options?: { throwIfMissing?: boolean; escapeValues?: boolean; }): string; declare function isArraysEqual<T>(arr1?: T[] | null, arr2?: T[] | null): boolean; declare function isClient(): boolean; declare function isObjectEmpty(obj: object): boolean; declare function isObjectHasValue<T extends string | number>(object: Record<string, T>, value: T): boolean; declare function isObjectValid<T>(obj: T): boolean; declare function isObject<T>(obj: T): boolean; declare function іsValidUrl(url: string): boolean; declare function joinWith(combiner: string, ...args: unknown[]): string; declare function join(...args: unknown[]): string; declare function kebabToCamelCase(str: string): string; type Args = Array<unknown> | [Array<unknown>, Array<string>]; type LogMethod = (message: string, ...args: Args) => void; type Log = { info: LogMethod; success: LogMethod; warn: LogMethod; error: LogMethod; }; declare const log: Log; declare function parseCurrentDateFromMs(ms: string | number): Date; declare function removeEmptyValues<T, K extends string | number>(array: T[], key?: K): T[]; type SetInterval = { callback: () => void; delay: number; counts: number; }; declare function setIntervalCounts({ callback, delay, counts, }: SetInterval): ReturnType<typeof setInterval>; declare function shuffleArray<TYPE>(array: TYPE[]): TYPE[]; declare function sortArrayLocalCompare<T, K extends string | number>(array: T[], key?: K): T[]; declare function sortArrayOfObj<T, K extends keyof T>(array: T[], key: K, type?: ValueType, undefinedPosition?: 'start' | 'end'): T[]; declare function stringCut(string: string, limit: number, ending?: string): string; declare function toTimeFormat(totalSeconds: number): string; type ArrItem$1 = string; type ObjItem$1 = Record<string, string | number>; declare function trimEndEmptyValues(array: ArrItem$1[] | ObjItem$1[], key?: string): ArrItem$1[] | ObjItem$1[]; type ArrItem = string; type ObjItem = Record<string, string | number>; declare function trimStartEmptyValues(array: ArrItem[] | ObjItem[], key?: string): ArrItem[] | ObjItem[]; type WriteTextToClipboardReturn = boolean; declare function writeTextToClipboard(text: string): Promise<WriteTextToClipboardReturn>; declare const a: { lab: typeof lab; legacy: typeof legacy; }; export { type ErrorHandler, type ReturnErrorHandler, type ValueType, type WriteTextToClipboardReturn, addId, className, clearLocalStorageAndReload, createHTMLElem, a as default, detectValueType, errorHandler, escapeHtml, getChangedProperties, getCommonValues, getCurrentDateInMs, getCurrentTimeWithOffset, getDifferentValues, getElemByKey, getFormattedDate, getIndexByKey, getIndexesOfNonEmptyElements, getMatch, getMatchSoft, getObjKeyByValue, getRandomHEXColor, getRandomNumber, getRandomRGBColor, getScrollDirection, getToday, getValueType, groupBy, hideEmail, interpolate, isArraysEqual, isClient, isObject, isObjectEmpty, isObjectHasValue, isObjectValid, join, joinWith, kebabToCamelCase, lab, legacy, log, parseCurrentDateFromMs, removeEmptyValues, setIntervalCounts, shuffleArray, sortArrayLocalCompare, sortArrayOfObj, stringCut, toTimeFormat, trimEndEmptyValues, trimStartEmptyValues, writeTextToClipboard, іsValidUrl };