UNPKG

json-response-gen

Version:

Repo for some utility functions to generate random data when you know the shape of data samples but cant get it

163 lines (144 loc) 5.8 kB
declare const SELECTION_TYPES: Readonly<{ IN_ORDER: "IN_ORDER"; RANDOM: "RANDOM"; }>; declare const DAY_RANGE: Readonly<{ 1: 31; 2: 28; 3: 31; 4: 30; 5: 31; 6: 30; 7: 31; 8: 31; 9: 30; 10: 31; 11: 30; 12: 31; LEAP: 29; }>; declare const DEFAULT_MOCKS_DIR = "__jgen__/mocks"; type InputType = object | any[]; type OutputType = object | any[]; type SelectionType = keyof typeof SELECTION_TYPES; type BuildProps = { repetitions?: number; selectionType?: SelectionType; writeDir?: string; addSharedValue?: (key: string, value: any) => void; getSharedValue?: (key: string) => any; getFromGeneration?: (key: string, genNumber?: number) => any; }; type Options = { build(buildOptions?: BuildProps, extraInfo?: {}): any | any[]; test(value: any): boolean; }; type RepetitionProps = { repetitions?: number; baseArrayPath?: string; sharedKeysMap?: { toShare?: string[]; toRename?: { [key: string]: string[]; }; }; }; type OptionProps = { shouldSpread?: boolean; selectionType?: string; }; type SharedProps = { shouldSpread?: boolean; value?: any; }; declare const handleValue: (value: any, buildOptions: BuildProps, extraInfo?: {}) => any; declare const handleObject: (shape: object, buildOptions: BuildProps, extraInfo?: {}) => object; declare const get: (obj: object | string, path: string[] | string, defaultValue: any) => any; declare function noop(): void; declare function implementsOptions(object: any): object is Options; declare const hasTestFunc: (value: any) => value is Options; declare const isLeapYear: (year: number) => boolean; declare const getDay: (month: number, year: number) => number; declare const conditionalDatePrefix: (dateNumber: number, prefix?: string) => string; declare const toReverseLookupMap: (lookupMap?: Object) => { [key: string]: string; }; declare const shouldGetFromExtraDetails: (path: string) => [boolean, string]; declare const prepDirs: (str: string, writeDir?: string) => string; declare class DateRange implements Options { range: number; maxToday: boolean; constructor(range: number, maxToday?: boolean); build(buildOptions?: BuildProps, extraInfo?: {}): string; b: (buildOptions?: BuildProps, extraInfo?: {}) => string; test(value: string): boolean; } declare class Option implements Options { selectionType?: string; array: any[]; nextIdx: number; shouldSpread?: boolean; constructor(array: any[], options?: OptionProps); build(buildOptions: BuildProps, extraInfo?: {}): any; b: (buildOptions: BuildProps, extraInfo?: {}) => any; test(value: any): boolean; } declare class Repetition implements Options { shape: any; options?: RepetitionProps; sharedOptions?: boolean; constructor(shape: any, options?: RepetitionProps); build(buildOptions: BuildProps, extraInfo?: {}): any[]; b: (buildOptions: BuildProps, extraInfo?: {}) => any[]; buildShared(buildOptions: BuildProps, extraInfo?: {}): any[]; test(value: any[]): boolean; } declare class Regex implements Options { pattern: RegExp; constructor(pattern: RegExp); build(buildOptions?: BuildProps, extraInfo?: {}): string; b: (buildOptions?: BuildProps, extraInfo?: {}) => string; test(value: any): boolean; } declare class Builder { results: OutputType[]; options: BuildProps; valueMap: Map<string, any>; constructor(options?: BuildProps); addResult: (result: OutputType) => void; getResult: (index?: number) => OutputType; getResults: () => OutputType[]; addSharedValue: (key: string, value: any) => void; getSharedValue: (key: string) => any; getFromGeneration: (key: string, genNumber?: number) => any; build: (shape: InputType, fileName?: string) => Builder; b: (shape: InputType, fileName?: string) => Builder; } declare class Shared implements Options { key: string; value: any; shouldSpread?: boolean; constructor(key: string, options?: SharedProps); build(buildOptions: BuildProps, extraInfo?: {}): any | any[]; b: (buildOptions: BuildProps, extraInfo?: {}) => any | any[]; test(value: any): boolean; } declare class Custom implements Options { callback: Function; shouldSpread: boolean; constructor(callback: Function, shouldSpread?: boolean); build(buildOptions?: BuildProps, extraInfo?: {}): string; b: (buildOptions?: BuildProps, extraInfo?: {}) => string; test(value: string): boolean; } declare const ALPHA_PHRASE: (wordCount: number) => Custom; declare const UPPER_ALPHA: (min: number, max?: number) => Regex; declare const LOWER_ALPHA: (min: number, max?: number) => Regex; declare const ALPHA: (min: number, max?: number) => Regex; declare const ALPHA_1: (min: number, max?: number) => Regex; declare const LOWER_ALPHA_NUMERIC: (min: number, max?: number) => Regex; declare const UPPER_ALPHA_NUMERIC: (min: number, max?: number) => Regex; declare const ALPHA_NUMERIC: (min: number, max?: number) => Regex; declare const NUMERIC: (min: number, max?: number) => Regex; declare const EMAIL: (length?: number, domain?: string) => Custom; export { ALPHA, ALPHA_1, ALPHA_NUMERIC, ALPHA_PHRASE, type BuildProps, Builder, Custom as C, Custom, DAY_RANGE, DEFAULT_MOCKS_DIR, DateRange, EMAIL, type InputType, LOWER_ALPHA, LOWER_ALPHA_NUMERIC, NUMERIC, Option, type OptionProps, type Options, type OutputType, Regex, Repetition, type RepetitionProps, SELECTION_TYPES, type SelectionType, Shared, type SharedProps, UPPER_ALPHA, UPPER_ALPHA_NUMERIC, conditionalDatePrefix, get, getDay, handleObject, handleValue, hasTestFunc, implementsOptions, isLeapYear, noop, prepDirs, shouldGetFromExtraDetails, toReverseLookupMap };