@sasaplus1/keystroke
v3.0.0
Published
manage keystroke
Downloads
67
Readme
keystroke.js
manage keystroke
Installation
$ deno add jsr:@sasaplus1/keystroke
$ npm install @sasaplus1/keystroke
Usage
import {
type Keystroke,
KeystrokeTree,
parse,
stringify,
} from "@sasaplus1/keystroke";
parse("cit"); // => [{code: "c", ... }, {code: "i", ... }, {code: "t", ... }]
parse("<C-x><C-c>"); // => [{code: "x", ctrl: true, ... }, {code: "c", ctrl: true, ... }]
stringify({ code: "i" } as Keystroke); // => "i"
stringify({ code: "f", ctrl: true } as Keystroke); // => "<C-f>"
const kt = new KeystrokeTree<() => string>();
kt.set("<C-x><C-c>", () => "exit");
kt.get("<C-x><C-c>")?.(); // => "exit"
kt.set("<C-x>6k", () => "close-session");
kt.get("<C-x>6k")?.(); // => "close-session"
kt.clear();
kt.get("<C-x>6k"); // => undefined
License
The MIT license