@naandalist/patch-package
Version:
Fix broken node modules with no fuss
28 lines (24 loc) • 545 B
text/typescript
import chalk from "chalk"
export const makeRegExp = (
reString: string,
name: string,
defaultValue: RegExp,
caseSensitive: boolean,
): RegExp => {
if (!reString) {
return defaultValue
} else {
try {
return new RegExp(reString, caseSensitive ? "" : "i")
} catch (_) {
console.log(`${chalk.red.bold("***ERROR***")}
Invalid format for option --${name}
Unable to convert the string ${JSON.stringify(
reString,
)} to a regular expression.
`)
process.exit(1)
return /unreachable/
}
}
}