@@ -358,7 +358,8 @@ export class Internet {
358
358
*
359
359
* @param len The length of the password to generate. Defaults to `15`.
360
360
* @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/`.
362
363
* @param prefix The prefix to use. Defaults to `''`.
363
364
*
364
365
* @example
@@ -369,15 +370,11 @@ export class Internet {
369
370
* faker.internet.password(20, true, /[A-Z]/, 'Hello ') // 'Hello IREOXTDWPERQSB'
370
371
*/
371
372
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 = ''
376
377
) : string {
377
- len = len || 15 ;
378
- if ( memorable == null ) {
379
- memorable = false ;
380
- }
381
378
/*
382
379
* password-generator ( function )
383
380
* Copyright(c) 2011-2013 Bermi Ferrer <[email protected] >
@@ -386,12 +383,11 @@ export class Internet {
386
383
const vowel = / [ a e i o u A E I O U ] $ / ;
387
384
const consonant = / [ b c d f g h j k l m n p q r s t v w x y z B C D F G H J K L M N P Q R S T V W X Y Z ] $ / ;
388
385
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
393
390
) : string => {
394
- let char : string ;
395
391
if ( prefix . length >= length ) {
396
392
return prefix ;
397
393
}
@@ -403,14 +399,14 @@ export class Internet {
403
399
}
404
400
}
405
401
const n = this . faker . datatype . number ( 94 ) + 33 ;
406
- char = String . fromCharCode ( n ) ;
402
+ let char = String . fromCharCode ( n ) ;
407
403
if ( memorable ) {
408
404
char = char . toLowerCase ( ) ;
409
405
}
410
406
if ( ! char . match ( pattern ) ) {
411
407
return _password ( length , memorable , pattern , prefix ) ;
412
408
}
413
- return _password ( length , memorable , pattern , '' + prefix + char ) ;
409
+ return _password ( length , memorable , pattern , prefix + char ) ;
414
410
} ;
415
411
return _password ( len , memorable , pattern , prefix ) ;
416
412
}
0 commit comments