pattern-rule-value.js
371 Bytes
"use strict";
module.exports = function(msg, rules) {
if (!rules || !Array.isArray(rules)) {
return null;
}
for (let rule of rules) {
if (!rule.pattern || !rule.value) return null;
const re = new RegExp(rule.pattern, rule.flags);
if (msg.search(re) >= 0) {
return rule.value;
}
}
return null;
}