Skip to content

Commit

Permalink
perf: avoid recreating regex
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Nov 10, 2021
1 parent 3ee803a commit e77a155
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/convertGlobToRegex.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const WILDCARD_RULE = /\*+/g;

export const convertGlobToRegex = (glob: string): RegExp => {
return new RegExp(
glob
.replace(/\*+/g, '*')
.replace(/\*/g, '(.+?)'),
.replace(WILDCARD_RULE, '(.+?)'),
);
};

0 comments on commit e77a155

Please sign in to comment.