{"name":"keyboard-key","version":"1.0.1","description":"A simple utility for determining the KeyboardEvent.key property from a keyboard event.","main":"src/keyboardKey.js","author":{"name":"Levi Thomason"},"license":"MIT","scripts":{"lint":"prettier --list-different \"**/*.js?(on|x)\" && eslint \"**/*.js?(on|x)\"","lint:fix":"prettier --write \"**/*.js?(on|x)\" && eslint --fix \"**/*.js?(on|x)\"","toc":"markdown-toc -i README.md","precommit":"yarn toc && lint-staged","prerelease":"yarn lint && yarn test","release:major":"yarn prerelease && ta-script npm/release major","release:minor":"yarn prerelease && ta-script npm/release minor","release:patch":"yarn prerelease && ta-script npm/release patch","test":"jest","test:watch":"yarn jest -- --watchAll"},"jest":{"collectCoverage":true,"collectCoverageFrom":["src/**/*.js","!**/node_modules/**","!**/test/**"],"coverageDirectory":"coverage","coverageThreshold":{"global":{"branches":50,"functions":50,"lines":50,"statements":50}},"roots":["./src","./test"],"testMatch":["**/*.spec.js"]},"lint-staged":{"*.js?(on|x)":["prettier --write","eslint --fix","git add"]},"devDependencies":{"babel-eslint":"^8.0.0","eslint":"^4.4.1","eslint-config-prettier":"^2.3.0","eslint-plugin-json":"^1.2.0","eslint-plugin-prettier":"^2.2.0","greenkeeper-lockfile":"^1.8.1","husky":"^0.14.3","jest":"^21.0.0","lint-staged":"^4.0.3","markdown-toc":"^1.1.0","prettier":"^1.6.1","ta-scripts":"^2.5.2"},"gitHead":"acc2598d2a7c85f39171df5fdbdc346e88b06dc5","_id":"keyboard-key@1.0.1","_npmVersion":"5.3.0","_nodeVersion":"8.2.1","_npmUser":{"name":"levithomason","email":"me@levithomason.com"},"dist":{"integrity":"sha512-OAfjaSI917BOonwfH6LQHMZJRv5035jjZvgElouB/DM4I7l5zEjrA15RD80YwIjhN69xqEfWCZIbhBcGpb85Ig==","shasum":"a946294fe59ad5431c63a3ea269f023e51fac6aa","tarball":"http://registry-npm.ywwl.com/keyboard-key/download/keyboard-key-1.0.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDQJraum/u0W2cx1NVeZJUR8Cwxx64EfsidGBIHU6SM4QIgPwVzMoH1lGpuNditSpSyWbm3etwPgrdw5dOcRXHwpew="}],"size":40691,"noattachment":false,"key":"/keyboard-key/-/keyboard-key-1.0.1.tgz"},"maintainers":[{"name":"levithomason","email":"me@levithomason.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/keyboard-key-1.0.1.tgz_1505712681165_0.7863338005263358"},"directories":{},"readme":"keyboard-key\n[![CircleCI](https://img.shields.io/circleci/project/github/levithomason/keyboard-key/master.svg?style=flat-square)](https://circleci.com/gh/levithomason/keyboard-key/master)\n[![Codecov](https://img.shields.io/codecov/c/github/levithomason/keyboard-key/master.svg?style=flat-square)](https://codecov.io/gh/levithomason/keyboard-key)\n[![David](https://img.shields.io/david/levithomason/keyboard-key.svg?style=flat-square)](https://david-dm.org/levithomason/keyboard-key)\n[![npm](https://img.shields.io/npm/v/keyboard-key.svg?style=flat-square)](https://www.npmjs.com/package/keyboard-key)\n============\n\nA simple utility for determining the `KeyboardEvent.key` property from a keyboard event.\n\n<!-- toc -->\n\n- [Install](#install)\n- [Usage](#usage)\n  * [getKey()](#getkey)\n  * [getCode()](#getcode)\n- [Why?](#why)\n- [Locale Caveat](#locale-caveat)\n\n<!-- tocstop -->\n\n## Install\n\n```\nyarn add keyboard-key\n\n# or\n\nnpm install keyboard-key\n```\n\n## Usage\n\n### getKey()\n\nGet the `key` property value from an event.\n\n```js\ndocument.addEventListener('keydown', event => {\n  const key = keyboardKey.getKey(event)\n\n  switch (key) {\n    case 'Escape':\n      // handle escape key\n      break\n    default:\n      break\n  }\n})\n```\n\n>See [MDN][2] or the source for a full list of `key` values.\n\n### getCode()\n\nYou can also get the normalized `keyCode` from an event.  `keyboard-key` includes a hash of `key` names to `keyCode`s for easy comparisons:\n\n```js\ndocument.addEventListener('keydown', event => {\n  const code = keyboardKey.getCode(event)\n\n  switch (code) {\n    case keyboardKey.Escape: // 27\n      // handle escape key\n      break\n    default:\n      break\n  }\n})\n```\n\n## Why?\n\nMost previous key identifying KeyboardEvent properties have been pressed have been deprecated in favor of `Keyboard.key`.\n\n:-1: `KeyboardEvent.char`  \n:-1: `KeyboardEvent.charCode`  \n:-1: `KeyboardEvent.keyCode`  \n:-1: `KeyboardEvent.keyIdentifier`  \n:-1: `KeyboardEvent.keyLocation`  \n:-1: `KeyboardEvent.which`\n\n:+1: `KeyboardEvent.key`\n\nUnfortunately, `KeyboardEvent.key` does not yet have full [browser support][3].  Leaving the browsers without a reliable property for identifying keyboard event keys.\n\n## Locale Caveat\n\nThis utility interprets use of the shift key when inferring event `key` values.  Example, an event describing <kbd>shift</kbd>+<kbd>/</kbd> would result in a `key` value of <kbd>?</kbd>.  This logic assumes an `en-US` locale keyboard layout.  This will **not work** if you are using a different locale such as a German layout where <kbd>/</kbd> is <kbd>shift</kbd>+<kbd>7</kbd>. \n\n[1]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key\n[2]: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values\n[3]: http://caniuse.com/#feat=keyboardevent-key\n","publish_time":1505712681273,"_cnpm_publish_time":1505712681273,"dist-tags":{"latest":"1.1.0"}}