-
Notifications
You must be signed in to change notification settings - Fork 1
/
dataset.js
45 lines (42 loc) · 1.2 KB
/
dataset.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
import { faker } from "@faker-js/faker";
const data = [];
const generateEmail = (first_name, last_name) => {
const email = faker.internet.email({
firstName: first_name,
lastName: last_name,
allowSpecialCharacters: true,
});
// make sure email is unique
if (data.find((user) => user.email === email)) return generateEmail(first_name, last_name);
return email;
};
/**
* Generate 50000 fake data
* with this schema:
* first_name, last_name, email, password, age, gender, created_at, updated_at
* @returns {Array} fake data
*/
export const generateFakeData = (num) => {
if (data.length) return data;
for (let i = 0; i < num; i++) {
const gender = faker.person.sexType();
const first_name = faker.person.firstName(gender);
const last_name = faker.person.lastName(gender);
const email = generateEmail(first_name, last_name);
const password = faker.internet.password();
const age = faker.number.int({ min: 15, max: 35 });
const created_at = faker.date.recent();
const updated_at = faker.date.recent();
data.push({
first_name,
last_name,
email,
password,
age,
gender,
created_at,
updated_at,
});
}
return data;
};