UNPKG

@jsonjoy.com/json-random

Version:

Random JSON generation, structured JSON by schema generation, no dependencies.

75 lines (74 loc) 1.82 kB
import { type Token } from './string'; type JsonValue = unknown; /** @ignore */ export type NodeType = 'null' | 'boolean' | 'number' | 'string' | 'binary' | 'array' | 'object'; export interface NodeOdds { null: number; boolean: number; number: number; string: number; binary: number; array: number; object: number; } export interface RandomJsonOptions { rootNode: 'object' | 'array' | 'string' | undefined; nodeCount: number; odds: NodeOdds; strings?: Token; } type ContainerNode = unknown[] | object; /** * Create a random JSON value. * * ```ts * RandomJson.generate() * ``` */ export declare class RandomJson { static generate(opts?: Partial<RandomJsonOptions>): JsonValue; static genBoolean(): boolean; static genNumber(): number; static genString(length?: number): string; static genBinary(length?: number): Uint8Array; static genArray(options?: Partial<Omit<RandomJsonOptions, 'rootNode'>>): unknown[]; static genObject(options?: Partial<Omit<RandomJsonOptions, 'rootNode'>>): object; /** @ignore */ opts: RandomJsonOptions; /** @ignore */ private totalOdds; /** @ignore */ private oddTotals; /** @ignore */ root: JsonValue; /** @ignore */ private containers; /** * @ignore */ constructor(opts?: Partial<RandomJsonOptions>); /** * @ignore */ create(): JsonValue; /** * @ignore */ addNode(): void; /** * @ignore */ protected generate(type: NodeType): unknown; protected generateString(): string; /** @ignore */ pickNodeType(): NodeType; /** * @ignore */ protected pickContainerType(): 'array' | 'object'; /** * @ignore */ protected pickContainer(): ContainerNode; } export {};