-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfakeDataGenerator.js
59 lines (51 loc) · 1.16 KB
/
fakeDataGenerator.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
52
53
54
55
56
57
58
59
const faker = require('faker')
const fs = require('fs')
const path = require('path')
const data = {}
function randomGender() {
const rand = Math.round(Math.random())
return rand ? 'Male' : 'Female'
}
function randomAge() {
return Math.floor(Math.random() * 101)
}
function randomType() {
const rand = Math.floor(Math.random() * 5)
if (rand <= 3) {
return 'Developer'
} else {
return 'Non Profit'
}
}
function randomDate() {
const rand = Math.floor(Math.random() * 7)
if (rand <= 3) {
return faker.date.recent()
}
if (rand <= 5) {
return faker.date.past()
} else {
return faker.date.future()
}
}
function userGenerator(num) {
let id = 1
let users = []
for (let i = 0; i < num; i++) {
users.push({
id,
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
joinDate: randomDate(),
phoneNumber: faker.phone.phoneNumber(),
email: faker.internet.email(),
sex: randomGender(),
age: randomAge(),
type: randomType()
})
id += 1
}
return users
}
data.users = userGenerator(1000)
fs.writeFileSync(path.resolve('server', 'data.json'), JSON.stringify(data))