forked from rap2hpoutre/pg-anonymizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextensions.js
59 lines (57 loc) · 1.61 KB
/
extensions.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
// extensions.js
const { faker } = require('@faker-js/faker');
const bcrypt = require('bcrypt');
function randomString(length) {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#_-+*^%`~/>,?<';
let result = '';
for (let i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
return result;
}
module.exports = {
randomCountryID: () => {
return faker.datatype.number({ min: 1, max: 231 });
},
randomBuildingNumber: () => {
return faker.address.buildingNumber();
},
replaceWithEmptyString: () => {
return "";
},
replaceWithString: () => {
return "Confidential";
},
replaceWithNull: () => {
return null;
},
randomHeight: () => {
return faker.datatype.number({ min: 150, max: 200 });
},
randomWeight: () => {
return faker.datatype.number({ min: 45, max: 180, precision: 0.1 });
},
randomBirthDate: () => {
const birthDate = new Date(faker.date.between('1910-01-01T00:00:00.000Z', '2003-31-12T00:00:00.000Z'));
return birthDate.toISOString().split("T")[0];
},
randomGender: () => {
return faker.name.gender(true);
},
randomPhoneNumber: () => {
return faker.phone.phoneNumber('+48 111 ### ####');
},
randomEmail: (record) => {
if (record === process.env['admin_email']) {
console.log(record)
return record
}
return faker.internet.email()
},
randomPassword: () => {
return randomString(10);
},
randomPasswordHash: () => {
const newPassword = randomString(10)
const salt = bcrypt.genSaltSync(13, 'a');
return bcrypt.hashSync(newPassword, salt);
}
};