Skip to content

Commit 2a4f928

Browse files
authored
Merge pull request #206 from RandomAPI/v1.4
V1.4
2 parents 2558f4c + 2ff5b0f commit 2a4f928

File tree

188 files changed

+160795
-1491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+160795
-1491
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# Randomuser.me-Node
2-
[![Build Status](https://travis-ci.org/RandomAPI/Randomuser.me-Node.svg?branch=master)](https://travis-ci.org/RandomAPI/Randomuser.me-Node)
3-
[![codecov](https://codecov.io/gh/RandomAPI/Randomuser.me-Node/branch/master/graph/badge.svg)](https://codecov.io/gh/RandomAPI/Randomuser.me-Node)
42

53
### About
64
This is the source code that powers the randomuser.me User Generator.

api/.nextRelease/api.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
/*
2-
• Use native js dates instead of moment for ~60% increase in dates calculation
3-
• Email addresses are now transliterated
4-
• More street/city names for NL dataset
5-
• Add country name to location block
6-
• Capitalized proper nouns
7-
• Split street into number and name properties
8-
• Fixed Norwegian id generation bug
9-
• Fixed Switzerland phone number format
10-
• Fixed Danish CPR number calculation
2+
• Fix US Social Security Number Generation
3+
• Add India Data
4+
• Add Mexico Data
5+
• Add Serbia Data
6+
• Add Ukraine Data
7+
• Update Turkish Data lists
8+
• Add CPF as Brazil's id
9+
• Add SIN as Canada's id
10+
• Add SVNR as Germany's id
11+
• Change serial# to SN for LEGO id
12+
• Fix French INSEE generation
13+
• Fix DOB/Registered age calculation
1114
*/
1215

1316
const fs = require('fs');
@@ -20,10 +23,11 @@ const YAML = require('yamljs');
2023
const js2xmlparser = require('js2xmlparser');
2124
const converter = require('json-2-csv');
2225
const faker = require('faker');
23-
const tr = require("transliteration");
26+
const tr = require('transliteration');
27+
const dayjs = require('dayjs')
2428
const util = require('../../util');
2529
const settings = require('../../settings');
26-
const version = '1.3';
30+
const version = '1.4';
2731

2832
class Generator {
2933
constructor() {
@@ -32,7 +36,7 @@ class Generator {
3236
'login', 'registered', 'dob', 'phone',
3337
'cell', 'id', 'picture', 'nat'
3438
];
35-
this.constantTime = 1569449450;
39+
this.constantTime = 1653344189;
3640
this.version = version;
3741

3842
this.datasets = null;
@@ -189,13 +193,13 @@ class Generator {
189193

190194
this.current.dob = {
191195
date: dobDate.toISOString(),
192-
age: new Date().getFullYear() - dobDate.getFullYear()
196+
age: dayjs().diff(dayjs(dobDate), 'years'),
193197
};
194198
let reg = range(1016688461000, this.constantTime * 1000);
195199
let regDate = new Date(reg);
196200
this.include('registered', {
197201
date: regDate.toISOString(),
198-
age: new Date().getFullYear() - regDate.getFullYear()
202+
age: dayjs().diff(dayjs(regDate), 'years'),
199203
});
200204

201205
let id, genderText;
@@ -380,7 +384,7 @@ class Generator {
380384
}
381385

382386
fullNatName(nat) {
383-
let mapping = {
387+
const mapping = {
384388
AU: "Australia",
385389
BR: "Brazil",
386390
CA: "Canada",
@@ -392,13 +396,16 @@ class Generator {
392396
FR: "France",
393397
GB: "United Kingdom",
394398
IE: "Ireland",
399+
IN: "India",
395400
IR: "Iran",
401+
MX: "Mexico",
396402
NL: "Netherlands",
403+
NO: "Norway",
397404
NZ: "New Zealand",
398405
RS: "Serbia",
399406
TR: "Turkey",
407+
UA: "Ukraine",
400408
US: "United States",
401-
UA: "Ukrainian",
402409
};
403410
return mapping[nat];
404411
}
@@ -418,6 +425,8 @@ function random(mode, length) {
418425
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
419426
} else if (mode == 5) {
420427
chars = '23456789';
428+
} else if (mode == 6) {
429+
chars = 'abcdefghijklmnopqrstuvwxyz';
421430
}
422431
for (let i = 0; i < length; i++) {
423432
result += chars[range(0, chars.length-1)];
@@ -430,7 +439,7 @@ function randomItem(arr) {
430439
return arr[range(0, arr.length-1)];
431440
}
432441

433-
function range (min, max) {
442+
function range(min, max) {
434443
return min + mersenne.rand(max-min+1);
435444
}
436445

api/.nextRelease/data/CA/inject.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,33 @@ module.exports = (inc, contents) => {
66

77
include(inc, contents, 'phone', random(4, 1) + random(3, 2) + ' ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
88
include(inc, contents, 'cell', random(4, 1) + random(3, 2) + ' ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
9-
include(inc, contents, 'id', {
10-
name: '',
11-
value: null
9+
include(inc, contents, 'id', () => {
10+
const checkSIN = (sin) => {
11+
const check = '121212121';
12+
const result = sin
13+
.split('')
14+
.map((num, index) => {
15+
let res = num * check[index];
16+
if (res >= 10) {
17+
res = String(res).split('').reduce((a,b) => +a + +b);
18+
}
19+
return res
20+
})
21+
.reduce((a, b) => a + b);
22+
23+
return result % 10 === 0;
24+
};
25+
const genSIN = () => {
26+
let sin = random(3, 9);
27+
while(!checkSIN(sin)){
28+
sin = random(3, 9);
29+
}
30+
return sin;
31+
};
32+
contents.id = {
33+
name: 'SIN',
34+
value: genSIN()
35+
};
1236
});
1337
include(inc, contents, 'location', () => {
1438
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

api/.nextRelease/data/DE/inject.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,27 @@ module.exports = (inc, contents) => {
66

77
include(inc, contents, 'phone', '0' + random(3, 3) + '-' + random(3, 7));
88
include(inc, contents, 'cell', '017' + random(3, 1) + '-' + random(3, 7));
9-
include(inc, contents, 'id', {
10-
name: '',
11-
value: null
9+
include(inc, contents, 'id', () => {
10+
const dobDate = new Date(contents.dob.date);
11+
const genSVNR = () => {
12+
const pension = [
13+
'02', '03', '04', '08', '09', '10', '11',
14+
'12', '13', '14', '15', '16', '17', '18',
15+
'19', '20', '21', '23', '24', '25', '26',
16+
'28', '29', '38', '39', '40', '42', '43',
17+
'44', '45', '46', '47', '48', '49', '50',
18+
'51', '52', '53', '54', '55', '56', '57',
19+
'58', '59', '60', '61', '62', '63', '64',
20+
'65', '66', '67', '68', '69', '70', '71',
21+
'72', '73', '74', '75', '76', '77', '78',
22+
'79', '80', '81', '82', '89'
23+
];
24+
return `${randomItem(pension)} ${pad(dobDate.getDate(), 2)}${pad(dobDate.getMonth() + 1, 2)}${dobDate.getYear()} ${contents.name.last[0]} ${contents.gender === 'male' ? pad(range(0,49), 2) : pad(range(50, 99), 2)}${range(0, 9)}`;
25+
};
26+
contents.id = {
27+
name: 'SVNR',
28+
value: genSVNR()
29+
};
1230
});
1331
include(inc, contents, 'picture', pic);
1432
};

api/.nextRelease/data/DK/inject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = (inc, contents) => {
77
include(inc, contents, 'phone', random(3, 8));
88
include(inc, contents, 'cell', random(3, 8));
99

10-
let dobDate = new Date(contents.dob.date.slice(0, -1));
10+
const dobDate = new Date(contents.dob.date);
1111
include(inc, contents, 'id', {
1212
name: 'CPR',
1313
value: `${pad(dobDate.getDate(), 2)}${pad(dobDate.getMonth() + 1, 2)}${dobDate.getYear()}-${random(3, 4)}`

api/.nextRelease/data/FR/inject.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ module.exports = (inc, contents) => {
77
include(inc, contents, 'phone', '0' + range(1, 5) + '-' + random(3, 2) + '-' + random(3, 2) + '-' + random(3, 2) + '-' + random(3, 2));
88
include(inc, contents, 'cell', '06-' + random(3, 2) + '-' + random(3, 2) + '-' + random(3, 2) + '-' + random(3, 2));
99
include(inc, contents, 'id', () => {
10-
const dobDate = new Date(contents.dob);
11-
const day = dobDate.getDay();
12-
const month = dobDate.getMonth();
13-
const year = String(dobDate.getFullYear()).substr(2, 2);
10+
const dobDate = new Date(contents.dob.date);
11+
const gender = contents.gender === 'male' ? 1 : 2;
12+
const year = dobDate.getYear();
13+
const month = dobDate.getMonth().toString().padStart(2, '0');
14+
const lloookkk = random(3, 8);
15+
const cc = (97 - (Number(`${gender}${year}${month}${lloookkk}`) % 97)).toString().padStart(2, '0');
1416

1517
contents.id = {
1618
name: 'INSEE',
17-
value: (contents.gender === 'male' ? '1' : '2') + year + month + random(3, 8) + ' ' + random(3, 1) + range(0, 7)
19+
value: `${gender}${year}${month}${lloookkk} ${cc}`
1820
};
1921
});
2022
include(inc, contents, 'picture', pic);

api/.nextRelease/data/LEGO/inject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = (inc, contents) => {
77
include(inc, contents, 'phone', '(' + random(3, 3) + ')-' + random(3, 3) + '-' + random(3, 4));
88
include(inc, contents, 'cell', '(' + random(3, 3) + ')-' + random(3, 3) + '-' + random(3, 4));
99
include(inc, contents, 'id', {
10-
name: 'serial#',
10+
name: 'SN',
1111
value: random(3, 12)
1212
});
1313
include(inc, contents, 'picture', pic);

0 commit comments

Comments
 (0)