IMO the RegExp().test() for errorOnRegex should default missing - or actually any non-string - values to "".
Currently, ^(true|undefined)$ is required to require a variable to either be "true" or not set. This feels hacky as it relies on RegExp().test() casting non-string values to a string, in which case undefined becomes "undefined".
As environment variables should always be strings, I think it's better to default non-strings to "" so that you can use ^(true)?$ to require a value to either be "true" or not set.
Without the change in src/index.js the newly added test fails with:
AssertionError: expected [Function: runTest] to throw error including 'REGEX MISMATCH: TEST_MISSING_REQUIRED' but got 'REGEX MISMATCH: TEST_MISSING_OPTIONAL, TEST_MISSING_REQUIRED'
+ expected - actual
-REGEX MISMATCH: TEST_MISSING_OPTIONAL, TEST_MISSING_REQUIRED
+REGEX MISMATCH: TEST_MISSING_REQUIRED
Coverage remained the same at 100.0% when pulling 61b99ed8b4ff597663680364bc7fa6c462a27971 on FokkeZB:RegExp-String into 43e550d0dce3b6345398915958fa6e31eea24672 on keithmorris:develop.
Coverage remained the same at 100.0% when pulling 61b99ed8b4ff597663680364bc7fa6c462a27971 on FokkeZB:RegExp-String into 43e550d0dce3b6345398915958fa6e31eea24672 on keithmorris:develop.
Coverage remained the same at 100.0% when pulling 61b99ed8b4ff597663680364bc7fa6c462a27971 on FokkeZB:RegExp-String into 43e550d0dce3b6345398915958fa6e31eea24672 on keithmorris:develop.
IMO the
RegExp().test()
forerrorOnRegex
should default missing - or actually any non-string - values to""
.Currently,
^(true|undefined)$
is required to require a variable to either be"true"
or not set. This feels hacky as it relies onRegExp().test()
casting non-string values to a string, in which caseundefined
becomes"undefined"
.As environment variables should always be strings, I think it's better to default non-strings to
""
so that you can use^(true)?$
to require a value to either be"true"
or not set.Without the change in
src/index.js
the newly added test fails with:Also see #41