Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/himenon/message-command-parser
Parse space- and colon-separated messages into parameters
https://github.com/himenon/message-command-parser
command-parser message-parser parser
Last synced: 11 days ago
JSON representation
Parse space- and colon-separated messages into parameters
- Host: GitHub
- URL: https://github.com/himenon/message-command-parser
- Owner: Himenon
- License: mit
- Created: 2022-06-06T06:17:49.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-04T13:24:36.000Z (11 months ago)
- Last Synced: 2024-12-06T08:47:00.020Z (28 days ago)
- Topics: command-parser, message-parser, parser
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@himenon/message-command-parser
- Size: 163 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @himenon/message-command-parser
## Install
```bash
# One of:
npm i @himenon/message-command-parser
yarn add @himenon/message-command-parser
pnpm add @himenon/message-command-parser
```## Usage
[Sample Code](./example/sample.ts) (`pnpm run test:sample`)
```ts
import { Parser } from "@himenon/message-command-parser";const messageParser = new Parser({
messageItems: [
{
command: "ping",
description: "ping",
},
{
command: "get release tags:string[]",
description: "Get Release By Tags",
},
],
});const showParsedValue = (message: string) => {
const parsedValue = messageParser.parse(message);if (parsedValue.kind === "plain") {
console.log({
message: parsedValue.message,
});
} else if (parsedValue.kind === "command") {
console.log({
action: parsedValue.action,
actionTargets: parsedValue.actionTargets,
parameters: parsedValue.parameters || {},
});
}
};showParsedValue("get release tags:v1.0.0,v1.1.0");
// {
// action: 'get',
// actionTargets: [ 'release' ],
// parameters: { tags: [ 'v1.0.0', 'v1.1.0' ] }
// }showParsedValue("ping");
// { action: 'ping', actionTargets: [], parameters: {} }showParsedValue("unregistered command");
// { message: 'unregistered command' }
```## Release
- Automatic version updates are performed when merged into the `main` branch.
## LICENCE
[@Himenon/message-command-parser ](https://github.com/Himenon/message-command-parser)・MIT