Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const testSubroutine = (subject: string, [userRule]: $ReadOnlyArray) => {
const rule: RegExp = parseRegex(userRule);
if (typeof subject !== 'string') {
throw new SurgeonError('Input is not a string.');
}
if (!rule.test(subject)) {
return new InvalidValueSentinel('Input does not match "' + rule.toString() + '" regular expression.');
}
return subject;
};
const matchSubroutine = (subject: string, [userRule, sprintfFormat]: $ReadOnlyArray) => {
const rule: RegExp = parseRegex(userRule);
if (typeof subject !== 'string') {
throw new SurgeonError('Input is not a string.');
}
const matches = subject.match(rule);
if (!matches) {
log.debug({
input: subject,
}, 'input');
return new InvalidValueSentinel('Input does not match "' + rule.toString() + '" regular expression.');
}
if (matches.length === 1) {