-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-data.js
51 lines (43 loc) · 1.32 KB
/
generate-data.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
/***
* dreamjs - fake data generator - https://github.com/adleroliveira/dreamjs
* jsonfile - module for writing json data to file - https://www.npmjs.com/package/jsonfile
***/
const dream = require('dreamjs');
const jsonfile = require('jsonfile');
/***
* path - output for generated file
* amount - number of generated objects
* phraseLength - number of words for phrase property
* images - array of all available images
***/
const config = {
path: './public/data.json',
amount: 150,
phraseLength: 15,
images: ['cat', 'dog', 'fox', 'koala', 'lion', 'owl', 'penguin', 'pig', 'raccoon', 'sheep']
};
dream.customType('user-image', function (helper) {
return helper.oneOf(config.images);
});
dream.customType('user-phrase', function (helper) {
return helper.chance.sentence({words: config.phraseLength});
});
dream.customType('incrementalId', function(helper){
return helper.previousItem ? helper.previousItem.id+1 : 0;
});
dream.schema('user', {
id: 'incrementalId',
name: 'name',
age: 'age',
phone: 'phone',
image: 'user-image',
phrase: 'user-phrase'
});
dream.useSchema('user')
.generateRnd(config.amount)
.output((err, result) => {
jsonfile.writeFile(config.path, result, function(err) {
console.log(err ? err : `Data was generated and placed to ${config.path}`);
});
});