Files
airllm-fork-nodejs/node_modules/env-var/lib/accessors/regexp.js
2026-02-05 15:27:49 +08:00

22 lines
588 B
JavaScript

'use strict'
module.exports = function asRegExp (value, flags) {
// We have to test the value and flags indivudally if we want to write our
// own error messages,as there is no way to differentiate between the two
// errors except by using string comparisons.
// Test the flags
try {
RegExp(undefined, flags)
} catch (err) {
throw new Error('invalid regexp flags')
}
try {
return new RegExp(value, flags)
} catch (err) {
// We know that the regexp is the issue because we tested the flags earlier
throw new Error('should be a valid regexp')
}
}