Skip to content

Commit ec1ca12

Browse files
authored
chore: improve regex usage (#2108)
1 parent a8dc7e0 commit ec1ca12

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

scripts/apidoc/signature.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function typeToText(type_?: Type, short = false): string {
212212
if (
213213
(reflectionType?.type === 'literal' ||
214214
reflectionType?.type === 'union') &&
215-
!type.name.match(/Char$/)
215+
!/Char$/.test(type.name)
216216
) {
217217
return typeToText(reflectionType, short);
218218
}

src/modules/finance/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ export class FinanceModule {
834834
const normalizedIssuer = issuer.toLowerCase();
835835
if (normalizedIssuer in localeFormat) {
836836
format = this.faker.helpers.arrayElement(localeFormat[normalizedIssuer]);
837-
} else if (issuer.match(/#/)) {
837+
} else if (/#/.test(issuer)) {
838838
// The user chose an optional scheme
839839
format = issuer;
840840
} else {

src/modules/helpers/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export class HelpersModule {
277277
let max: number;
278278
let tmp: number;
279279
let repetitions: number;
280-
let token = string.match(RANGE_REP_REG);
280+
let token = RANGE_REP_REG.exec(string);
281281
while (token != null) {
282282
min = parseInt(token[2]);
283283
max = parseInt(token[3]);
@@ -293,23 +293,23 @@ export class HelpersModule {
293293
string.slice(0, token.index) +
294294
token[1].repeat(repetitions) +
295295
string.slice(token.index + token[0].length);
296-
token = string.match(RANGE_REP_REG);
296+
token = RANGE_REP_REG.exec(string);
297297
}
298298

299299
// Deal with repeat `{num}`
300-
token = string.match(REP_REG);
300+
token = REP_REG.exec(string);
301301
while (token != null) {
302302
repetitions = parseInt(token[2]);
303303
string =
304304
string.slice(0, token.index) +
305305
token[1].repeat(repetitions) +
306306
string.slice(token.index + token[0].length);
307-
token = string.match(REP_REG);
307+
token = REP_REG.exec(string);
308308
}
309309
// Deal with range `[min-max]` (only works with numbers for now)
310310
//TODO: implement for letters e.g. [0-9a-zA-Z] etc.
311311

312-
token = string.match(RANGE_REG);
312+
token = RANGE_REG.exec(string);
313313
while (token != null) {
314314
min = parseInt(token[1]); // This time we are not capturing the char before `[]`
315315
max = parseInt(token[2]);
@@ -324,7 +324,7 @@ export class HelpersModule {
324324
string.slice(0, token.index) +
325325
this.faker.number.int({ min, max }).toString() +
326326
string.slice(token.index + token[0].length);
327-
token = string.match(RANGE_REG);
327+
token = RANGE_REG.exec(string);
328328
}
329329

330330
return string;

src/modules/internet/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ export class InternetModule {
14841484
}
14851485

14861486
if (memorable) {
1487-
if (prefix.match(consonant)) {
1487+
if (consonant.test(prefix)) {
14881488
pattern = vowel;
14891489
} else {
14901490
pattern = consonant;
@@ -1497,7 +1497,7 @@ export class InternetModule {
14971497
char = char.toLowerCase();
14981498
}
14991499

1500-
if (!char.match(pattern)) {
1500+
if (!pattern.test(char)) {
15011501
return _password(length, memorable, pattern, prefix);
15021502
}
15031503

0 commit comments

Comments
 (0)