@diy0r/nestjs-rabbitmq
Version:
Nestjs rabbitMQ module
18 lines • 722 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toRegex = void 0;
const toRegex = (pattern) => {
const word = '[a-z]+';
const normalizedPattern = pattern.replace(/#(?:\.#)+/g, '#');
const withWildcardReplaced = normalizedPattern.replace(/\*/g, word);
if (withWildcardReplaced === '#') {
return new RegExp(`(?:${word}(?:\\.${word})*)?`);
}
const withHashReplaced = withWildcardReplaced
.replace(/^#\./, `(?:${word}\\.)*`)
.replace(/\.#/g, `(?:\\.${word})*`);
const escapedDots = withHashReplaced.replace(/(?<!\\)\./g, '\\.');
return new RegExp(`^${escapedDots}$`);
};
exports.toRegex = toRegex;
//# sourceMappingURL=toRegex.js.map