aboutsummaryrefslogtreecommitdiff
path: root/src/modules/helpers
diff options
context:
space:
mode:
authorShinigami <[email protected]>2023-05-01 11:20:12 +0200
committerGitHub <[email protected]>2023-05-01 09:20:12 +0000
commitec1ca128b8b4ee5b0d1d77a1dd18d40792173c27 (patch)
tree5406238150f1c96e18e23791c32b39415371d188 /src/modules/helpers
parenta8dc7e07f6d5ee2ae38724ba5d503d7b88bd7147 (diff)
downloadfaker-ec1ca128b8b4ee5b0d1d77a1dd18d40792173c27.tar.xz
faker-ec1ca128b8b4ee5b0d1d77a1dd18d40792173c27.zip
chore: improve regex usage (#2108)
Diffstat (limited to 'src/modules/helpers')
-rw-r--r--src/modules/helpers/index.ts12
1 files changed, 6 insertions, 6 deletions
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;