@codexteam/shortcuts

中文文档
1.2.0发布于 2022/08/05MITCommonJS零依赖近 30 天下载 7649

Library for handling keyboard shortcuts

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Creating a shortcut
  4. How it works
  5. Contribution

CodeX Shortcuts

CodeX shortcuts is a micro-library for dispatching keyboard shortcuts in Javascript. You don't need external dependencies.

Installation

Package is available on NPM

npm install @codexteam/shortcuts --save

Usage

Require module if you use Webpack or ES6

const Shortcut = require('@codexteam/shortcuts');

or

import Shortcut from '@codexteam/shortcuts'

Creating a shortcut

library provided as class, so to create a new shortcut, make a Shortcut instance with specified options.

Example:

let cmdA = new Shortcut({
    name : 'CMD+A',
    on : document.body,
    callback: function(event) {
        // your handler
    }
});

name - this is shortcut name, keys must be separated by +

on - binding element. Shortcut will be fired only on passed (this) element

callback - you code that defines the behaviour

If you have a single-page web application and you don't need shortcuts handler you can easily remove it

cmdA.remove();

How it works

Library parses data given on constructor, defines commands and keys.

Supported commands : shift, cmd, command, ctrl, control, windows, alt.

other words we pass as keys and special commands. Special commands are: backspace, enter, right, left, up, down, escape, insert, delete.

Contribution

To contribute, please fork, add your patch and tests for it (in the test/ folder) and submit a pull request.

CodeX is a team united of passionate people who loves web development, design and marketing.
We build a full-valued projects on the world area.

Feel free to give us a feedback [email protected]

Follow us on:

VK: https://vk.com/codex_team

Telegram: https://t.me/codex_team

Instagram: https://www.instagram.com/codex_team

版本与发布记录

@codexteam/shortcuts 共发布 4 个版本,首次发布于 2018/02/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.2.0latest2022/08/054 年前
1.1.12019/04/067 年前
1.1.02019/04/057 年前
1.0.02018/02/138 年前

关于 @codexteam/shortcuts 的常见问题

@codexteam/shortcuts 是什么?

Library for handling keyboard shortcuts

如何安装 @codexteam/shortcuts?

在项目目录运行 npm install @codexteam/shortcuts,或使用 pnpm add / yarn add / bun add。

@codexteam/shortcuts 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/codexteam__shortcuts 是否存在。

@codexteam/shortcuts 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@codexteam/shortcuts 可以商用吗?

@codexteam/shortcuts 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@codexteam/shortcuts 的下载量有多少?

根据 npm 官方下载统计,@codexteam/shortcuts 在 2026/10/10 – 2026/11/08 这 30 天内被下载 7,649 次,日均约 255 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@codexteam/shortcuts 还在维护吗?

最新版本 1.2.0 发布于 2022/08/05(4 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/02/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。