UNPKG

fallout-utility

Version:
28 lines 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCommand = void 0; const strings_1 = require("./strings"); /** * Returns the command and arguments from a string * @param string Parse message command from this string * @param prefix Check this command's prefix * @param separator Set arg separator */ function getCommand(string, prefix, separator = ' ') { const commandData = { name: undefined, prefix, args: [], raw: string, rawArgs: '', separator, }; if (prefix && !(0, strings_1.startsWith)(string, prefix)) return commandData; commandData.name = (prefix ? string.slice(prefix.length) : string).trim().split(/\s+/)[0]; commandData.rawArgs = (prefix ? string.slice(prefix.length) : string).slice(commandData.name.length).trim() || ''; commandData.args = commandData.rawArgs ? (0, strings_1.splitString)(commandData.rawArgs, true, separator) : []; return commandData; } exports.getCommand = getCommand; //# sourceMappingURL=commands.js.map