Created
September 18, 2015 19:16
-
-
Save clintonhalpin/da4d794a809538d7f5f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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