Skip to content

Commit

Permalink
fix(env-expect.js): improve RegExp support; better debugging experience
Browse files Browse the repository at this point in the history
  • Loading branch information
Xunnamius committed Jan 4, 2021
1 parent c9fa2b4 commit aff191d
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions env-expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,14 @@ module.exports = {
)
)
};
} else if (typeof rule.name == 'string') {
rule.name = RegExp(rule.name);
} else if (typeof rule.name == 'string' || rule.name instanceof RegExp) {
rule.name = rule.name instanceof RegExp ? rule.name : RegExp(rule.name);
rule.value =
typeof rule.value == 'string' ? RegExp(rule.value) : DEFAULT_VALUE_REGEX[0];
typeof rule.value == 'string'
? RegExp(rule.value)
: rule.value instanceof RegExp
? rule.value
: DEFAULT_VALUE_REGEX[0];

normalizedRule = {
operation: 'or',
Expand Down Expand Up @@ -152,6 +156,7 @@ module.exports = {
)
};
} else {
debug('::normalize BAD RULE ENCOUNTERED = %O', rule);
throw new IllegalEnvironmentError(
`bad rule encountered${
fromPkg ? ' in ./package.json "env-expect"' : ''
Expand Down

0 comments on commit aff191d

Please sign in to comment.