{"id":11209,"library":"keyname","title":"Keyboard Event Key Name Utility","description":"keyname is a JavaScript utility designed to translate numeric keyboard event key codes into more human-readable string names. For instance, it can convert a key code of `27` to \"esc\" or `65` to \"a\". Released as version `0.1.0` and last updated approximately 11 years ago, this package originates from the 'component' ecosystem, which was a frontend package manager system that predated or competed with the widespread adoption of npm for browser-side modules. Consequently, the package is considered abandoned, with no active development, bug fixes, or new features. While it serves its original function of mapping legacy `KeyboardEvent.keyCode` values, its relevance has significantly diminished due to the broad browser support for the native `KeyboardEvent.key` and `KeyboardEvent.code` properties, which directly provide string representations of pressed keys, handling variations in keyboard layouts and modifier states. This means developers typically no longer need a utility like `keyname` for new projects or modern browser targets. It reports having zero runtime dependencies and a minimal number of downstream dependents (8 projects), reflecting its specialized and now largely superseded role.","status":"abandoned","version":"0.1.0","language":"javascript","source_language":"en","source_url":"git://github.com/component/keyname","tags":["javascript","keys","keyboard","event"],"install":[{"cmd":"npm install keyname","lang":"bash","label":"npm"},{"cmd":"yarn add keyname","lang":"bash","label":"yarn"},{"cmd":"pnpm add keyname","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is CommonJS-only and does not support ES Modules. Using 'import' will result in an error.","wrong":"import keyname from 'keyname';","symbol":"keyname","correct":"const keyname = require('keyname');"}],"quickstart":{"code":"const keyname = require('keyname');\n\n// Get name for Escape key code\nconsole.log(keyname(27));\n// => \"esc\"\n\n// Get name for 'A' key code\nconsole.log(keyname(65));\n// => \"a\"\n\n// Get name for '1' key code\nconsole.log(keyname(49));\n// => \"1\"\n\n// Unknown key codes return undefined\nconsole.log(keyname(23123123));\n// => undefined\n\n// In modern browsers, consider using KeyboardEvent.key directly:\n// document.addEventListener('keydown', (event) => {\n//   console.log('Pressed key:', event.key);\n// });","lang":"javascript","description":"Demonstrates basic usage of `keyname` to convert numeric key codes to string names, also noting modern alternatives."},"warnings":[{"fix":"For new projects or modern browser support, prefer `KeyboardEvent.key` or `KeyboardEvent.code`. If targeting very old browsers where `KeyboardEvent.key` is unavailable, consider a more actively maintained polyfill or a library that provides graceful degradation.","message":"The package `keyname` is abandoned and has not been updated in over a decade. Its functionality, which relies on `KeyboardEvent.keyCode`, is superseded by the widely supported `KeyboardEvent.key` and `KeyboardEvent.code` properties available natively in modern browsers.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Ensure your project or file uses CommonJS (`const keyname = require('keyname');`) or configure your bundler (e.g., Webpack, Rollup, Parcel) to handle CJS modules in an ESM environment. However, migration to native `KeyboardEvent.key` is strongly recommended.","message":"This package is CommonJS-only (uses `require()`) and does not provide ES Module (`import`) exports. Attempting to import it using `import` syntax in an ESM context will lead to runtime errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Avoid using this package in new development. For existing projects, evaluate the risk and consider migrating to native browser APIs or a actively maintained alternative.","message":"The package is unmaintained, meaning it will not receive security updates, bug fixes, or new features. Relying on unmaintained code can introduce security vulnerabilities or compatibility issues with newer JavaScript runtimes or browser environments.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"This package is CJS-only. If you must use it, ensure your environment supports CommonJS modules. However, the recommended fix is to migrate away from `keyname` and use `KeyboardEvent.key` directly on the event object.","cause":"Attempting to use `require('keyname')` in an ES Module context (e.g., a modern browser environment or Node.js module with `\"type\": \"module\"` in package.json) where `require` is not available.","error":"ReferenceError: require is not defined"},{"fix":"Access `event.key` directly on the `KeyboardEvent` object instead of using `event.keyCode`. This provides a more robust and localized string representation of the pressed key.","cause":"While `keyname` processes `keyCode` values, the `keyCode` property itself on `KeyboardEvent` objects is deprecated by modern web standards and browsers.","error":"event.keyCode is deprecated"}],"ecosystem":"npm"}