43
44 // If this looks like a URL for a resource, because it contains
45 // a file extension, skip.
46 if (url.pathname.match(fileExtensionRegexp)) {47 return false48 }49
50 // Return true to signal that we want to use the handler.
51 return true
The following pattern:
if (condition) {
return true
}
return false
can be refactored to:
return condition
When condition
is not a boolean value,
it can be cast into one using the Boolean
constructor.
function isEven(num: number) {
if (num % 2 === 0) return true
return false
}
async function userExists(name: string) {
if (await db.getUser(name)) return true
return false
}
function isEven(num: number) {
return num % 2 === 0
}
async function userExists(name: string) {
return Boolean(await db.getUser(name))
}