UNPKG

@grammyjs/commands

Version:
16 lines (15 loc) 687 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ensureArray = void 0; exports.escapeSpecial = escapeSpecial; exports.getCommandsRegex = getCommandsRegex; const ensureArray = (value) => Array.isArray(value) ? value : [value]; exports.ensureArray = ensureArray; const specialChars = "\\.^$|?*+()[]{}-".split(""); const replaceAll = (s, find, replace) => s.replace(new RegExp(`\\${find}`, "g"), replace); function escapeSpecial(str) { return specialChars.reduce((acc, char) => replaceAll(acc, char, `\\${char}`), str); } function getCommandsRegex(prefix) { return new RegExp(`(\?\<\!\\S)(\?<prefix>${escapeSpecial(prefix)})\\S+(\\s|$)`, "g"); }