mochine
Mock engine: a generator for simulating data. mochine could help simulate the data you describe.
Install
in npm
npm install mochine
in browser
Usage
Usage 1: Using [[DESCRIPTOR]]
; // npm usage; Mochine is defined on window if using in browserconst Mock = ;// Then, see Demo below
[[DESCRIPTOR]]
DESCRIPTOR = DESC || ;
[[DESC]]
DESC = name: DESCRIPTION;
[[DESCRIPTION]]
Generate an integer
DESCRIPTION = "int([[MIN]], [[MAX]])" MIN: minimal integer default 0MAX: maximal integer default 100
Generate a number(decimal or integer)
DESCRIPTION = "int([[MIN]], [[MAX]])" MIN: minimal number default 0MAX: maximal number default 100
Generate a string
DESCRIPTION = "string([[MIN]], [[MAX]])" MIN: minimal length of the generated string default 0MAX: maximal length of the generated string default 12
Generate a boolean
DESCRIPTION = "bool()"
Generate a enumeration
DESCRIPTION = "enum([e1, e2, ..., en])" || "enum(e1, e2, ..., en)" e1 ~ en: Mochine will pick one from them when mocking util now en only support number or string
Generate a date
DESCRIPTION = "date([[FORMAT]], [[START]], [[END]])" FORMAT: default 'YYYY-MM-DD' use tokens Y M D H I Sto represent year month day hour minute second YYYY will get a full yearYYY will only get last and so on and so it is withothers START: minimal date default formated string such as "2016/10/01 10:20:30"END: maximal date default + 30 formated string such as "2016/10/10 10:20:30" Mochine will pick one date between START and END when mocking
Generate an array
DESCRIPTION = "array([[LENGTH]], [[GEN]])" LENGTH: length of the generated array default 10but if LENGTH is a `function`and LENGTH will be change to be GEN GEN: array elements DESCRIPTION any one of DESCRIPTION introduced abovedefault 'string()'
Generate self-defined data
Cooming next
Usage 2: Using Typegines
; // npm usage; Mochine is defined on window if using in browserconst Mock = ;// Then, see Demo below
Typegines
has all type methods corresponding to [[DESCRIPTION]]
above with same arguments.
Demo
const Mock = ; const Me = ;const MyClassmate = ; // [[!!IMPORTANT!!]] also, you can mock just the sub-data const name = Mockname;const birthday = Mock;const location = Mocklocation;const lat = Mocklocation0;