RegExp
constructor JS-011549 if (ctx.request.url == '/') {
50 ctx.redirect('/pow')
51 return
52 } else if (RegExp(`^\/pow`).test(ctx.request.url)) {53 await next()
54 return
55 } else {
6import NoSql from './util/nosql'
7
8const nosql: NoSql = NoSql.getInstance()
9const uuidTest = new RegExp(10 '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'11)12
13export const controller: Koa.Middleware = async function (
14 ctx: Koa.ParameterizedContext,
When a regular expression is known in advance, it is considered a best practice to avoid the string literal notation on top of the regular expression notation, and use regular expression literals instead of the constructor function.
// bad practice:
const number = new RegExp("^\d\.$");
// recommended:
const number_ = /^\d\.$/;
Regex literals are easier to read and do not require a call to the RegExp
constructor at runtime.
new RegExp("abc");
new RegExp("abc", "u");
RegExp("abc");
RegExp("abc", "u");
new RegExp("\d\d\.\d\d\.\d\d\d\d");
RegExp(`^\d\.$`);
new RegExp(String.raw`^\d\.$`);
/abc/;
/abc/u;
/\d\d\.\d\d\.\d\d\d\d/;
/^\d\.$/;
// RegExp constructor is allowed for dynamically generated regular expressions
new RegExp(pattern);
RegExp("abc", flags);
new RegExp(prefix + "abc");
RegExp(`${prefix}abc`);
new RegExp(String.raw`^\d\. ${sufix}`);