import { Secret, SignOptions, VerifyOptions, JwtPayload, DecodeOptions } from 'jsonwebtoken'; /** * Intersperses a separator element between each element of an array. * * Takes an array and a separator value, and returns a new array where the separator * is inserted between each pair of adjacent elements from the original array. * The separator is not added before the first element or after the last element. * * @template T - The type of elements in the input array * @template S - The type of the separator element * @param arr - The input array to intersperse * @param sep - The separator element to insert between array elements * @returns A new array with separator elements interspersed between original elements * * @example * ```typescript * intersperse([1, 2, 3], 0) * // Returns: [1, 0, 2, 0, 3] * * intersperse(['a', 'b', 'c'], '-') * // Returns: ['a', '-', 'b', '-', 'c'] * * intersperse([1], 0) * // Returns: [1] * * intersperse([], 0) * // Returns: [] * ``` */ declare function intersperse(arr: T[], sep: S): (T | S)[]; /** * Flattens a nested array by one level. * * Takes an array of arrays and returns a new array with all sub-arrays * concatenated into a single level. Only flattens one level deep. * * @template T - The type of elements in the nested arrays * @param arr - The array of arrays to flatten * @returns A new flattened array containing all elements from the sub-arrays * * @example * ```typescript * flatten([[1, 2], [3, 4], [5]]) * // Returns: [1, 2, 3, 4, 5] * * flatten([['a', 'b'], ['c'], ['d', 'e']]) * // Returns: ['a', 'b', 'c', 'd', 'e'] * * flatten([]) * // Returns: [] * * flatten([[], [1, 2], []]) * // Returns: [1, 2] * ``` */ declare function flatten(arr: T[][]): T[]; /** * Creates a cross join (Cartesian product) of two arrays. * * Takes two arrays and returns an array of tuples representing all possible * combinations where the first element comes from the first array and the * second element comes from the second array. * * @template T - The type of elements in the first array * @template U - The type of elements in the second array * @param arr1 - The first array * @param arr2 - The second array * @returns An array of tuples representing all combinations * * @example * ```typescript * crossJoin([1, 2], ['a', 'b']) * // Returns: [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] * * crossJoin(['x'], [1, 2, 3]) * // Returns: [['x', 1], ['x', 2], ['x', 3]] * * crossJoin([], [1, 2]) * // Returns: [] * * crossJoin([1], []) * // Returns: [] * ``` */ declare function crossJoin(arr1: T[], arr2: U[]): [T, U][]; /** * Gets an element from an array at the specified index. * * Retrieves an element at the given index. Supports negative indices to count * from the end of the array. Returns the default value if the index is out of bounds. * * @template T - The type of elements in the array * @template D - The type of the default value * @param arr - The array to get the element from * @param index - The index to get, negative values count from the end * @param defaultValue - The value to return if index is out of bounds * @returns The element at the specified index or the default value * * @example * ```typescript * get([1, 2, 3, 4], 1) * // Returns: 2 * * get([1, 2, 3, 4], -1) * // Returns: 4 * * get([1, 2, 3], 10, 'default') * // Returns: 'default' * * get([], 0, 'empty') * // Returns: 'empty' * ``` */ declare function get(arr: T[], index: number, defaultValue?: D): T | D | undefined; /** * Gets the first element of an array. * * Returns the first element of the array, or the default value if the array is empty. * * @template T - The type of elements in the array * @template D - The type of the default value * @param arr - The array to get the first element from * @param defaultValue - The value to return if array is empty * @returns The first element or the default value * * @example * ```typescript * first([1, 2, 3]) * // Returns: 1 * * first(['a', 'b', 'c']) * // Returns: 'a' * * first([], 'default') * // Returns: 'default' * * first([]) * // Returns: undefined * ``` */ declare function first(arr: T[], defaultValue?: D): T | D | undefined; /** * Gets the last element of an array. * * Returns the last element of the array, or the default value if the array is empty. * * @template T - The type of elements in the array * @template D - The type of the default value * @param arr - The array to get the last element from * @param defaultValue - The value to return if array is empty * @returns The last element or the default value * * @example * ```typescript * last([1, 2, 3]) * // Returns: 3 * * last(['a', 'b', 'c']) * // Returns: 'c' * * last([], 'default') * // Returns: 'default' * * last([]) * // Returns: undefined * ``` */ declare function last(arr: T[], defaultValue?: D): T | D | undefined; /** * Splits an array into chunks based on size or a predicate function. * * If a number is provided, splits the array into chunks of that size. * If a function is provided, splits the array at positions where the function returns true. * * @template T - The type of elements in the array * @param arr - The array to split * @param sizeOrFunc - Either the chunk size (number) or a predicate function * @returns An array of arrays representing the chunks * * @example * ```typescript * split([1, 2, 3, 4, 5, 6], 2) * // Returns: [[1, 2], [3, 4], [5, 6]] * * split([1, 2, 3, 4, 5], 2) * // Returns: [[1, 2], [3, 4], [5]] * * split([1, 2, 3, 4, 5], (item, index) => item % 3 === 0) * // Returns: [[1, 2], [3], [4, 5]] * * split([], 2) * // Returns: [] * ``` */ declare function split(arr: T[], sizeOrFunc: number | ((item: T, index: number) => boolean)): T[][]; /** * Returns a random element from an array. * * Selects and returns a random element from the array. Returns undefined if the array is empty. * * @template T - The type of elements in the array * @param arr - The array to select a random element from * @returns A random element from the array or undefined if empty * * @example * ```typescript * random([1, 2, 3, 4, 5]) * // Returns: any element from the array (e.g., 3) * * random(['apple', 'banana', 'cherry']) * // Returns: any string from the array (e.g., 'banana') * * random([]) * // Returns: undefined * * random(['single']) * // Returns: 'single' * ``` */ declare function random(arr: T[]): T | undefined; /** * Returns a new array with elements shuffled in random order. * * Creates a new array with the same elements as the input array but in a random order. * Uses the Fisher-Yates shuffle algorithm for uniform distribution. * * @template T - The type of elements in the array * @param arr - The array to shuffle * @returns A new array with elements in random order * * @example * ```typescript * shuffle([1, 2, 3, 4, 5]) * // Returns: [3, 1, 5, 2, 4] (example, actual order will be random) * * shuffle(['a', 'b', 'c']) * // Returns: ['c', 'a', 'b'] (example, actual order will be random) * * shuffle([]) * // Returns: [] * * shuffle(['single']) * // Returns: ['single'] * ``` */ declare function shuffle(arr: T[]): T[]; /** * Creates a deep clone of an object or array. * * Performs a deep copy by recursively iterating through objects and arrays, * creating new instances with copied primitive values. Uncloneable types * (functions, symbols, etc.) are converted to undefined. Handles circular * references to prevent infinite loops. * * @param obj - The object or array to clone * @param visited - Internal WeakMap for tracking visited objects (used for circular reference detection) * @returns A deep clone of the input * * @example * ```typescript * deepClone({ a: 1, b: { c: 2 } }) * // Returns: { a: 1, b: { c: 2 } } (new object) * * const original = { x: [1, 2, 3], y: { z: 4 } }; * const cloned = deepClone(original); * cloned.x.push(4); * // original.x is still [1, 2, 3] * * deepClone({ fn: () => {}, num: 42 }) * // Returns: { fn: undefined, num: 42 } * ``` */ declare function deepClone(obj: T, visited?: WeakMap): T; /** * Deeply merges two objects based on these rules. * - for every given object key: * - if firstObject has the key but secondObject doesn't, firstObject's value is used * - if secondObject has the key but firstObject doesn't, secondObject's value is used * - if both values are primitive, the secondObject's value will be used * - if both values are objects, they are merged recursively * - if both values are arrays, they are merged based on the arrayMergeStrategy option * - if the values are of different types, the second value will be used * * @param firstObj First object to merge from * @param secondObj Second object to merge into * @param options - Options for merging behavior * @param options.arrayMergeStrategy - Strategy for merging arrays: 'replace' (default) or 'concat' * @returns The merged object */ declare function deepMerge(firstObj: Record, secondObj: Record, options?: { arrayMergeStrategy?: 'replace' | 'concat'; }): Record; /** * Recursively evaluates all nodes in an object using the provided async function. * * Traverses the object and applies the async function to each non-object value, * returning a new object with the evaluated values. If a value is a Promise, * it will be awaited before applying the function. Objects and arrays are processed * recursively. * * @param obj - The object to evaluate * @param func - The async function to apply to each non-object value * @returns A promise that resolves to the new object with evaluated values * * @example * ```typescript * const input = { * a: 1, * b: { * c: 2, * d: [3, 4] * } * }; * * const result = await evaluateAllNodes(input, async (value) => value * 2); * // result is: * // { * // a: 2, * // b: { * // c: 4, * // d: [6, 8] * // } * // } * ``` */ declare function evaluateAllNodes(obj: Record, func: (node: any) => any): Promise>; /** * traverse an object and apply a function to all branches (objects and arrays) * @param obj object to be traversed * @param func function to be applied to each branch * @returns traversed object */ declare function evaluateAllBranches(obj: Record, func: (node: any) => any): Promise>; declare const array_crossJoin: typeof crossJoin; declare const array_deepClone: typeof deepClone; declare const array_deepMerge: typeof deepMerge; declare const array_evaluateAllBranches: typeof evaluateAllBranches; declare const array_evaluateAllNodes: typeof evaluateAllNodes; declare const array_first: typeof first; declare const array_flatten: typeof flatten; declare const array_get: typeof get; declare const array_intersperse: typeof intersperse; declare const array_last: typeof last; declare const array_random: typeof random; declare const array_shuffle: typeof shuffle; declare const array_split: typeof split; declare namespace array { export { array_crossJoin as crossJoin, array_deepClone as deepClone, array_deepMerge as deepMerge, array_evaluateAllBranches as evaluateAllBranches, array_evaluateAllNodes as evaluateAllNodes, array_first as first, array_flatten as flatten, array_get as get, array_intersperse as intersperse, array_last as last, array_random as random, array_shuffle as shuffle, array_split as split }; } declare function isBcryptHash(str: string): boolean; declare function encryptPassword(password: string): Promise; declare function compareBcrypt(password: string, hash: string): Promise; /** * Hash utilities for common cryptographic hashing algorithms */ declare namespace hash { /** * Generates an MD5 hash of the input string * * @param data - The string to hash * @returns The MD5 hash as a hexadecimal string * * @example * ```typescript * hash.md5('hello world') * // Returns: '5eb63bbbe01eeed093cb22bb8f5acdc3' * ``` */ function md5(data: string): string; /** * Generates a SHA-1 hash of the input string * * @param data - The string to hash * @returns The SHA-1 hash as a hexadecimal string * * @example * ```typescript * hash.sha1('hello world') * // Returns: '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed' * ``` */ function sha1(data: string): string; /** * Generates a SHA-256 hash of the input string * * @param data - The string to hash * @returns The SHA-256 hash as a hexadecimal string * * @example * ```typescript * hash.sha256('hello world') * // Returns: 'b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9' * ``` */ function sha256(data: string): string; /** * Generates a SHA-512 hash of the input string * * @param data - The string to hash * @returns The SHA-512 hash as a hexadecimal string * * @example * ```typescript * hash.sha512('hello world') * // Returns: '309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f' * ``` */ function sha512(data: string): string; /** * Generates a SHA3-256 hash of the input string * * @param data - The string to hash * @returns The SHA3-256 hash as a hexadecimal string * * @example * ```typescript * hash.sha3_256('hello world') * // Returns: '644bcc7e564373040999aac89e7622f3ca71fba1d972fd94a31c3bfbf24e3938' * ``` */ function sha3_256(data: string): string; /** * Generates a SHA3-512 hash of the input string * * @param data - The string to hash * @returns The SHA3-512 hash as a hexadecimal string * * @example * ```typescript * hash.sha3_512('hello world') * // Returns: '840006653e9ac9e95117a15c915caab81662918e925de9e004f774ff82d7079a40d4d27b1b372657c61d46d470304c88c788b3a4527ad074d1dccbee5dbaa99a' * ``` */ function sha3_512(data: string): string; } /** * Password hashing and comparison utilities using bcrypt */ declare namespace password { /** * Checks if a string is a valid bcrypt hash * * @param str - The string to check * @returns True if the string is a valid bcrypt hash, false otherwise * * @example * ```typescript * password.isBcryptHash('$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy') * // Returns: true * * password.isBcryptHash('not a hash') * // Returns: false * ``` */ function isBcryptHash(str: string): boolean; /** * Encrypts a password using bcrypt * * @param password - The plain text password to encrypt * @param rounds - The number of rounds to use for salt generation (default: 10) * @returns A promise that resolves to the encrypted password hash * * @example * ```typescript * await password.encryptPassword('mySecurePassword') * // Returns: '$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy' * ``` */ function encryptPassword(password: string, rounds?: number): Promise; /** * Compares a plain text password with a bcrypt hash * * @param password - The plain text password to compare * @param hash - The bcrypt hash to compare against * @returns A promise that resolves to true if the password matches the hash, false otherwise * * @example * ```typescript * await password.comparePassword('myPassword', '$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy') * // Returns: true or false * ``` */ function comparePassword(password: string, hash: string): Promise; } /** * Cryptographic key generation utilities */ declare namespace keys { /** * Generates an RSA key pair * * @param modulusLength - The modulus length in bits (default: 2048) * @returns An object containing the public and private keys in PEM format * * @example * ```typescript * const { publicKey, privateKey } = keys.rsa() * // Returns: { publicKey: '-----BEGIN PUBLIC KEY-----...', privateKey: '-----BEGIN PRIVATE KEY-----...' } * ``` */ function rsa(modulusLength?: number): { publicKey: string; privateKey: string; }; /** * Generates an Ed25519 key pair * * @returns A promise that resolves to an object containing the public and private keys as hex strings * * @example * ```typescript * const { publicKey, privateKey } = await keys.ed25519() * // Returns: { publicKey: '1a2b3c...', privateKey: '9f8e7d...' } * ``` */ function ed25519(): Promise<{ publicKey: string; privateKey: string; }>; } /** * JSON Web Token (JWT) utilities */ declare namespace jwt { /** * Signs a JWT with the provided payload and secret * * @param payload - The payload to encode in the JWT * @param secret - The secret key to sign the JWT with * @param options - Optional JWT sign options (algorithm, expiresIn, etc.) * @returns The signed JWT token * * @example * ```typescript * const token = Enc.jwt.sign({ userId: 123 }, 'mySecret', { expiresIn: '1h' }) * // Returns: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...' * ``` */ function sign(payload: string | object | Buffer, secret: Secret, options?: SignOptions): string; /** * Verifies a JWT token * * @param token - The JWT token to verify * @param secret - The secret key to verify the JWT with * @param options - Optional JWT verify options * @returns The decoded payload if verification succeeds * @throws Will throw an error if verification fails * * @example * ```typescript * try { * const payload = Enc.jwt.verify(token, 'mySecret') * console.log(payload) // { userId: 123, iat: 1234567890, exp: 1234571490 } * } catch (err) { * console.error('Invalid token') * } * ``` */ function verify(token: string, secret: Secret, options?: VerifyOptions): string | JwtPayload; /** * Decodes a JWT token without verifying its signature * * @param token - The JWT token to decode * @param options - Optional decode options * @returns The decoded payload or null if the token is invalid * * @example * ```typescript * const payload = Enc.jwt.decode(token) * // Returns: { userId: 123, iat: 1234567890, exp: 1234571490 } * ``` */ function decode(token: string, options?: DecodeOptions): null | string | JwtPayload; } /** * Digital signature utilities */ declare namespace sign { /** * Signs data using Ed25519 private key * * @param privateKey - The Ed25519 private key as a hex string * @param data - The data to sign * @returns A promise that resolves to the signature as a hex string * * @example * ```typescript * const { privateKey } = await keys.ed25519() * const signature = await sign.ed25519(privateKey, 'message to sign') * // Returns: 'a1b2c3d4...' * ``` */ function ed25519(privateKey: string, data: string): Promise; /** * Verifies an Ed25519 signature * * @param publicKey - The Ed25519 public key as a hex string * @param signature - The signature to verify as a hex string * @param data - The original data that was signed * @returns A promise that resolves to true if the signature is valid, false otherwise * * @example * ```typescript * const isValid = await sign.verifyEd25519(publicKey, signature, 'message to sign') * // Returns: true or false * ``` */ function verifyEd25519(publicKey: string, signature: string, data: string): Promise; } declare const enc_hash: typeof hash; declare const enc_jwt: typeof jwt; declare const enc_keys: typeof keys; declare const enc_password: typeof password; declare const enc_sign: typeof sign; declare namespace enc { export { enc_hash as hash, enc_jwt as jwt, enc_keys as keys, enc_password as password, enc_sign as sign }; } interface EventEmittor { on(event: T[number], listener: (...args: any[]) => void): this; off(event: T[number], listener: (...args: any[]) => void): this; emit(event: T[number], ...args: any[]): Promise; } declare class EventManager implements EventEmittor { private listeners; on(event: T[number], listener: (...args: any[]) => void): this; off(event: T[number], listener: (...args: any[]) => void): this; emit(event: T[number], ...args: any[]): Promise; } declare class EventEmittorBase implements EventEmittor { protected event_manager: EventManager; on(event: T[number], listener: (...args: any[]) => void): this; off(event: T[number], listener: (...args: any[]) => void): this; emit(event: T[number], ...args: any[]): Promise; } interface FlexibleFactoryInterface { register(key: string, factory: (...args: any[]) => T): void; create(key: string, ...args: any[]): Promise; } declare class FlexibleFactory { registry: Map; register(key: string, ctor: (...args: any[]) => T): void; create(key: string, ...args: any[]): T; } /** * Abbreviates large numbers with appropriate suffixes (K, M, B, T, etc.). * * Converts numbers to abbreviated format using standard suffixes: * - K for thousands (1,000+) * - M for millions (1,000,000+) * - B for billions (1,000,000,000+) * - T for trillions (1,000,000,000,000+) * * @param num - The number to abbreviate * @returns The abbreviated number string with appropriate suffix * * @example * ```typescript * abbreviate(1000) // "1K" * abbreviate(1500) // "1.5K" * abbreviate(1000000) // "1M" * abbreviate(2500000) // "2.5M" * abbreviate(999) // "999" * ``` */ declare function abbreviate(num: number): string; /** * Clamps a number between minimum and maximum values. * * Ensures that the input number falls within the specified range. * If the number is below the minimum, returns the minimum. * If the number is above the maximum, returns the maximum. * Otherwise, returns the original number. * * @param num - The number to clamp * @param min - The minimum allowed value * @param max - The maximum allowed value * @returns The clamped number within the specified range * * @example * ```typescript * clamp(5, 1, 10) // 5 * clamp(-5, 1, 10) // 1 * clamp(15, 1, 10) // 10 * clamp(7.5, 0, 5) // 5 * ``` */ declare function clamp(num: number, min: number, max: number): number; /** * Formats a number as currency with proper locale formatting. * * Converts a numeric value to a formatted currency string using * the browser's Intl.NumberFormat API. Supports different currencies * and uses appropriate locale-specific formatting. * * @param num - The number to format as currency * @param currency - The currency code (ISO 4217) to use for formatting * @returns The formatted currency string * * @example * ```typescript * currencyFormat(1234.56) // "$1,234.56" (in USD) * currencyFormat(1234.56, 'EUR') // "€1,234.56" (in EUR) * currencyFormat(1000, 'GBP') // "£1,000.00" (in GBP) * currencyFormat(0) // "$0.00" * ``` */ declare function currencyFormat(num: number, currency?: string): string; /** * Formats a number of bytes into a human-readable file size string. * * Converts byte values to appropriate units (B, KB, MB, GB, TB, PB, EB, ZB, YB) * with proper decimal formatting. Uses binary (1024) units for conversion. * * @param num - The number of bytes to format * @returns The formatted file size string with appropriate unit * * @example * ```typescript * fileSize(1024) // "1 KB" * fileSize(1536) // "1.5 KB" * fileSize(1048576) // "1 MB" * fileSize(500) // "500 B" * fileSize(0) // "0 B" * ``` */ declare function fileSize(num: number): string; /** * Formats a number with specified decimal places and thousands separators. * * Converts a number to a string with the specified number of decimal places * and includes thousands separators for better readability. * * @param num - The number to format * @param decimalPlaces - The number of decimal places to show (default: 2) * @returns The formatted number string with separators * * @example * ```typescript * format(1234.5678) // "1,234.57" * format(1234.5678, 1) // "1,234.6" * format(1000000) // "1,000,000.00" * format(42, 0) // "42" * ``` */ declare function format(num: number, decimalPlaces?: number): string; /** * Converts a number to its ordinal string representation. * * Adds the appropriate ordinal suffix (st, nd, rd, th) to a number * based on English ordinal number rules. * * @param num - The number to convert to ordinal form * @returns The ordinal string representation of the number * * @example * ```typescript * ordinal(1) // "1st" * ordinal(2) // "2nd" * ordinal(3) // "3rd" * ordinal(4) // "4th" * ordinal(21) // "21st" * ordinal(22) // "22nd" * ordinal(23) // "23rd" * ordinal(101) // "101st" * ``` */ declare function ordinal(num: number): string; /** * Parses a string or number to extract a numeric value. * * Attempts to parse a string representation of a number or return * the numeric value if already a number. Returns undefined if the * input cannot be parsed to a valid number. Properly handles the * case where the input is 0. * * @param str - The string, number, or undefined to parse as a number * @returns The parsed number or undefined if parsing fails * * @example * ```typescript * parse("123") // 123 * parse("123.45") // 123.45 * parse("-42") // -42 * parse("1,234") // 1234 * parse("0") // 0 * parse(0) // 0 * parse(42) // 42 * parse("not a number") // undefined * parse("") // undefined * parse(undefined) // undefined * ``` */ declare function parse(str: string | number | undefined): number | undefined; /** * Converts a number to its written English word representation. * * Transforms numeric values into their English word equivalents. * Supports integers and handles negative numbers appropriately. * * @param num - The number to convert to words * @returns The written English representation of the number * * @example * ```typescript * spell(42) // "forty-two" * spell(100) // "one hundred" * spell(1001) // "one thousand one" * spell(-5) // "minus five" * spell(0) // "zero" * ``` */ declare function spell(num: number): string; /** * Converts a number to its written English ordinal word representation. * * Transforms numeric values into their English ordinal word equivalents * (first, second, third, etc.). Supports positive integers. * * @param num - The number to convert to ordinal words * @returns The written English ordinal representation of the number * * @example * ```typescript * spellOrdinal(1) // "first" * spellOrdinal(2) // "second" * spellOrdinal(3) // "third" * spellOrdinal(21) // "twenty-first" * spellOrdinal(100) // "one hundredth" * ``` */ declare function spellOrdinal(num: number): string; /** * Rounds a number or array of numbers to a specified precision. * * Provides flexible rounding capabilities with configurable precision and rounding method. * Supports single numbers or arrays of numbers, returning the same type as the input. * Handles NaN values gracefully by preserving them in the output. * * Precision can be positive (decimal places), zero (nearest integer), or negative * (rounding to tens, hundreds, etc.). * * @param number - The number or array of numbers to round * @param options - Configuration options for rounding behavior * @param options.precision - Number of decimal places to round to (default: 1) * - Positive: round to decimal places (e.g., 2 = 0.01, 3 = 0.001) * - Zero: round to nearest integer * - Negative: round to tens, hundreds, etc. (e.g., -1 = 10, -2 = 100) * @param options.method - Rounding method to use: 'round' (default), 'ceil', or 'floor' * @returns The rounded number or array of numbers, matching the input type * * @example * ```typescript * // Basic rounding with default precision (1 decimal place) * round(3.14159) // 3.1 * round(2.718) // 2.7 * * // Custom precision * round(3.14159, {precision: 2}) // 3.14 * round(3.14159, {precision: 0}) // 3 * round(1.23456, {precision: 3}) // 1.235 * * // Negative precision (round to tens, hundreds, etc.) * round(1234.5678, {precision: -1}) // 1230 * round(1234.5678, {precision: -2}) // 1200 * round(1234.5678, {precision: -3}) // 1000 * * // Different rounding methods * round(3.14159, {precision: 2, method: 'round'}) // 3.14 * round(3.14159, {precision: 2, method: 'ceil'}) // 3.15 * round(3.14159, {precision: 2, method: 'floor'}) // 3.14 * round(1234, {precision: -1, method: 'ceil'}) // 1240 * round(1234, {precision: -1, method: 'floor'}) // 1230 * * // Array of numbers * round([3.14159, 2.71828], {precision: 2}) // [3.14, 2.72] * round([1.1, 2.2, 3.3], {precision: 0}) // [1, 2, 3] * round([1234, 5678], {precision: -2}) // [1200, 5700] * * // Handles NaN * round(NaN) // NaN * round([1.5, NaN, 2.7], {precision: 0}) // [2, NaN, 3] * ``` */ declare function round(number: number, options?: { precision?: number; method?: 'round' | 'ceil' | 'floor'; }): number; declare function round(number: number[], options?: { precision?: number; method?: 'round' | 'ceil' | 'floor'; }): number[]; declare const number_abbreviate: typeof abbreviate; declare const number_clamp: typeof clamp; declare const number_currencyFormat: typeof currencyFormat; declare const number_fileSize: typeof fileSize; declare const number_format: typeof format; declare const number_ordinal: typeof ordinal; declare const number_parse: typeof parse; declare const number_round: typeof round; declare const number_spell: typeof spell; declare const number_spellOrdinal: typeof spellOrdinal; declare namespace number { export { number_abbreviate as abbreviate, number_clamp as clamp, number_currencyFormat as currencyFormat, number_fileSize as fileSize, number_format as format, number_ordinal as ordinal, number_parse as parse, number_round as round, number_spell as spell, number_spellOrdinal as spellOrdinal }; } /** * create a singleton using the function provided. * @param func - a function that will be called to create the instance. * @returns A function that return a singleton instance of the type T for a given label. */ declare function createSingleton(func: (...args: any[]) => T): (label?: string, ...args: any[]) => T; /** * given a function fn, repeat it every interval milliseconds. * rc.start() to start the repeater * rc.stop() to stop the repeater * createRepeater(fn, 5000); // run fn every 5 seconds * @param fn * @param interval * @returns */ declare function createRepeater(fn: Function, interval: number): { start(): void; stop(): void; }; type StepFn = (value: I, ...args: A) => O | Promise; declare class Chainer extends Promise { private chainPromise; constructor(initial: T); step(fn: StepFn, ...args: any[]): Chainer; s(fn: StepFn, ...args: any[]): Chainer; static from(initial: T): Chainer; } /** * chains multiple functions/steps together. Each step can be synchronous or asynchronous. * Each step receives the result of the previous step as the first parameter. more parameters can be passed after that. * To calculate the final result, use `await` on the returned Chainer. * @param initial initial value to start * @returns final result * @example * ```ts * import { chainer } from "@devbro/pashmak/helpers"; * const add = (x: number, y: number, z: number) => x + y + z; * const multiply = (x: number, y: number) => x * y; * * const result = await chainer(4) * .step(add, 2, 0) // 4 + 2 = 6 * .step(multiply, 3) // 6 * 3 = 18 */ declare function chainer(initial: T): Chainer; /** * Checks if a variable is a class constructor. * @param variable - The variable to check * @returns True if the variable is a class, false otherwise */ declare function isClass(variable: any): boolean; /** * Checks if a variable is a function (but not a class constructor). * @param variable - The variable to check * @returns True if the variable is a function and not a class, false otherwise */ declare function isFunction(variable: any): boolean; declare const sleep: (ms: number) => Promise; type JSONValue = string | number | boolean | null | undefined | JSONObject | JSONArray; interface JSONObject { [key: string]: JSONValue; } type JSONArray = JSONValue[]; declare function getEnv(key: string, ...defaultValue: string[]): string | undefined; export { array as Arr, enc as Enc, type EventEmittor, EventEmittorBase, EventManager, FlexibleFactory, type FlexibleFactoryInterface, type JSONArray, type JSONObject, type JSONValue, number as Num, chainer, compareBcrypt, createRepeater, createSingleton, encryptPassword, getEnv, isBcryptHash, isClass, isFunction, sleep };