Skip to content

Commit

Permalink
chore: improve regex usage (#2108)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinigami92 committed May 1, 2023
1 parent a8dc7e0 commit ec1ca12
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion scripts/apidoc/signature.ts
Expand Up @@ -212,7 +212,7 @@ function typeToText(type_?: Type, short = false): string {
if (
(reflectionType?.type === 'literal' ||
reflectionType?.type === 'union') &&
!type.name.match(/Char$/)
!/Char$/.test(type.name)
) {
return typeToText(reflectionType, short);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/finance/index.ts
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions src/modules/helpers/index.ts
Expand Up @@ -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]);
Expand All @@ -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]);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/internet/index.ts
Expand Up @@ -1484,7 +1484,7 @@ export class InternetModule {
}

if (memorable) {
if (prefix.match(consonant)) {
if (consonant.test(prefix)) {
pattern = vowel;
} else {
pattern = consonant;
Expand All @@ -1497,7 +1497,7 @@ export class InternetModule {
char = char.toLowerCase();
}

if (!char.match(pattern)) {
if (!pattern.test(char)) {
return _password(length, memorable, pattern, prefix);
}

Expand Down

0 comments on commit ec1ca12

Please sign in to comment.