{"name":"tinykeys","version":"1.0.6","keywords":["key","keys","bindings","hot","hotkeys","a11y","accessibility","keyboard","navigation","event","handler","react","vue","angular","ember","mousetrap","shortcuts"],"author":{"name":"Jamie Kyle","email":"me@thejameskyle.com"},"license":"MIT","_id":"tinykeys@1.0.6","homepage":"https://github.com/jamiebuilds/tinykeys#readme","bugs":{"url":"https://github.com/jamiebuilds/tinykeys/issues"},"ava":{"require":["ts-node/register"],"extensions":["ts","tsx"]},"dist":{"shasum":"a4e48e994e6c1539859ec33e192afcf5f44e8722","tarball":"http://registry-npm.ywwl.com/tinykeys/download/tinykeys-1.0.6.tgz","fileCount":12,"integrity":"sha512-0m0W18g3HoW3vX+bt+Uw7b8Rbq3ejjpY8w3bQa3Ch2L6d8yWKi8i+z43feKogogDvFEQT6qpPCY+7xnjluofgg==","signatures":[{"sig":"MEYCIQC2Bxs3vQE1jK1JmnJOFZsaqkHP90i61tQl/WLqdtw/dAIhAMGmZFUCH7A2UuySwMn8p6ivcj0VsxZEcG5Cg2YghqMJ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":37537,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfKeV4CRA9TVsSAnZWagAAZcoP/2XFaGENXRiC59oRh9iP\nIk9T7XLnxXm+a0R701uNXeP2Q27MYOaZ5K1jfFH1L5cBnlpORufnxICMADV0\nyXdl9khXalpN+euE9n8ObAajIgtAuGej7RXCnVgkBzIfAk94DkwKNJHNF8J6\nFDdq/qDEN7akzpvlDxXYghhNM3f7kJIVOTjeZ60shmsFdD4CgCiVkLFsNE3d\nyOvsRcsVlMS8DsjG1XdoZOWEiaOQTV7wcLog1bANCNi27JD8iQpdiZBN1Xft\niBUGJRmj57DHl21g/WfPmu5ilqBWlfGWYYtccuzRnkV/+hUknXGjO6tJDZRl\n7AbLm4KiiQpLvXp3RPw0kFXPnyaI7JnBEVCjZiigL/kQesQ0Aoqz7vDbdtJX\nnanLP/RKx+62soXkb2VhvIkUPAkiVvbeOI+fkOqrsUp7FTE0MD1iYKV6i9TH\nSaIeZg/C9Nt5pa4uBCSaTJdXod6xYujrpWoKJlltXAUJbncCRBX5sJKlLp2H\nvY0zy4kNNA8TtARu1baf8T3NpUTpcXxOJiH3KnwuPq+YL0I1jdCp5aO+xYl+\nDlthJcgVfusZng0r6Y6Ij3cI+crrM5ITGaS2X/WLkHCC+mCKc0utg5ikJoe5\nVx27bjBAwYrB0B0MM+bPR1SacsaBgFLRj3YJys17DDVwFTvc2AwiYkbVw1/9\nmetP\r\n=oY00\r\n-----END PGP SIGNATURE-----\r\n","size":6939,"noattachment":false,"key":"/tinykeys/-/tinykeys-1.0.6.tgz"},"main":"dist/tinykeys.js","unpkg":"dist/tinykeys.umd.js","module":"dist/tinykeys.module.js","source":"src/tinykeys.ts","gitHead":"fa79fcdf1ddf4a1238dba20b303355515aeb2c8d","scripts":{"lint":"eslint '**'","test":"TS_NODE_PROJECT=./tsconfig.test.json nyc --reporter=lcov --reporter=text-summary ava","build":"rm -rf dist && microbundle --inline none","check":"npm run -s typecheck && npm run -s lint && npm run -s check:format","start":"rm -rf example-dist && parcel example/index.html -d example-dist","format":"prettier --write '**'","precommit":"lint-staged","typecheck":"tsc --noEmit","check:format":"prettier --check '**'","build:example":"rm -rf example-dist && parcel build example/index.html -d example-dist --public-url ./","prepublishOnly":"npm run -s build"},"_npmUser":{"name":"thejameskyle","email":"me@thejameskyle.com"},"repository":{"url":"git+https://github.com/jamiebuilds/tinykeys.git","type":"git"},"_npmVersion":"6.14.4","description":"A tiny (~400 B) & modern library for keybindings.","directories":{},"lint-staged":{"*":["prettier --write","git add"]},"_nodeVersion":"14.0.0","_hasShrinkwrap":false,"devDependencies":{"ava":"^3.11.0","nyc":"^15.1.0","husky":"^4.2.5","eslint":"^7.5.0","parcel":"^1.12.4","ts-node":"^8.10.2","prettier":"^2.0.5","typescript":"^3.9.7","lint-staged":"^10.2.11","microbundle":"^0.12.3","eslint-plugin-ava":"^10.5.0","@typescript-eslint/parser":"^3.7.1","@typescript-eslint/eslint-plugin":"^3.7.1"},"_npmOperationalInternal":{"tmp":"tmp/tinykeys_1.0.6_1596581239674_0.7013940016796112","host":"s3://npm-registry-packages"},"readme":"# `tinykeys`\n\n> A tiny (~650 B) & modern library for keybindings.\n> [See Demo](https://jamiebuilds.github.io/tinykeys/)\n\n## Install\n\n```sh\nnpm install --save tinykeys\n```\n\nOr for a CDN version, you can use it on [unpkg.com](https://unpkg.com/tinykeys)\n\n## Usage\n\n```js\nimport { tinykeys } from \"tinykeys\" // Or `window.tinykeys` using the CDN version\n\ntinykeys(window, {\n  \"Shift+D\": () => {\n    alert(\"The 'Shift' and 'd' keys were pressed at the same time\")\n  },\n  \"y e e t\": () => {\n    alert(\"The keys 'y', 'e', 'e', and 't' were pressed in order\")\n  },\n  \"$mod+([0-9])\": event => {\n    event.preventDefault()\n    alert(`Either 'Control+${event.key}' or 'Meta+${event.key}' were pressed`)\n  },\n})\n```\n\nAlternatively, if you want to only create the keybinding handler, and register\nit as an event listener yourself:\n\n```js\nimport { createKeybindingsHandler } from \"tinykeys\"\n\nlet handler = createKeybindingsHandler({\n  \"Shift+D\": () => {\n    alert(\"The 'Shift' and 'd' keys were pressed at the same time\")\n  },\n  \"y e e t\": () => {\n    alert(\"The keys 'y', 'e', 'e', and 't' were pressed in order\")\n  },\n  \"$mod+KeyD\": event => {\n    event.preventDefault()\n    alert(\"Either 'Control+d' or 'Meta+d' were pressed\")\n  },\n})\n\nwindow.addEventListener(\"keydown\", handler)\n```\n\n### React Hooks Example\n\nIf you're using tinykeys within a component, you should also make use of the\nreturned `unsubscribe()` function.\n\n```js\nimport { useEffect } from \"react\"\nimport { tinykeys } from \"tinykeys\"\n\nfunction useKeyboardShortcuts() {\n  useEffect(() => {\n    let unsubscribe = tinykeys(window, {\n      // ...\n    })\n    return () => {\n      unsubscribe()\n    }\n  })\n}\n```\n\n## Commonly used `key`'s and `code`'s\n\nKeybindings will be matched against\n[`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)\nand[`KeyboardEvent.code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values)\nwhich may have some names you don't expect.\n\n| Windows       | macOS           | `key`         | `code`                         |\n| ------------- | --------------- | ------------- | ------------------------------ |\n| N/A           | `Command` / `⌘` | `Meta`        | `MetaLeft` / `MetaRight`       |\n| `Alt`         | `Option` / `⌥`  | `Alt`         | `AltLeft` / `AltRight`         |\n| `Control`     | `Control` / `^` | `Control`     | `ControlLeft` / `ControlRight` |\n| `Shift`       | `Shift`         | `Shift`       | `ShiftLeft` / `ShiftRight`     |\n| `Space`       | `Space`         | N/A           | `Space`                        |\n| `Enter`       | `Return`        | `Enter`       | `Enter`                        |\n| `Esc`         | `Esc`           | `Escape`      | `Escape`                       |\n| `1`, `2`, etc | `1`, `2`, etc   | `1`, `2`, etc | `Digit1`, `Digit2`, etc        |\n| `a`, `b`, etc | `a`, `b`, etc   | `a`, `b`, etc | `KeyA`, `KeyB`, etc            |\n| `-`           | `-`             | `-`           | `Minus`                        |\n| `=`           | `=`             | `=`           | `Equal`                        |\n| `+`           | `+`             | `+`           | `Equal`\\*                      |\n\nSomething missing? Check out the key logger on the\n[demo website](https://jamiebuilds.github.io/tinykeys/)\n\n> _\\* Some keys will have the same code as others because they appear on the\n> same key on the keyboard. Keep in mind how this is affected by international\n> keyboards which may have different layouts._\n\n## Key aliases\n\nIn some instances, tinykeys will alias keys depending on the platform to\nsimplify cross-platform keybindings on international keyboards.\n\n### `AltGraph` (modifier)\n\nOn Windows, on many non-US standard keyboard layouts, there is a key named\n`Alt Gr` or `AltGraph` in the browser, in some browsers, pressing `Control+Alt`\nwill report `AltGraph` as being pressed instead.\n\nSimilarly on macOS, the `Alt` (`Option`) key will sometimes be reported as the\n`AltGraph` key.\n\n**Note:** The purpose of the `Alt Gr` key is to type \"Alternate Graphics\" so you\nwill often want to use the `event.code` (`KeyS`) for letters instead of\n`event.key` (`S`)\n\n```js\ntinykeys(window, {\n  \"Control+Alt+KeyS\": event => {\n    // macOS: `Control+Alt+S` or `Control+AltGraph+S`\n    // Windows: `Control+Alt+S` or `Control+AltGraph+S` or `AltGraph+S`\n  },\n  \"$mod+Alt+KeyS\": event => {\n    // macOS: `Meta+Alt+S` or `Meta+AltGraph+S`\n    // Windows: `Control+Alt+S` or `Control+AltGraph+S` or `AltGraph+S`\n  },\n})\n```\n\n## Keybinding Syntax\n\nKeybindings are made up of a **_sequence_** of **_presses_**.\n\nA **_press_** can be as simple as a single **_key_** which matches against\n[`KeyboardEvent.code`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code/code_values)\nand\n[`KeyboardEvent.key`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key)\n(case-insensitive).\n\n```js\n// Matches `event.key`:\n\"d\"\n// Matches: `event.code`:\n\"KeyD\"\n```\n\nPresses can optionally be prefixed with **_modifiers_** which match against any\nvalid value to\n[`KeyboardEvent.getModifierState()`](https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/getModifierState).\n\n```js\n\"Control+d\"\n\"Meta+d\"\n\"Shift+D\"\n\"Alt+KeyD\"\n\"Meta+Shift+D\"\n```\n\nThere is also a special `$mod` modifier that makes it easy to support cross\nplatform keybindings:\n\n- Mac: `$mod` = `Meta` (⌘)\n- Windows/Linux: `$mod` = `Control`\n\n```js\n\"$mod+D\" // Meta/Control+D\n\"$mod+Shift+D\" // Meta/Control+Shift+D\n```\n\nAlternatively, you can use parenthesis to use case-sensitive regular expressions\nto match multiple keys.\n\n```js\n\"$mod+([0-9])\" // $mod+0, $mod+1, $mod+2, etc...\n// equivalent regex: /^[0-9]$/\n```\n\n### Keybinding Sequences\n\nKeybindings can also consist of several key presses in a row:\n\n```js\n\"g i\" // i.e. \"Go to Inbox\"\n\"g a\" // i.e. \"Go to Archive\"\n\"ArrowUp ArrowUp ArrowDown ArrowDown ArrowLeft ArrowRight ArrowLeft ArrowRight B A\"\n```\n\nEach press can optionally be prefixed with modifier keys:\n\n```js\n\"$mod+K $mod+1\" // i.e. \"Toggle Level 1\"\n\"$mod+K $mod+2\" // i.e. \"Toggle Level 2\"\n\"$mod+K $mod+3\" // i.e. \"Toggle Level 3\"\n```\n\nEach press in the sequence must be pressed within 1000ms of the last.\n\n### Display the keyboard sequence\n\nYou can use the `parseKeybinding` method to get a structured representation of a\nkeyboard shortcut. It can be useful when you want to display it in a fancier way\nthan a plain string.\n\n```js\nimport { parseKeybinding } from \"tinykeys\"\n\nlet parsedShortcut = parseKeybinding(\"$mod+Shift+K $mod+1\")\n```\n\nResults into:\n\n<!-- prettier-ignore -->\n```js\n[\n  [[\"Meta\", \"Shift\"], \"K\"],\n  [[\"Meta\"], \"1\"],\n]\n```\n\n## Additional Configuration Options\n\nYou can configure the behavior of tinykeys in a couple ways using a third\n`options` parameter.\n\n```js\ntinykeys(\n  window,\n  {\n    M: toggleMute,\n  },\n  {\n    event: \"keyup\",\n    capture: true,\n  },\n)\n```\n\n### `options.event`\n\nValid values: `\"keydown\"`, `\"keyup\"`\n\nKey presses will listen to this event (default: `\"keydown\"`).\n\n> **Note:** Do not pass `\"keypress\"`, it is deprecated in browsers.\n\n### `options.timeout`\n\nKeybinding sequences will wait this long between key presses before cancelling\n(default: `1000`).\n\n> **Note:** Setting this value too low (i.e. `300`) will be too fast for many of\n> your users.\n","publish_time":1596581239822,"maintainers":[{"name":"thejameskyle","email":"me@thejameskyle.com"}],"_cnpm_publish_time":1596581239822,"dist-tags":{"latest":"4.0.1"}}