ts-randomizer
Version:
A tool to create random data by type parameters
38 lines (37 loc) • 1.27 kB
TypeScript
import { TypeDescription } from '../types';
type Mutator<T> = (x: T | null) => unknown;
export type BasicType = string | number | boolean | object | Date | Function;
export type Value<T> = T extends BasicType ? BasicType : T;
/**
* Creates anonymous variables by description of T.
*/
export declare class SpecimenFactory<T> {
private readonly input;
private readonly mutators;
private readonly arrayValueCount;
/**
* @param input The description of type to create.
*/
constructor(input: TypeDescription);
/**
* Creates an variable of the requested type.
* @returns An anonymous variable of type T.
*/
create(): T;
/**
* Creates many anonymous objects.
* @returns A sequence of anonymous object of type T.
*/
createMany(minCount?: number, maxCount?: number): T[];
/**
* Registers that a writable property or field should be assigned an anonymous value
* as part of specimen post-processing.
* @param func An expression that identifies the property or field that will should have a value assigned.
*/
with(func: Mutator<T>): this;
private generate;
private generatePropertyValue;
private generatePropertiesValues;
private generateValue;
}
export {};