Skip to content

Instantly share code, notes, and snippets.

@clintonhalpin
Created September 18, 2015 19:16
Show Gist options
  • Select an option

  • Save clintonhalpin/da4d794a809538d7f5f1 to your computer and use it in GitHub Desktop.

Select an option

Save clintonhalpin/da4d794a809538d7f5f1 to your computer and use it in GitHub Desktop.
import faker from 'faker';
import moment from 'moment';
import _ from 'lodash';
export let generateFakeData = function(model, num = 5) {
let res = [];
if(!_.isFunction(model)) {
throw "You must pass in a model, with type Function"
}
for(let i = 0; i < num; i++) {
let newModel = new model();
for(var prop in newModel) {
if(_.isObject(newModel[prop])) {
switch(newModel[prop].type) {
case "random":
newModel[prop] = _.sample(newModel[prop].arr);
break;
default:
break;
}
}
}
res.push(newModel);
}
return res;
}
let model = function() {
this.name = faker.fake('{{name.lastName}} {{name.firstName}}');
this.description = faker.fake('{{hacker.phrase}}')
this.owner = faker.fake('{{name.lastName}} {{name.firstName}}');
this.status = {
type: "random",
arr: ["Active", "Disabled"]
}
return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment