-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerateData.js
executable file
·51 lines (47 loc) · 1.24 KB
/
generateData.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
/**
* Generate fake context data.
* Data is directed to STDOUT, to use with the context playground application redirect output
* to ./src/data.js.
* For example:
* $> node generateData.js > ./src/data.js
*/
const { faker } = require("@faker-js/faker");
function createRandomUser() {
return {
kind: "multi",
user: {
key: faker.string.uuid(),
name: faker.person.fullName(),
state: faker.location.state(),
city: faker.location.city(),
country: faker.location.country(),
},
subscription: {
key: faker.helpers.arrayElement(["free", "basic", "pro", "enterprise"]),
},
application: {
key: faker.helpers.arrayElement([
"autobahn",
"electfast",
"bluelightning",
]),
version: faker.system.semver(),
},
department: createKeyFromName(faker.commerce.department()),
company: createKeyFromName(faker.company.name()),
};
}
function createKeyFromName(name) {
const key = name.toLocaleLowerCase().replaceAll(/\W+/g, "-");
return { name, key };
}
function main() {
const max = 100;
const users = [];
for (let i = 0; i < max; i++) {
const user = createRandomUser();
users.push(user);
}
console.log(JSON.stringify(users, null, 2));
}
main();