Skip to content

Commit 4a09b69

Browse files
authored
Merge pull request #150 from mlevin2/bugfix/rug-149
Bugfix/rug 149
2 parents e48850a + 16ac055 commit 4a09b69

File tree

3 files changed

+40
-38
lines changed

3 files changed

+40
-38
lines changed

api/.nextRelease/api.js

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,20 @@ class Generator {
132132
///////////////////
133133

134134
this.seedRNG();
135-
135+
136136
let output = [];
137137
let nat, inject;
138-
138+
139139
for (let i = 0; i < this.results; i++) {
140140
this.current = {};
141141
nat = this.nat === null ? this.randomNat() : this.nat;
142142
if (Array.isArray(nat)) {
143143
nat = nat[range(0, nat.length-1)];
144144
}
145145
inject = this.injects[nat];
146-
146+
147147
this.current.gender = this.gender === null ? randomItem(['male', 'female']) : this.gender;
148-
148+
149149
let name = this.randomName(this.current.gender, nat);
150150
this.include('name', {
151151
title: this.current.gender === 'male' ? 'Mr' : randomItem(this.datasets.common.title),
@@ -169,9 +169,9 @@ class Generator {
169169
},
170170
timezone
171171
});
172-
172+
173173
this.include('email', tr.transliterate(`${name[0]}.${name[1]}`).replace(/ /g, '').toLowerCase() + '@example.com');
174-
174+
175175
let salt = random(2, 8);
176176
let password = this.password === undefined ? randomItem(this.datasets.common.passwords) : this.genPassword();
177177
this.include('login', {
@@ -183,7 +183,7 @@ class Generator {
183183
sha1: crypto.createHash('sha1').update(password + salt).digest('hex'),
184184
sha256: crypto.createHash('sha256').update(password + salt).digest('hex')
185185
});
186-
186+
187187
let dob = range(-800000000000, this.constantTime * 1000 - 86400000 * 365 * 21);
188188
let dobDate = new Date(dob);
189189

@@ -197,7 +197,7 @@ class Generator {
197197
date: regDate.toISOString(),
198198
age: new Date().getFullYear() - regDate.getFullYear()
199199
});
200-
200+
201201
let id, genderText;
202202
if (nat != 'LEGO') {
203203
id = this.current.gender == 'male' ? range(0, 99) : range(0, 96);
@@ -207,17 +207,17 @@ class Generator {
207207
genderText = 'lego';
208208
}
209209
let base = 'https://randomuser.me/api/';
210-
210+
211211
this.include('picture', {
212212
large: base + 'portraits/' + genderText + '/' + id + '.jpg',
213213
medium: base + 'portraits/med/' + genderText + '/' + id + '.jpg',
214214
thumbnail: base + 'portraits/thumb/' + genderText + '/' + id + '.jpg'
215215
});
216-
216+
217217
inject(this.inc, this.current, this.datasets); // Inject unique fields for nationality
218-
218+
219219
this.include('nat', nat);
220-
220+
221221
// Gender hack - Remove gender if the user doesn't want it in the results
222222
if (this.inc.indexOf('gender') === -1) {
223223
delete this.current.gender;
@@ -227,10 +227,10 @@ class Generator {
227227
if (this.inc.indexOf('dob') === -1) {
228228
delete this.current.dob;
229229
}
230-
230+
231231
output.push(this.current);
232232
}
233-
233+
234234
let json = {
235235
results: output,
236236
info: {
@@ -240,9 +240,9 @@ class Generator {
240240
version: this.version
241241
}
242242
};
243-
243+
244244
if (this.noInfo) delete json.info;
245-
245+
246246
if (this.format === 'yaml') {
247247
resolve({output: YAML.stringify(json, 4), ext: "yaml"});
248248
} else if (this.format === 'xml') {
@@ -266,22 +266,22 @@ class Generator {
266266
seed = this.seed.substring(0, 16);
267267
}
268268
seed = this.page !== 1 ? seed + String(this.page) : seed;
269-
269+
270270
seed = parseInt(crypto.createHash('md5').update(seed).digest('hex').substring(0, 8), 16);
271271
mersenne.seed(seed);
272272
faker.seed(seed);
273273
}
274-
274+
275275
// Choose random seed
276276
defaultSeed() {
277277
this.seed = random(1, 16);
278278
}
279-
279+
280280
// Return random nat to use
281281
randomNat() {
282282
return this.nats[range(0, this.nats.length - 1)];
283283
}
284-
284+
285285
// Make sure nat is available
286286
validNat(nat) {
287287
if (Array.isArray(nat)) {
@@ -295,12 +295,12 @@ class Generator {
295295
}
296296
return true;
297297
}
298-
298+
299299
randomName(gender, nat) {
300300
gender = gender === undefined ? randomItem(['male', 'female']) : gender;
301301
return [randomItem(this.datasets[nat][gender + '_first']), randomItem(this.datasets[nat]['last'])];
302302
}
303-
303+
304304
// Return available nats
305305
getNats() {
306306
let exclude = ['common', 'LEGO'];
@@ -309,13 +309,13 @@ class Generator {
309309
});
310310
return nats;
311311
}
312-
312+
313313
include(field, value) {
314314
if (this.inc.indexOf(field) !== -1) {
315315
this.current[field] = value;
316316
}
317317
}
318-
318+
319319
checkOptions(options) {
320320
let keys = Object.keys(options);
321321
for (let i = 0; i < keys.length; i++) {
@@ -329,32 +329,32 @@ class Generator {
329329
if (this.password.length === 0) {
330330
return randomItem(this.datasets.common.passwords);
331331
}
332-
332+
333333
let charsets = {
334334
special: " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
335335
upper: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
336336
lower: "abcdefghijklmnopqrstuvwxyz",
337337
number: "0123456789"
338338
};
339-
339+
340340
// Parse sections
341341
let sections = ["special", "upper", "lower", "number"];
342342
let matches = this.password.split(',').filter(val => sections.indexOf(val) !== -1)
343-
343+
344344
if (matches.length === 0) {
345345
return randomItem(this.datasets.common.passwords);
346346
}
347-
347+
348348
matches = matches.filter((v,i,self) => self.indexOf(v) === i);
349-
349+
350350
// Construct charset to choose from
351351
let charset = "";
352352
matches.forEach(match => {
353353
charset += charsets[match];
354354
});
355-
355+
356356
let length = this.password.split(',').slice(-1)[0];
357-
357+
358358
// Range
359359
let min, max;
360360
if (length.indexOf('-') !== -1) {
@@ -367,15 +367,15 @@ class Generator {
367367
}
368368
min = min > 64 || min < 1 || min === undefined || isNaN(min) ? 8 : min;
369369
max = max > 64 || max < 1 || max === undefined || isNaN(max) ? 64 : max;
370-
370+
371371
let passLen = range(min, max);
372-
372+
373373
// Generate password
374374
let password = "";
375375
for (let i = 0; i < passLen; i++) {
376376
password += String(charset[range(0, charset.length-1)]);
377377
}
378-
378+
379379
return password;
380380
}
381381

@@ -414,6 +414,8 @@ function random(mode, length) {
414414
chars = '0123456789';
415415
} else if (mode == 4) {
416416
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
417+
} else if (mode == 5) {
418+
chars = '23456789';
417419
}
418420
for (let i = 0; i < length; i++) {
419421
result += chars[range(0, chars.length-1)];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module.exports = (inc, contents) => {
44
const pic = contents.picture;
55
delete contents.picture;
66

7-
include(inc, contents, 'phone', random(3, 3) + '-' + random(3, 3) + '-' + random(3, 4));
8-
include(inc, contents, 'cell', random(3, 3) + '-' + random(3, 3) + '-' + random(3, 4));
7+
include(inc, contents, 'phone', random(4, 1) + random(3, 2) + ' ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
8+
include(inc, contents, 'cell', random(4, 1) + random(3, 2) + ' ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
99
include(inc, contents, 'id', {
1010
name: '',
1111
value: null

api/.nextRelease/data/US/inject.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module.exports = (inc, contents) => {
44
const pic = contents.picture;
55
delete contents.picture;
66

7-
include(inc, contents, 'phone', '(' + random(3, 3) + ')-' + random(3, 3) + '-' + random(3, 4));
8-
include(inc, contents, 'cell', '(' + random(3, 3) + ')-' + random(3, 3) + '-' + random(3, 4));
7+
include(inc, contents, 'phone', '(' + random(4, 1) + random(3, 2) + ') ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
8+
include(inc, contents, 'cell', '(' + random(4, 1) + random(3, 2) + ') ' + random(4, 1) + random(3, 2) + '-' + random(3, 4));
99
include(inc, contents, 'id', {
1010
name: 'SSN',
1111
value: random(3, 3) + '-' + random(3, 2) + '-' + random(3, 4)

0 commit comments

Comments
 (0)