diff options
| author | ST-DDT <[email protected]> | 2023-10-17 22:18:04 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-10-17 20:18:04 +0000 |
| commit | 980f230947ca250086aedf37160abe86c766f969 (patch) | |
| tree | 2c8e24322c2688c9ea01883bf22b4092acd27979 /src/modules | |
| parent | c0330442be99988db57e9dad12ebdcd3b3a92213 (diff) | |
| download | faker-980f230947ca250086aedf37160abe86c766f969.tar.xz faker-980f230947ca250086aedf37160abe86c766f969.zip | |
infra(typescript-eslint): prefer-regexp-exec (#2466)
Diffstat (limited to 'src/modules')
| -rw-r--r-- | src/modules/helpers/index.ts | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/modules/helpers/index.ts b/src/modules/helpers/index.ts index ab0ec5b8..22d8491f 100644 --- a/src/modules/helpers/index.ts +++ b/src/modules/helpers/index.ts @@ -407,7 +407,7 @@ export class SimpleHelpersModule { if (pattern instanceof RegExp) { isCaseInsensitive = pattern.flags.includes('i'); pattern = pattern.toString(); - pattern = pattern.match(/\/(.+?)\//)?.[1] ?? ''; // Remove frontslash from front and back of RegExp + pattern = /\/(.+?)\//.exec(pattern)?.[1] ?? ''; // Remove frontslash from front and back of RegExp } let min: number; @@ -417,7 +417,7 @@ export class SimpleHelpersModule { // Deal with single wildcards const SINGLE_CHAR_REG = /([.A-Za-z0-9])(?:\{(\d+)(?:,(\d+)|)\}|(\?|\*|\+))(?![^[]*]|[^{]*})/; - let token = pattern.match(SINGLE_CHAR_REG); + let token = SINGLE_CHAR_REG.exec(pattern); while (token != null) { const quantifierMin: string = token[2]; const quantifierMax: string = token[3]; @@ -434,14 +434,14 @@ export class SimpleHelpersModule { pattern.slice(0, token.index) + token[1].repeat(repetitions) + pattern.slice(token.index + token[0].length); - token = pattern.match(SINGLE_CHAR_REG); + token = SINGLE_CHAR_REG.exec(pattern); } const SINGLE_RANGE_REG = /(\d-\d|\w-\w|\d|\w|[-!@#$&()`.+,/"])/; const RANGE_ALPHANUMEMRIC_REG = /\[(\^|)(-|)(.+?)\](?:\{(\d+)(?:,(\d+)|)\}|(\?|\*|\+)|)/; // Deal with character classes with quantifiers `[a-z0-9]{min[, max]}` - token = pattern.match(RANGE_ALPHANUMEMRIC_REG); + token = RANGE_ALPHANUMEMRIC_REG.exec(pattern); while (token != null) { const isNegated = token[1] === '^'; const includesDash: boolean = token[2] === '-'; @@ -452,7 +452,7 @@ export class SimpleHelpersModule { const rangeCodes: number[] = []; let ranges = token[3]; - let range = ranges.match(SINGLE_RANGE_REG); + let range = SINGLE_RANGE_REG.exec(ranges); if (includesDash) { // 45 is the ascii code for '-' @@ -494,7 +494,7 @@ export class SimpleHelpersModule { } ranges = ranges.substring(range[0].length); - range = ranges.match(SINGLE_RANGE_REG); + range = SINGLE_RANGE_REG.exec(ranges); } repetitions = getRepetitionsBasedOnQuantifierParameters( @@ -549,12 +549,12 @@ export class SimpleHelpersModule { pattern.slice(0, token.index) + generatedString + pattern.slice(token.index + token[0].length); - token = pattern.match(RANGE_ALPHANUMEMRIC_REG); + token = RANGE_ALPHANUMEMRIC_REG.exec(pattern); } const RANGE_REP_REG = /(.)\{(\d+),(\d+)\}/; // Deal with quantifier ranges `{min,max}` - token = pattern.match(RANGE_REP_REG); + token = RANGE_REP_REG.exec(pattern); while (token != null) { min = parseInt(token[2]); max = parseInt(token[3]); @@ -568,19 +568,19 @@ export class SimpleHelpersModule { pattern.slice(0, token.index) + token[1].repeat(repetitions) + pattern.slice(token.index + token[0].length); - token = pattern.match(RANGE_REP_REG); + token = RANGE_REP_REG.exec(pattern); } const REP_REG = /(.)\{(\d+)\}/; // Deal with repeat `{num}` - token = pattern.match(REP_REG); + token = REP_REG.exec(pattern); while (token != null) { repetitions = parseInt(token[2]); pattern = pattern.slice(0, token.index) + token[1].repeat(repetitions) + pattern.slice(token.index + token[0].length); - token = pattern.match(REP_REG); + token = REP_REG.exec(pattern); } return pattern; |
