Skip to content

Commit

Permalink
Compile regular expressions at module initialization instead of every…
Browse files Browse the repository at this point in the history
… invocation
  • Loading branch information
jjhbw committed May 17, 2020
1 parent e01e04f commit 00ae3d4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/processTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,11 +549,12 @@ const builtInCommands = [
'IMAGE',
'LINK',
'HTML',
];
] as const;

const builtInRegexes = builtInCommands.map(word => new RegExp(`^${word}\\b`));

const notBuiltIns = (cmd: string) =>
!builtInCommands.some(word =>
new RegExp(`^${word}\\b`).test(cmd.toUpperCase())
);
!builtInRegexes.some(r => r.test(cmd.toUpperCase()));

const getCommand = (ctx: Context): string => {
let { cmd } = ctx;
Expand Down

0 comments on commit 00ae3d4

Please sign in to comment.