Skip to content

Commit 845c6db

Browse files
authored
refactor: remove inconsistent defaults from internet.password() (#767)
1 parent 01cd057 commit 845c6db

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/internet.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ export class Internet {
358358
*
359359
* @param len The length of the password to generate. Defaults to `15`.
360360
* @param memorable Whether the generated password should be memorable. Defaults to `false`.
361-
* @param pattern The pattern that all chars should match should match. Defaults to `/\w/`.
361+
* @param pattern The pattern that all chars should match should match.
362+
* This option will be ignored, if `memorable` is `true`. Defaults to `/\w/`.
362363
* @param prefix The prefix to use. Defaults to `''`.
363364
*
364365
* @example
@@ -369,15 +370,11 @@ export class Internet {
369370
* faker.internet.password(20, true, /[A-Z]/, 'Hello ') // 'Hello IREOXTDWPERQSB'
370371
*/
371372
password(
372-
len?: number,
373-
memorable?: boolean,
374-
pattern?: RegExp,
375-
prefix?: string
373+
len: number = 15,
374+
memorable: boolean = false,
375+
pattern: RegExp = /\w/,
376+
prefix: string = ''
376377
): string {
377-
len = len || 15;
378-
if (memorable == null) {
379-
memorable = false;
380-
}
381378
/*
382379
* password-generator ( function )
383380
* Copyright(c) 2011-2013 Bermi Ferrer <[email protected]>
@@ -386,12 +383,11 @@ export class Internet {
386383
const vowel = /[aeiouAEIOU]$/;
387384
const consonant = /[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]$/;
388385
const _password = (
389-
length = 10,
390-
memorable = true,
391-
pattern = /\w/,
392-
prefix = ''
386+
length: number,
387+
memorable: boolean,
388+
pattern: RegExp,
389+
prefix: string
393390
): string => {
394-
let char: string;
395391
if (prefix.length >= length) {
396392
return prefix;
397393
}
@@ -403,14 +399,14 @@ export class Internet {
403399
}
404400
}
405401
const n = this.faker.datatype.number(94) + 33;
406-
char = String.fromCharCode(n);
402+
let char = String.fromCharCode(n);
407403
if (memorable) {
408404
char = char.toLowerCase();
409405
}
410406
if (!char.match(pattern)) {
411407
return _password(length, memorable, pattern, prefix);
412408
}
413-
return _password(length, memorable, pattern, '' + prefix + char);
409+
return _password(length, memorable, pattern, prefix + char);
414410
};
415411
return _password(len, memorable, pattern, prefix);
416412
}

0 commit comments

Comments
 (0)