chat-arg-parser

2.1.2 • Public • Published

npm version StyleCI

chat-arg-parser

Parses commands with a specified prefix, delimited by spaces, with support for double & single quotations, and no need for escaping.

The function returns an object containing the command and its arguments:

{
    cmd: 'jail',
    args: ['person', '10d'],
}

Installation

Using npm:

$ npm install chat-arg-parser

How to use

const parseCommandInput = require('chat-arg-parser');
 
// command_input would be set by an event where a user sends a command,
// for example, this could be a Discord server chat message
 
var command_input = '!jail';
parseCommandInput('!', command_input);
// => {cmd: 'jail', args: []}
 
var command_input = '!jail "name with spaces" 10s';
parseCommandInput('!', command_input);
// => {cmd: 'jail', args: ['name with spaces', '10s']}
 
var command_input = "!jail 'name with spaces' 10s";
parseCommandInput('!', command_input);
// => {cmd: 'jail', args: ['name with spaces', '10s']}
 
var command_input = '!jail "name with "quotation" 10s';
parseCommandInput('!', command_input);
// => {cmd: 'jail', args: ['name with "quotation', '10s']}
 
var command_input = 'not a command';
parseCommandInput('!', command_input);
// => false

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.1.2
    0
    • latest

Version History

Package Sidebar

Install

npm i chat-arg-parser

Weekly Downloads

6

Version

2.1.2

License

MIT

Unpacked Size

5.27 kB

Total Files

4

Last publish

Collaborators

  • williamvenner