model-golem
A model factory JS library to generate data mocks
Installing
npm install --save-dev model-golem
Using
Load the Factory:
// NodeJS / CommonJS Modulesvar Factory = ; // ES2015 Modules;
Define a model:
var Person = { // this.sequence is autoincremented on every creation step, starts from 0 return thissequence; } // Define the attributes giving their default values name: '' charisma: 42 // Reuse attributes { return thisitemname; };
Instantiate the Factory with your model:
var peopleFactory = Person;
Create your mocks!
var person = ; /* person === { id: 0, name: 'Leo Balter', charisma: 42, username: 'leobalter' }*/
Create your mocks from arrays!
var people = ; /* people === [ { id: 2, name: 'Green Avocados', charisma: 0, username: 'greenavocados' }, { id: 100, name: 'Spicy Mustard', charisma: 37, username: 'mryellow' } ]*/
Get the stored data!
var stored = peopleFactorystore; /* stored === [ { id: 1, name: 'Leo Balter', charisma: 42, username: 'leobalter' }, { id: 2, name: 'Green Avocados', charisma: 0, username: 'greenavocados' }, { id: 100, name: 'Spicy Mustard', charisma: 37, username: 'mryellow' } ]*/