diff options
| author | Shinigami <[email protected]> | 2023-05-01 11:20:12 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-01 09:20:12 +0000 |
| commit | ec1ca128b8b4ee5b0d1d77a1dd18d40792173c27 (patch) | |
| tree | 5406238150f1c96e18e23791c32b39415371d188 /src/modules | |
| parent | a8dc7e07f6d5ee2ae38724ba5d503d7b88bd7147 (diff) | |
| download | faker-ec1ca128b8b4ee5b0d1d77a1dd18d40792173c27.tar.xz faker-ec1ca128b8b4ee5b0d1d77a1dd18d40792173c27.zip | |
chore: improve regex usage (#2108)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/finance/index.ts | 2 | ||||
| -rw-r--r-- | src/modules/helpers/index.ts | 12 | ||||
| -rw-r--r-- | src/modules/internet/index.ts | 4 |
3 files changed, 9 insertions, 9 deletions
diff --git a/src/modules/finance/index.ts b/src/modules/finance/index.ts index 32b04795..4add0243 100644 --- a/src/modules/finance/index.ts +++ b/src/modules/finance/index.ts @@ -834,7 +834,7 @@ export class FinanceModule { const normalizedIssuer = issuer.toLowerCase(); if (normalizedIssuer in localeFormat) { format = this.faker.helpers.arrayElement(localeFormat[normalizedIssuer]); - } else if (issuer.match(/#/)) { + } else if (/#/.test(issuer)) { // The user chose an optional scheme format = issuer; } else { diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index 048614cf..ba7e083a 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -277,7 +277,7 @@ export class HelpersModule { let max: number; let tmp: number; let repetitions: number; - let token = string.match(RANGE_REP_REG); + let token = RANGE_REP_REG.exec(string); while (token != null) { min = parseInt(token[2]); max = parseInt(token[3]); @@ -293,23 +293,23 @@ export class HelpersModule { string.slice(0, token.index) + token[1].repeat(repetitions) + string.slice(token.index + token[0].length); - token = string.match(RANGE_REP_REG); + token = RANGE_REP_REG.exec(string); } // Deal with repeat `{num}` - token = string.match(REP_REG); + token = REP_REG.exec(string); while (token != null) { repetitions = parseInt(token[2]); string = string.slice(0, token.index) + token[1].repeat(repetitions) + string.slice(token.index + token[0].length); - token = string.match(REP_REG); + token = REP_REG.exec(string); } // Deal with range `[min-max]` (only works with numbers for now) //TODO: implement for letters e.g. [0-9a-zA-Z] etc. - token = string.match(RANGE_REG); + token = RANGE_REG.exec(string); while (token != null) { min = parseInt(token[1]); // This time we are not capturing the char before `[]` max = parseInt(token[2]); @@ -324,7 +324,7 @@ export class HelpersModule { string.slice(0, token.index) + this.faker.number.int({ min, max }).toString() + string.slice(token.index + token[0].length); - token = string.match(RANGE_REG); + token = RANGE_REG.exec(string); } return string; diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 066044aa..37ada74a 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -1484,7 +1484,7 @@ export class InternetModule { } if (memorable) { - if (prefix.match(consonant)) { + if (consonant.test(prefix)) { pattern = vowel; } else { pattern = consonant; @@ -1497,7 +1497,7 @@ export class InternetModule { char = char.toLowerCase(); } - if (!char.match(pattern)) { + if (!pattern.test(char)) { return _password(length, memorable, pattern, prefix); } |
