redis-smq
Version:
A high-performance, reliable, and scalable message queue for Node.js.
30 lines • 949 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._matchRoutingKey = _matchRoutingKey;
function compileTopicPattern(pattern) {
const tokens = pattern.length ? pattern.split('.') : [];
const esc = (s) => s.replace(/[-/\\^$+?.()|[\]{}]/g, '\\$&');
let re = '^';
let prevWasHash = false;
tokens.forEach((tok, idx) => {
if (tok === '#') {
re += idx === 0 ? '(?:[^.]+(?:\\.[^.]+)*)?' : '(?:\\.[^.]+)*';
prevWasHash = true;
return;
}
if (idx > 0) {
re += prevWasHash ? '(?:\\.)?' : '\\.';
}
prevWasHash = false;
if (tok === '*')
re += '[^.]+';
else
re += esc(tok);
});
re += '$';
return new RegExp(re);
}
function _matchRoutingKey(routingKey, pattern) {
return compileTopicPattern(pattern).test(routingKey);
}
//# sourceMappingURL=_match-routing-key.js.map