New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

discord-cmd-parser

Package Overview
Dependencies
Maintainers
0
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-cmd-parser

Parser for discord chat commands

latest
Source
npmnpm
Version
2.2.1
Version published
Weekly downloads
2
Maintainers
0
Weekly downloads
 
Created
Source

Discord Args Parser

Installation

yarn add discord-cmd-parser
or
npm install discord-cmd-parser

Usage

// Import package in your project
const  Parser = require('discord-cmd-parser');

// Initialize with or without options
const  parser = Parser.createParser()
// args and commands always tranfroms to lower case excemp names of the args and args in quotes  

// parse()
console.log(parser.parse('git remote add origin https://github.com')) // ---> {_:['git', 'remote', 'add', 'origin', 'https://github.com']}

// Or with args definition
console.log(parser.parse('git remote add origin https://github.com', ['command', 'arg1', 'arg2', 'arg3'])) // ---> {_:['https://github.com'], command: 'git', arg1: 'remote', arg2: 'add', arg3: 'origin'}

// Also you can use quotes to define long args with spaces and new lines
console.log(parser.parse(`command "super long arg with spaces or tabs
or newlines" https://github.com`), ['command', 'longArg', 'link']) // ---> {_:[], command: 'command', longarg: 'super long arg with spaces or tabs or newlines', link: 'https://github.com'}

// Multiple spaces, tabs and new lines always will be converted to one space
console.log(parser.parse(`command "super long arg with spaces or tabs
or newlines" https://git hub.com `), ['command', 'longArg', 'link']) // ---> {_:['hub.com'], command: 'command', longArg: 'super long arg with spaces or tabs or newlines', link: 'https://git'}

console.log(parser.parseCommandArgs( parser.parse(`git remote test1 test2`), {command: { default: ""}, arg1: { default: "asdas" }, arg2: { default: "odd" }})) // ---> {_: ["test2"], command: 'git', arg1: 'remote',arg2: 'test1'}

Methods

MethodreturnDescription
parse(string: string)[]stringParses string into args.
parseCommandArgs(parsedMessage: string[], commandArgsDef: IargsDefinition[])Objectassign parsed string to args.
disableQuotes()voidDisables parsing args in quotes as one.
enableQuotes()voidEnable parsing args in quotes as one.
changeQuotesType(value: string)voidChange quotes type.

Options

OptionTypeDeffaultDescription
useQuotesbooleantrueif false quotes will be ignored
quotesTypestring"symbol to separate long arg

License

MIT License

Copyright (c) 2021 Andrew t.rumibul.work@gmail.com

Keywords

discord

FAQs

Package last updated on 27 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts