@rus-anonym/commands-manager
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

@rus-anonym/commands-manager

Examples

Commands

TextCommand

import { TRawFunc, ICommandParams, Command } from "@rus-anonym/commands-manager";

class TextCommand<Func extends TRawFunc> extends Command<Func> {
    private _trigger: string;

    constructor(params: ICommandParams<Func> & { trigger: string }) {
        super(params);
        this._trigger = params.trigger;
    }

    public check(value: string): boolean {
        return this._trigger === value;
    }
}

const cmd = new TextCommand({ func: (log: string) => log, trigger: "hello" });

cmd.check("hello"); // true
cmd.check("hey"); // false
cmd.execute(); // Expected N arguments, but got 0 ts(2554)
cmd.execute("hey"); // Promise<"hey">

Manager

Template

import { Manager } from "@rus-anonym/commands-manager";

const manager = new Manager([
    new TextCommand({ func: (log: string) => log, trigger: "hello" }),
    new TextCommand({ func: () => 2, trigger: "1+1" }),
    new TextCommand({
        func: (x: number, y: number) => x * y,
        trigger: "multiply",
    }),
]);

manager.find("hello"); // TextCommand<{ func: (log: string) => string; }>
manager.find("1+1"); // TextCommand<{ func: () => number; }>
manager.find("multiply"); // TextCommand<{ func: (x: number, y: number) => number; }>

Readme

Keywords

none

Package Sidebar

Install

npm i @rus-anonym/commands-manager

Weekly Downloads

3

Version

1.2.0

License

MIT

Unpacked Size

8.4 kB

Total Files

16

Last publish

Collaborators

  • rus_anonym