Command parsers for text chat applications.
Using npm:
$ npm install epicus
or using yarn:
$ yarn add epicus
import { CommandParser } from "epicus";
// New parser with prefix "!"
let parser = new CommandParser({ prefix: "!" });
let str = "!hunt unicorn";
parser.parse(str); // { success: true, command: "hunt", args: ["unicorn"] }
// Creating a new plugin
let Unicorns = new Plugin((command, args) => {
return { success: true, command, args: args.map((arg) => arg.replace(/unicorn/g, "🦄")) };
});
// Plugging it
parser.plug(Unicorns);
parser.parse(str); // { success: true, command: "hunt", args: ["🦄"] }
Type: object
Type: string
Default: '!'
Prefix of your commands.
Type: string
Default: ' '
Delimiter to split command.
Type: Plugin[]
Default: []
Plugins to be loaded.
Type: boolean
Default: false
Set to true
to have case sensitive command parsing.
Plugs a plugin to the command parser.
Unplugs a plugin from the command parser.
Parses the string.
Type: ( command: string, args: string[], metadata: { prefix: string; delimiter: string; body: string } ) => { success: boolean; command?: Command; args?: Args; }
Function to be called when the plugin is loaded.
Type: number
Default: 0
Sets the priority of the plugin, higher the priority the earlier is loaded.
Plugins with the same priority are loaded in the order of plugging them to the parser.