UNPKG

datum-focus

Version:

Data shape, model, metadata, JSON, JSON Schema, GraphQL, MongoDB query and aggregations, iterator generators

72 lines (68 loc) 1.57 kB
import { v4 as guid } from "uuid"; import { BOOLEAN } from "../../boolean"; import { FLOAT } from "../../float"; import { INTEGER } from "../../number"; import { DATE_STR, EMAIL, GUID, NAME, PASSWORD, REGEX, STRING, URL, USERNAME } from "../../string"; import boolean from './boolean'; import date from "./date"; import email from "./email"; import float from "./float"; import int from "./integer"; import password from './password'; import phrase from './phrase'; import regex from './regex'; import url from './url'; import username from './username'; import word from "./word"; export function valueArray(type: string, count: number) { const ret: any[] = []; for (let i = 0; i < count; i++) { ret.push(value(type)); } return ret; } export function valueDictionary(type: string, count: number, keyType: string = GUID) { const ret = {}; for (let i = 0; i < count; i++) { Object.assign(ret, { [value(keyType)]: value(type) }); } return ret; } export default function value(type: string): any { switch (type) { case BOOLEAN: return boolean(); case DATE_STR: return date(); case EMAIL: return email(); case FLOAT: return float; case GUID: return guid(); case INTEGER: return int({ max: 99, min: 1 }); case NAME: return word(); case PASSWORD: return password(); case REGEX: return regex(); case STRING: return phrase(); case URL: return url(); case USERNAME: return username(); } }