UNPKG

sussy-util

Version:
103 lines (102 loc) 4.05 kB
declare class Random { readonly defaultCharset: string; private static readonly instance; private constructor(); /** * It returns a random integer between the lower and upper bounds, inclusive. * * min <= n < max * @param [lower=0] - The lowest number that can be returned. * @param [upper=10] - The upper bound of the random number. * @returns A random integer between the lower and upper bounds. */ randomInt(lower?: number, upper?: number): number; /** * Generates a random double (floating-point) number within a specified range. * @param {number} lower - The lower bound of the random number. * @param {number} upper - The upper bound of the random number. * @returns {number} A random double within the specified range. */ randomDouble(lower: number, upper: number): number; /** * Returns a random character from a given string or the default charset. * * @param {string} [charset] - The character set to use. Defaults to the default charset. * @returns {string} A random character from the charset. */ randomChar(charset?: string): string; /** * Generates a random string of specified length from a given charset or the default charset. * * @param {number} [length=10] - The length of the string to be generated. * @param {string} [charset] - The characters to use when generating the string. Defaults to the default charset. * @returns {string} A string of random characters. */ randomString(length?: number, charset?: string): string; /** * It returns a random element from an array. * @param {T[]} arr - T[] - The array to get a random element from. * @returns The return type is T. */ randomElement<T>(arr: T[]): T; /** * It returns a random element from an array. * @param {T[]} arr - The array to choose a random element from. * @param {number} start - The start index of the range. * @param {number} end - The index of the last element in the range. * @returns The random element in the array. */ randomElementInRange<T>(arr: T[], start: number, end: number): T; /** * Generates a random element from an object by selecting a random property. * @param {T} obj - The object to choose a random property from. * @returns The value of a random property in the object. */ randomProperty<T extends object>(obj: T): T[keyof T]; /** * Generates a random boolean value. * @returns A random boolean value. */ randomBoolean(): boolean; /** * Generates a random color in hexadecimal format (#RRGGBB). * * @returns {string} A random color in hexadecimal format. */ randomColor(): string; /** * Generates a random RGB color array [r, g, b]. * * @returns {number[]} A random RGB color array. */ randomRgbColor(): number[]; /** * Generates a random UUID (Universally Unique Identifier). * * @returns {string} A random UUID. */ randomUUID(): string; /** * Generates a random date within a specified range. * * @param {Date} startDate - The start date of the range. * @param {Date} endDate - The end date of the range. * @returns {Date} A random date within the specified range. */ randomDate(startDate: Date, endDate: Date): Date; static getInstance(): Random; /** * Returns a random value from an enum. * @param {T} enumObject - The enum to choose a random value from. * @returns The random value from the enum. */ randomEnumValue<T extends object>(enumObject: T): T[keyof T]; /** * Generates a random date in the past within a specified range. * @param {number} yearsAgo - The number of years ago the date can be. * @returns {Date} A random date in the past within the specified range. */ randomDateInPast(yearsAgo: number): Date; } declare const _default: Random; export default _default;