// Generated by dts-bundle-generator v9.5.1 /** * Chunks an array into smaller arrays of a specified size. * Works with regular arrays and TypedArrays. * * @param {ArrayLike} arr - The array to be chunked. * @param {number} size - The size of each chunk. * @returns {T[][]} An array of chunked arrays. * * @example * const arr = [1, 2, 3, 4, 5, 6]; * const newArr = chunkArray(arr, 2); // [[1, 2], [3, 4], [5, 6]] */ export declare function chunkArray(arr: ArrayLike, size: number): T[][]; /** * Shuffles the elements of an array randomly. * * @param {T[] | readonly T[]} array - The array to be shuffled. * @returns {T[]} A new array with the same elements in a random order. * * @example * const arr = [1, 2, 3, 4, 5]; * const shuffledArr = shuffleArray(arr); // [3, 1, 5, 2, 4] (random order) */ export declare function shuffleArray(array: T[] | readonly T[]): T[]; /** * Returns a random item from the given array. * * @param {T[] | readonly T[]} array - The array from which to select a random item. * @returns {T} A random item from the array. */ export declare function getRandomArrayItem(array: T[] | readonly T[]): T; export declare function getHexGradientStops({ startColor, endColor, stops, }: { startColor: string; endColor: string; stops: number; }): string[]; /** * Get a date string in a local format, from an optional timezone * * Example output: * * `6/13/2024, 9:45:57 AM` */ /** * Returns the current date and time as a string in the local format. * * @param {string} [timeZone] - The optional time zone to use for formatting the date. * @returns {string} A string representing the current date and time in the local format. * @example * // Get the local date in the default time zone * getLocalDate(); // "10/5/2024, 7:15:50 AM" * * // Get the local date in a specific time zone * getLocalDate('Europe/London'); // "10/5/2024, 12:15:50 PM" */ export declare function getLocalDate(timeZone?: string): string; /** * Checks if a value is a valid JavaScript Date object. * * @param {unknown} date - The value to check. * @returns {boolean} `true` if the value is a valid Date object, `false` otherwise. * @example * // Valid date * isValidDate(new Date()); // true * * // Invalid date * isValidDate(new Date('nope')); // false */ export declare function isValidDate(date: unknown): boolean; /** * Converts an Error object into a plain JavaScript object. * This function is useful for serializing Error objects, which may contain * non-enumerable properties. * * @param {any} error - The Error object to convert. * @returns {Record} A plain object representation of the Error. */ export declare function errorToObject(error: any, options?: { prettyStack: boolean; }): Record; export type BestEffortOptions = { onError?: (error: unknown) => void; log?: boolean; }; /** * Executes a callback and swallows any errors, logging them instead of throwing. * Useful for non-critical operations where failure shouldn't break the flow. * Failures are intentionally silent, hence the name "best effort". * * @param cb - Sync or async callback to execute * @param options - Optional settings * @param options.onError - Called alongside logging when an error occurs * @param options.log - When true, logs errors via `log.error` (default: true) * @returns The callback result, or undefined if an error occurred */ export declare function bestEffort(cb: () => Promise, options?: BestEffortOptions): Promise; export declare function bestEffort(cb: () => T, options?: BestEffortOptions): T | undefined; /** * Awaits a promise and returns a tuple instead of throwing, so the caller can * handle errors inline without a try/catch block. * * On success the tuple is `[result, null]`. On failure it is * `[null, Error, originalError]`, where the second item is always an `Error` * instance (wrapping non-Error throws) and the third item is the raw thrown * value. * * @param {Promise} promise - The promise to await. * @returns {Promise<[T, null] | [null, Error, unknown]>} A result/error tuple. * * @example * const [data, error] = await catchy(fetchData()) * if (error) return // handle the failure * // `data` is safe to use here */ export declare function catchy(promise: Promise): Promise<[ T, null ] | [ null, Error, unknown ]>; /** * Asserts that a condition is truthy, throwing an error if it's not. * * @param {unknown} condition - The condition to check. * @param {string} message - The error message to throw if the condition is falsy. * @throws {Error} Throws an error with the provided message if the condition is falsy. */ export declare function invariant(condition: unknown, message: string): asserts condition; export type FetchWithProgressInput = { url: string; onProgress: (progressPercent: number) => void; contentLengthHeader?: string; options?: Parameters[1]; }; /** * Vanilla `fetch` with the added ability to track progress with a callback. * * @param {FetchWithProgressInput} input - The input parameters for the fetch operation. * @param {string} input.url - The URL to fetch. * @param {function} input.onProgress - Callback function to track progress, receives a percentage. * @param {string} [input.contentLengthHeader] - Optional custom header name for content length. Defaults to `Content-Length`. * @param {object} [input.options] - Optional fetch options. Defaults to `undefined`. * * @returns {Promise} - A promise that resolves to the Response object. * * @example * const url = 'https://example.com/file'; * fetchWithProgress({ * url, * onProgress: (progress) => console.log(`Progress: ${progress}%`), * }).then(response => { * // Handle the response * }); */ export declare function fetchWithProgress({ url, onProgress, contentLengthHeader, options, }: FetchWithProgressInput): Promise; /** * A recursive type representing any value that is valid JSON. */ export type JsonData = string | number | boolean | null | { [key: string]: JsonData; } | JsonData[]; /** * Safely parses a JSON string, returning a default value if parsing fails. * * @param jsonString - The JSON string to parse. * @param defaultValue - The value to return if parsing fails. * @returns The parsed object of type T, or the default value if parsing fails. */ export declare function safeJsonParse(jsonString: string): T | undefined; export declare function safeJsonParse(jsonString: string, defaultValue: T): T; /** * A no-operation function that does nothing. * Useful as a default callback or placeholder function. */ export declare function noop(): void; /** * Formats a floating-point number to a consistent decimal representation as a * string. Trims trailing zeros and removes unnecessary decimal points. * * @param {number} num - The number to format. * @returns {string} The formatted number as a string. * * @example * sanitizeDecimal(2.1091); // "2.11" * sanitizeDecimal(2.0); // "2" * sanitizeDecimal(2.10); // "2.1" */ export declare function sanitizeDecimal(num: number): string; /** * Converts a number of bytes into a human-readable string representation. * Uses the most appropriate unit (GB, MB, KB, or bytes) based on the size. * * @param {number} bytes - The number of bytes to convert. * @returns {string} A string representing the size in the most appropriate unit (GB, MB, KB, or bytes). * * @example * bytesToSize(1500000); // "1.43 MB" * bytesToSize(1024); // "1 KB" * bytesToSize(1); // "1 byte" * bytesToSize(0); // "0 bytes" */ export declare function bytesToSize(bytes: number): string; /** * Generates a random number between the specified minimum and maximum values, inclusive. * * @param {number} min - The minimum value. * @param {number} max - The maximum value. * @returns {number} A random number between min and max, inclusive. */ export declare function getRandomNumber(min: number, max: number): number; export declare function isPlainObject(value: any): value is Record; /** biome-ignore-all lint/suspicious/noExplicitAny: this is ok here */ /** biome-ignore-all lint/suspicious/noConsole: this is needed for a logger! */ /** * Creates a logger object with colored and timestamped logging methods. * * Each log line is preceded by a date in the form of `[6/13/2024, 9:45:57 AM]`. * Objects are not colored and are logged as is. * * The following methods are available: * * `text`: The same a `console.log`. No color output is applied. * * `success`: A green (or aqua) color is applied to the log. * * `error`: A red color is applied to the log. * * `warning`: A yellow color is applied to the log. * * @param {Object} options - The options for creating the logger. * @param {string} [options.timeZone] - The time zone to use for timestamps. * @returns {Object} An object with logging methods: `text`, `success`, `error`, and `warning`. * * @example * log.text('Hello!') // `[6/13/2024, 9:45:57 AM] Hello!` */ export declare function createLogger({ timeZone, includeTime, }?: { timeZone?: string; includeTime?: boolean; }): { text(...items: any[]): void; success(...items: any[]): void; error(...items: any[]): void; warning(...items: any[]): void; }; /** * A convenience export so consumers can implement a conditional "silent" logger * without having to stub this object themselves, leaving the business logic * untouched. * * Example: * * ``` * import {log, emptyLog} from '@qodesmith/utils' * * const logger = silent ? emptyLog : log * * // Business logic... * logger.text('Hello world!') * ``` */ export declare const emptyLog: { text(..._items: any[]): void; success(..._items: any[]): void; error(..._items: any[]): void; warning(..._items: any[]): void; }; /** * Gets the true string length by removing ANSI escape sequences (color codes). * This is useful when measuring the display width of strings that contain terminal colors. * * @param {string} text - The string to measure * @returns {number} The true length of the string without ANSI escape sequences * * @example * getTrueStringLength('\u001b[31mHello\u001b[0m') // 5 (instead of 14) * getTrueStringLength('Hello World') // 11 */ export declare function getTrueStringLength(text: string): number; /** * Creates a formatted table string with Unicode box-drawing characters. * Supports thin, thick, and rounded corner styles. * * @param {Object} options - Table configuration options * @param {(string|number)[][]} options.rows - Array of table rows, where each row is an array of cell values * @param {number} [options.padding=1] - Number of spaces to pad each cell horizontally * @param {boolean} [options.rounded] - Use rounded corners (thin lines with rounded corners) * @param {boolean} [options.thick] - Use thick lines for the table border * @returns {string} A formatted table string with proper alignment and borders * * @throws {Error} Throws an error if rows have different lengths * * @example * makeTableString({ * rows: [['Name', 'Age'], ['John', 25], ['Jane', 30]] * }) * // Returns a formatted table with thin borders * * @example * makeTableString({ * rows: [['A', 'B'], ['1', '2']], * thick: true, * padding: 2 * }) * // Returns a formatted table with thick borders and 2-space padding */ export declare function makeTableString({ rows, padding, ...rest }: ({ rows: (string | number)[][]; rounded: true; } | { rows: (string | number)[][]; thick: true; } | { rows: (string | number)[][]; }) & { padding?: number; }): string; /** * Pluralizes a word based on the given amount. * * @param {number|string} amount - The quantity to determine pluralization * @param {string} word - The word to be pluralized * @returns {string} A string combining the amount and the pluralized word * * @example * pluralize(3, 'apple') // '3 apples' * pluralize('0', 'apple') // '0 apples' * pluralize(1, 'apple') // '1 apple' */ export declare function pluralize(amount: number | string, word: string, includeNumber?: boolean): string; /** * Provides BASIC slug creation functionality. The result is a url-safe string * with the following rules: * - Upper and lowercase letters allowed * - Numbers allowed * - `-_.~` are the only special characters allowed * - Leading and trailing spaces are trimmed * - Spaces are converted to `-` * - Consecutive `-` will be reduced to a single `-` * * @param {string} text - The string to slugify * @returns {string} A slugified string * * @example * slugify('Hello world!') // 'Hello-world' * slugify(' ----This is!@#$%^&a test ') // '-This-isa-test' */ export declare function slugify(text: string): string; /** * Generates a random pronounceable word by alternating between consonants and * vowels, starting with a consonant. * * @param {number} length - The length of the word to generate. * @returns {string} A randomly generated pronounceable word. */ export declare function getRandomPronounceableWord(lenth?: number): string; /** * Waits for a specified number of milliseconds before resolving. * * @param {number} ms - The number of milliseconds to wait. * @returns {Promise} A Promise that resolves after the specified delay. * * @example * // Wait for 2 seconds * await wait(2000); */ export declare function wait(ms: number): Promise; /** * Creates a debounced version of the provided function. * * This function returns a new function that, when invoked, will delay the * execution of the original function until after `wait` milliseconds have * elapsed since the last time it was invoked. This is useful for implementing * behavior that should only happen after a repeated action has completed. * * @param {T} func - The function to debounce. * @param {number} wait - The number of milliseconds to delay. * @returns {(...args: Parameters) => void} A debounced version of the input function. * * @example * // `searchFunction` will be called a max every 300ms. * const debouncedSearch = debounce(searchFunction, 300); */ export declare function debounce void>(func: T, wait: number): (...args: Parameters) => void; /** * Converts a number of seconds into a formatted duration string, separated by * colons. * * @param {number} totalSeconds - The total number of seconds to convert * @returns {string} A formatted string representing the duration in hours:minutes:seconds or minutes:seconds * * @example * secondsToDuration(24) // '0:24' * secondsToDuration(60) // '1:00' * secondsToDuration(3600) // '1:00:00' * secondsToDuration(24 * 60 * 60 * 2 + 1) // '48:00:01' */ export declare function secondsToDuration(totalSeconds: number): string; /** * Converts a given quantity of time into milliseconds based on the specified * unit. * * @param {number} quantity - The amount of time to convert. * @param {'s' | 'm' | 'h' | 'd' | 'w' | 'y'} unit - The unit of time to convert from. * - `s` for seconds * - `m` for minutes * - `h` for hours * - `d` for days * - `w` for weeks * - `y` for years * @param {boolean} isLeapYear - Whether to calculate year as leap year (366 days) or regular year (365 days). Only affects 'y' unit. * @returns {number} The equivalent time in milliseconds. * * @example * getUnitInMs(1, 's') // 1000 * getUnitInMs(1, 'm') // 60000 * getUnitInMs(1, 'h') // 3600000 * getUnitInMs(1, 'd') // 86400000 * getUnitInMs(1, 'w') // 604800000 * getUnitInMs(1, 'y') // 31536000000 (365 days) * getUnitInMs(1, 'y', true) // 31622400000 (366 days) */ export declare function getUnitInMs(quantity: number, unit: "s" | "m" | "h" | "d" | "w" | "y", isLeapYear?: boolean): number; /** * Converts a given quantity of time into seconds based on the specified unit. * * @param {number} quantity - The amount of time to convert. * @param {'ms' | 'm' | 'h' | 'd' | 'w' | 'y'} unit - The unit of time to convert from. * - `ms` for milliseconds * - `m` for minutes * - `h` for hours * - `d` for days * - `w` for weeks * - `y` for years * @param {boolean} isLeapYear - Whether to calculate year as leap year (366 days) or regular year (365 days). Only affects 'y' unit. * @returns {number} The equivalent time in seconds. * * @example * getUnitInSeconds(1000, 'ms') // 1 * getUnitInSeconds(1, 'm') // 60 * getUnitInSeconds(1, 'h') // 3600 * getUnitInSeconds(1, 'd') // 86400 * getUnitInSeconds(1, 'w') // 604800 * getUnitInSeconds(1, 'y') // 31536000 (365 days) * getUnitInSeconds(1, 'y', true) // 31622400 (366 days) */ export declare function getUnitInSeconds(quantity: number, unit: "ms" | "m" | "h" | "d" | "w" | "y", isLeapYear?: boolean): number; /** * Get the frames per second for the current browser. * * This function uses `requestAnimationFrame` over a 1 second period to * determine the FPS. It executes a callback function with a number representing * the calculated FPS. * * @param {function} cb - Callback function that receives the calculated FPS as a parameter. */ export declare function getFps(cb: (num: number) => T): void; /** * Get the frames per second for the current browser asynchronously. * * This function uses `requestAnimationFrame` over a 1 second period to * determine the FPS. It returns a promise that resolves to a number * representing the calculated FPS. * * @returns {Promise} A promise that resolves to the calculated FPS. */ export declare function genFps(): Promise; export {};