superstruct
superstruct copied to clipboard
pattern (regex) does not return consistent output when using the global modifier
In this example:
const s = require("superstruct");
const Query = s.object({
url: s.pattern(s.string(), /^example/g),
});
const testQuery = {
url: "example",
};
console.log(s.is(testQuery, Query), s.is(testQuery, Query));
It returns the following output:
% node index.js
true false
I would expect each call to is to return the same output. I suspect this is because of the stateful behaviour of regular expressions.
I just opened a PR with a fix https://github.com/ianstormtaylor/superstruct/pull/1295