1.0.1 • Published 2 years ago

epicus v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Epicus

npm tests npm

Command parsers for text chat applications.

Install

Using npm:

$ npm install epicus

or using yarn:

$ yarn add epicus

Basic Usage

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: ["🦄"] }

API

CommandParser([, options])

options

Type: object

prefix

Type: string\ Default: '!'

Prefix of your commands.

delimiter

Type: string\ Default: ' '

Delimiter to split command.

plugins

Type: Plugin[]\ Default: []

Plugins to be loaded.

caseSensitive

Type: boolean\ Default: false

Set to true to have case sensitive command parsing.

Methods

.plug(plugin)

Plugs a plugin to the command parser.

.unplug(plugin)

Unplugs a plugin from the command parser.

.parse(string)

Parses the string.

Plugin(func, priority?)

func

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.

priority

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.