Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/1marcuth/command-options-handler
https://github.com/1marcuth/command-options-handler
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/1marcuth/command-options-handler
- Owner: 1Marcuth
- Created: 2024-02-21T19:59:04.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-02-22T23:59:09.000Z (9 months ago)
- Last Synced: 2024-02-23T00:26:48.833Z (9 months ago)
- Language: TypeScript
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Command Options Handler
Command Options Handler is a library for handling options/arguments in string format.
### Usage
```ts
import CommandHandler, { Command } from "command-options-handler"const command: Command = {
name: "Teste",
description: "This is the description of the test command.",
options: [
{
name: "want-something",
description: "This is the description of the first argument/option. The names here have no impact whatsoever. I just put them to fit with my bot development architecture :)",
type: "yesOrNo"
}
]
}const commandHandler = new CommandHandler(command)
console.dir(commandHandler.handleStringOptions([ "yes" ]), { depth: null })
console.dir(commandHandler.handleStringOptions([ "YeS ", "x" ]), { depth: null })
console.dir(commandHandler.handleStringOptions([ "yeah", "ok" ]), { depth: null })
```### Execution result
```js
{
isValid: true,
argumentsExpected: 1,
argumentsReceived: 1,
optionsValidation: [
{
name: 'want-something',
isValid: { type: true, value: true },
value: { raw: 'yes', parsed: 'yes' }
}
]
}
{
isValid: true,
argumentsExpected: 1,
argumentsReceived: 2,
optionsValidation: [
{
name: 'want-something',
isValid: { type: true, value: true },
value: { raw: 'YeS ', parsed: 'yes' }
}
]
}
{
isValid: false,
argumentsExpected: 1,
argumentsReceived: 2,
optionsValidation: [
{
name: 'want-something',
isValid: { type: false, value: false },
value: { raw: 'yeah', parsed: null }
}
]
}
```