UNPKG

dbl-utils

Version:

Utilities for dbl, adba and others projects

112 lines (111 loc) 4.58 kB
/** * Splits an array into chunks of a given size. * @param {T[]} arr - Array to split into chunks. * @param {number} chunkSize - Size of each chunk. * @returns {T[][]} Array of chunked arrays. */ export declare function sliceIntoChunks<T>(arr: T[], chunkSize: number): T[][]; export type IArrayString = (null | undefined | boolean | string | IArrayString)[]; /** * Splits and flattens a list of strings based on a separator. * @param {string[]} arrayStrings - Array of strings to split and flatten. * @param {string} separator - Separator to use for splitting. * @returns {string[]} Flattened and splitted array of strings. */ export declare function splitAndFlat(arrayStrings: IArrayString, separator?: string): string[]; /** * Generates a random set of colors with an optional format. * @param count - Number of colors to generate. * @param options - Object containing optional parameters. * @param options.format - The format of the output colors ('hex', 'rgb', 'nrgb'). * @param options.bounds - The bounds for color transformation. * @param options.distribute - Whether the colors should be evenly distributed. * @returns An array of colors in the specified format. */ export declare function generateRandomColors(count: number, { format, bounds, distribute }?: { format?: 'hex' | 'rgb' | 'nrgb'; bounds?: number | number[] | { r: number; g: number; b: number; }; distribute?: boolean; }): Array<string | [number, number, number] | number[]>; /** * Evaluates the similarity of a set of colors. * @param cls - Array of colors in hex format. * @returns A similarity score between 0 and 1, where 0 indicates all colors are distinct and 1 indicates all are similar. */ export declare function evaluateColorSimilarity(colors: string[]): number; /** * Normalizes a string by converting it to lowercase and removing diacritical marks. * @param {string} str - The string to normalize. * @returns {string} The normalized string. */ export declare function normalize(str?: string): string; /** * Converts a string to a slug. * @param {string} str - The string to slugify. * @returns {string} The slugified string. */ export declare function slugify(str?: string): string; /** * Generates a random four-character string consisting of hexadecimal digits. * @returns {string} The random four-character string. */ export declare function randomS4(): string; /** * Generates a random string of the specified length using the provided characters. * * @param {number} [length=16] - The length of the generated string. Default is 16. * @param {string} [characters='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'] - A string representing the characters to be used. Default includes uppercase, lowercase letters, and digits. * @returns {string} A random string composed of the specified characters. */ export declare function randomString(length?: number, characters?: string): string; /** * Generates an array of time intervals between two dates. * @param {Object} options - Options for generating time intervals. * @param {string|number} options.from - Start date in string format or as a UNIX timestamp. * @param {string|number} options.to - End date in string format or as a UNIX timestamp. * @param {number} options.step - The step size in hours for each time interval. * @param {string} [options.boundary] - Restrict chunks to 'day', 'month', or 'day,month' boundaries. * @returns {Array} An array of objects representing each time interval. */ export declare function timeChunks(options: { from: string | number; to: string | number; step: number; boundary?: string; }): { from: string; to: string; step: number; }[]; /** * Resolves the promise after a given timeout. * @param {number} timeout - Milliseconds to wait before resolving. * @returns {Promise<void>} The promise that resolves after the timeout. */ export declare function delay(timeout: number): Promise<void>; /** * Computes the hash value of a string. * @param {string} string - The string to hash. * @returns {number} The computed hash value. */ export declare function hash(string: string): number; /** * Linear Congruential Generator (LCG) class for pseudo-random number generation. * @class LCG */ export declare class LCG { private a; private c; private m; private seed; constructor(seed: number); /** * Generates a pseudo-random number between 0 and 1. * @returns {number} The generated pseudo-random number. */ random(): number; }