@jsonjoy.com/json-random
Version:
Random JSON generation, structured JSON by schema generation, no dependencies.
32 lines (31 loc) • 1.11 kB
TypeScript
/**
* Tokens used to specify random string generation options
*/
export type Token = TokenLiteral | TokenPick | TokenRepeat | TokenChar | TokenList;
/**
* A string literal to use as-is.
*/
export type TokenLiteral = string;
/**
* Picks a random token from the provided tokens.
*/
export type TokenPick = [type: 'pick', ...from: Token[]];
/**
* Repeats `pattern` a random number of times between `min` and `max`.
*/
export type TokenRepeat = [type: 'repeat', min: number, max: number, pattern: Token];
/**
* Specifies a Unicode code point range from which to pick a random character.
* The `count` parameter specifies how many characters to pick, defaults to 1.
*/
export type TokenChar = [type: 'char', min: number, max: number, count?: number];
/**
* Executes a list of `every` tokens in sequence.
*/
export type TokenList = [type: 'list', ...every: Token[]];
/**
* Generates a random string based on the provided token.
* @param token The token defining the random string generation.
* @returns A randomly generated string.
*/
export declare function randomString(token: Token): string;