You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cvm/src/match-or-error.js

17 lines
451 B
JavaScript

"use strict";
module.exports = function matchOrError(regex, string) {
if (regex == null) {
throw new Error("No regular expression was provided");
} else if (string == null) {
throw new Error("No string to match on was provided");
} else {
let match = regex.exec(string);
if (match == null) {
throw new Error(`Regular expression ${regex.toString()} failed to match on string: ${string}`);
} else {
return match.slice(1);
}
}
};