UNPKG

@grandom/string

Version:

A configurable, flexible, seedable, and overall great random string generator.

78 lines (77 loc) 2.21 kB
import { RandomGenerator } from '@grandom/core'; import { type Filter } from '../StringFilter'; export interface ConfigOptions { filter?: { include?: Filter; exclude?: Filter; }; bias?: number; } type RandomStringOptions = { length?: number | [number, number] | { minimum?: number; maximum?: number; }; } & ConfigOptions; export default class RandomString extends RandomGenerator { /** * The default length of a random string. * * @default 16 */ static DEFAULT_LENGTH: number; /** * Numbers set. * * @default '0123456789' */ static NUMBERS: string; /** * Letters set. * * @default 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' */ static LETTERS: string; /** * Letters and numbers. * * @default 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' */ static ALPHANUMERIC: string; /** * Generates a random **16 character long** string consisting * of alphanumeric characters **(A-Za-z0-9)**. */ string(): string; /** * Generates a random string consisting * of alphanumeric characters **(A-Za-z0-9)**. * * @param length The length of the randomly generated string. */ string(length: number): string; /** * Generates a random string. * * @param length The length of the randomly generated string. * @param options Random string generation options. */ string(length: number, options: ConfigOptions): string; /** * Generates a random string **between minimum and maximum**. * * @param minimum The minimum length of the randomly generated string * ***(inclusive)***. * @param maximum The maximum length of the randomly generated string * ***(inclusive)***. * @param options Random string generation options. */ string(minimum: number, maximum: number, options: ConfigOptions): string; /** * Generates a random string. * * @param options Random string generation options. */ string(options: RandomStringOptions): string; } export {};