Skip to content

Commit

Permalink
Merge pull request #206 from RandomAPI/v1.4
Browse files Browse the repository at this point in the history
V1.4
  • Loading branch information
keitharm authored Jul 5, 2022
2 parents 2558f4c + 2ff5b0f commit 2a4f928
Show file tree
Hide file tree
Showing 188 changed files with 160,795 additions and 1,491 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Randomuser.me-Node
[![Build Status](https://travis-ci.org/RandomAPI/Randomuser.me-Node.svg?branch=master)](https://travis-ci.org/RandomAPI/Randomuser.me-Node)
[![codecov](https://codecov.io/gh/RandomAPI/Randomuser.me-Node/branch/master/graph/badge.svg)](https://codecov.io/gh/RandomAPI/Randomuser.me-Node)

### About
This is the source code that powers the randomuser.me User Generator.
Expand Down
43 changes: 26 additions & 17 deletions api/.nextRelease/api.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/*
• Use native js dates instead of moment for ~60% increase in dates calculation
• Email addresses are now transliterated
• More street/city names for NL dataset
• Add country name to location block
• Capitalized proper nouns
• Split street into number and name properties
• Fixed Norwegian id generation bug
• Fixed Switzerland phone number format
• Fixed Danish CPR number calculation
• Fix US Social Security Number Generation
• Add India Data
• Add Mexico Data
• Add Serbia Data
• Add Ukraine Data
• Update Turkish Data lists
• Add CPF as Brazil's id
• Add SIN as Canada's id
• Add SVNR as Germany's id
• Change serial# to SN for LEGO id
• Fix French INSEE generation
• Fix DOB/Registered age calculation
*/

const fs = require('fs');
Expand All @@ -20,10 +23,11 @@ const YAML = require('yamljs');
const js2xmlparser = require('js2xmlparser');
const converter = require('json-2-csv');
const faker = require('faker');
const tr = require("transliteration");
const tr = require('transliteration');
const dayjs = require('dayjs')
const util = require('../../util');
const settings = require('../../settings');
const version = '1.3';
const version = '1.4';

class Generator {
constructor() {
Expand All @@ -32,7 +36,7 @@ class Generator {
'login', 'registered', 'dob', 'phone',
'cell', 'id', 'picture', 'nat'
];
this.constantTime = 1569449450;
this.constantTime = 1653344189;
this.version = version;

this.datasets = null;
Expand Down Expand Up @@ -189,13 +193,13 @@ class Generator {

this.current.dob = {
date: dobDate.toISOString(),
age: new Date().getFullYear() - dobDate.getFullYear()
age: dayjs().diff(dayjs(dobDate), 'years'),
};
let reg = range(1016688461000, this.constantTime * 1000);
let regDate = new Date(reg);
this.include('registered', {
date: regDate.toISOString(),
age: new Date().getFullYear() - regDate.getFullYear()
age: dayjs().diff(dayjs(regDate), 'years'),
});

let id, genderText;
Expand Down Expand Up @@ -380,7 +384,7 @@ class Generator {
}

fullNatName(nat) {
let mapping = {
const mapping = {
AU: "Australia",
BR: "Brazil",
CA: "Canada",
Expand All @@ -392,13 +396,16 @@ class Generator {
FR: "France",
GB: "United Kingdom",
IE: "Ireland",
IN: "India",
IR: "Iran",
MX: "Mexico",
NL: "Netherlands",
NO: "Norway",
NZ: "New Zealand",
RS: "Serbia",
TR: "Turkey",
UA: "Ukraine",
US: "United States",
UA: "Ukrainian",
};
return mapping[nat];
}
Expand All @@ -418,6 +425,8 @@ function random(mode, length) {
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
} else if (mode == 5) {
chars = '23456789';
} else if (mode == 6) {
chars = 'abcdefghijklmnopqrstuvwxyz';
}
for (let i = 0; i < length; i++) {
result += chars[range(0, chars.length-1)];
Expand All @@ -430,7 +439,7 @@ function randomItem(arr) {
return arr[range(0, arr.length-1)];
}

function range (min, max) {
function range(min, max) {
return min + mersenne.rand(max-min+1);
}

Expand Down
30 changes: 27 additions & 3 deletions api/.nextRelease/data/CA/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,33 @@ module.exports = (inc, contents) => {

include(inc, contents, 'phone', random(4, 1) + random(3, 2) + ' ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
include(inc, contents, 'cell', random(4, 1) + random(3, 2) + ' ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
include(inc, contents, 'id', {
name: '',
value: null
include(inc, contents, 'id', () => {
const checkSIN = (sin) => {
const check = '121212121';
const result = sin
.split('')
.map((num, index) => {
let res = num * check[index];
if (res >= 10) {
res = String(res).split('').reduce((a,b) => +a + +b);
}
return res
})
.reduce((a, b) => a + b);

return result % 10 === 0;
};
const genSIN = () => {
let sin = random(3, 9);
while(!checkSIN(sin)){
sin = random(3, 9);
}
return sin;
};
contents.id = {
name: 'SIN',
value: genSIN()
};
});
include(inc, contents, 'location', () => {
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
Expand Down
24 changes: 21 additions & 3 deletions api/.nextRelease/data/DE/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,27 @@ module.exports = (inc, contents) => {

include(inc, contents, 'phone', '0' + random(3, 3) + '-' + random(3, 7));
include(inc, contents, 'cell', '017' + random(3, 1) + '-' + random(3, 7));
include(inc, contents, 'id', {
name: '',
value: null
include(inc, contents, 'id', () => {
const dobDate = new Date(contents.dob.date);
const genSVNR = () => {
const pension = [
'02', '03', '04', '08', '09', '10', '11',
'12', '13', '14', '15', '16', '17', '18',
'19', '20', '21', '23', '24', '25', '26',
'28', '29', '38', '39', '40', '42', '43',
'44', '45', '46', '47', '48', '49', '50',
'51', '52', '53', '54', '55', '56', '57',
'58', '59', '60', '61', '62', '63', '64',
'65', '66', '67', '68', '69', '70', '71',
'72', '73', '74', '75', '76', '77', '78',
'79', '80', '81', '82', '89'
];
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)}`;
};
contents.id = {
name: 'SVNR',
value: genSVNR()
};
});
include(inc, contents, 'picture', pic);
};
2 changes: 1 addition & 1 deletion api/.nextRelease/data/DK/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (inc, contents) => {
include(inc, contents, 'phone', random(3, 8));
include(inc, contents, 'cell', random(3, 8));

let dobDate = new Date(contents.dob.date.slice(0, -1));
const dobDate = new Date(contents.dob.date);
include(inc, contents, 'id', {
name: 'CPR',
value: `${pad(dobDate.getDate(), 2)}${pad(dobDate.getMonth() + 1, 2)}${dobDate.getYear()}-${random(3, 4)}`
Expand Down
12 changes: 7 additions & 5 deletions api/.nextRelease/data/FR/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ module.exports = (inc, contents) => {
include(inc, contents, 'phone', '0' + range(1, 5) + '-' + random(3, 2) + '-' + random(3, 2) + '-' + random(3, 2) + '-' + random(3, 2));
include(inc, contents, 'cell', '06-' + random(3, 2) + '-' + random(3, 2) + '-' + random(3, 2) + '-' + random(3, 2));
include(inc, contents, 'id', () => {
const dobDate = new Date(contents.dob);
const day = dobDate.getDay();
const month = dobDate.getMonth();
const year = String(dobDate.getFullYear()).substr(2, 2);
const dobDate = new Date(contents.dob.date);
const gender = contents.gender === 'male' ? 1 : 2;
const year = dobDate.getYear();
const month = dobDate.getMonth().toString().padStart(2, '0');
const lloookkk = random(3, 8);
const cc = (97 - (Number(`${gender}${year}${month}${lloookkk}`) % 97)).toString().padStart(2, '0');

contents.id = {
name: 'INSEE',
value: (contents.gender === 'male' ? '1' : '2') + year + month + random(3, 8) + ' ' + random(3, 1) + range(0, 7)
value: `${gender}${year}${month}${lloookkk} ${cc}`
};
});
include(inc, contents, 'picture', pic);
Expand Down
2 changes: 1 addition & 1 deletion api/.nextRelease/data/LEGO/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = (inc, contents) => {
include(inc, contents, 'phone', '(' + random(3, 3) + ')-' + random(3, 3) + '-' + random(3, 4));
include(inc, contents, 'cell', '(' + random(3, 3) + ')-' + random(3, 3) + '-' + random(3, 4));
include(inc, contents, 'id', {
name: 'serial#',
name: 'SN',
value: random(3, 12)
});
include(inc, contents, 'picture', pic);
Expand Down
Loading

0 comments on commit 2a4f928

Please sign in to comment.