UNPKG

redis-smq

Version:

A high-performance, reliable, and scalable message queue for Node.js.

27 lines 834 B
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); } export function _matchRoutingKey(routingKey, pattern) { return compileTopicPattern(pattern).test(routingKey); } //# sourceMappingURL=_match-routing-key.js.map