UNPKG

shelving

Version:

Toolkit for using data in JavaScript.

17 lines (16 loc) 981 B
import type { ImmutableArray } from "./array.js"; /** Generate a random integer between two numbers. */ export declare function getRandom(min?: number, max?: number): number; /** Get a random number that is anything except an existing number. */ export declare function getRandomExcept(existing: number, min?: number, max?: number): number; /** * Make a random key, e.g. `xs23r34hhsdx` or `e4m29klrugef` * - Not designed to be cryptographically random! * - Will probably clash — if you're making a random ID, check for existence of the record before saving. * - Designed to be semi-readable, doesn't use capital letters or `i` or `o` or `l` or `u` */ export declare function getRandomKey(length?: number): string; /** Get a random character from a string. */ export declare function getRandomCharacter(str: string): string; /** Get a random item from an array or random character from a string string. */ export declare function getRandomItem<T>(arr: ImmutableArray<T>): T;