···11+MIT License
22+33+Copyright (c) 2023 Ben Pevsner
44+55+Permission is hereby granted, free of charge, to any person obtaining a copy
66+of this software and associated documentation files (the "Software"), to deal
77+in the Software without restriction, including without limitation the rights
88+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99+copies of the Software, and to permit persons to whom the Software is
1010+furnished to do so, subject to the following conditions:
1111+1212+The above copyright notice and this permission notice shall be included in all
1313+copies or substantial portions of the Software.
1414+1515+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121+SOFTWARE.
+71
README.md
···11+# Slash Command Parser
22+33+A generic parser for slash command text input. Pulls inspiration from Slack and Discord slash commands.
44+55+# Usage
66+77+Basic Usage:
88+99+```ts
1010+import parse from 'https://deno.land/x/slash_command_parser/mod.ts'
1111+1212+parse('/todos add name: My Todo Name')
1313+```
1414+1515+```ts
1616+{
1717+ text: 'add name: My Todo Name',
1818+ command: 'todos',
1919+ options: { name: 'My Todo Name' },
2020+ subCommands: ['add'],
2121+}
2222+```
2323+2424+Pass in a template to parse options:
2525+2626+```ts
2727+import parse, {
2828+ OptionDefinition,
2929+ OptionType,
3030+} from 'https://deno.land/x/slash_command_parser/mod.ts'
3131+3232+const template: OptionDefinition[] = [
3333+ { name: 'item', type: OptionType.string },
3434+ { name: 'howmany', type: OptionType.integer },
3535+ { name: 'complete', type: OptionType.boolean },
3636+]
3737+3838+parse('/todos add item: lettuce howmany: 2 complete: false', template)
3939+```
4040+4141+```ts
4242+{
4343+ text: 'add item: lettuce howmany: 2 complete: false',
4444+ command: 'todos',
4545+ options: { item: 'lettuce', howmany: 2, complete: false },
4646+ subCommands: ['add'],
4747+}
4848+```
4949+5050+If you want greater control over parsing or error handling, you can call each step individually:
5151+5252+```ts
5353+import {
5454+ parseCommand,
5555+ parseOptions,
5656+ parseSubCommands,
5757+} from 'https://deno.land/x/slash_command_parser/mod.ts'
5858+5959+const content = 'add item: lettuce howmany: 2 complete: false'
6060+6161+// Just parsing command + text can give you a "Slack"-style slashcommand
6262+const { command, text } = parseCommand(content)
6363+6464+// Expand to support 4 sub-commands instead of 2
6565+const { subCommands, remaining } = parseSubCommands(text, 4)
6666+const options = parseOptions(remaining, template)
6767+6868+console.log({ command, text, options, subCommands })
6969+```
7070+7171+See more usage examples in the [test file](./mod.test.ts).