
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Super performant and feature rich shortcuts management library.
⌘A
), this is useful for providing shortcut hints in tooltips.npm install --save shortcuts
This library provides a Shortcuts
class, which will manage your shortcuts, and a Shortcut
object, which provides some utilities.
The following keys can be used when defining a shortcut:
Other keys are not supported.
The Shortcuts class will be used for adding/removing/resetting/recording shortcuts. This is its interface:
class Shortcuts {
constructor ( options?: { shortcuts?: ShortcutDescriptor[]: capture?: boolean, target?: Node, shouldHandleEvent?: event => boolean } );
get (): ShortcutDescriptor[];
add ( descriptors: ShortcutDescriptor | ShortcutDescriptor[] );
remove ( descriptors: ShortcutDescriptor | ShortcutDescriptor[] );
reset ();
record ( handler: ( shortcut ) => any ): Function;
}
shortcuts
option accepts an optional array of shortcuts descriptors. More on this below.capture
option governs whether events are attached for the capturing phase or for the bubbling phase of the propagation.target
option accepts an optional DOM node, where the keyboard evenr listener will be attached to.shouldHandleEvent
option accepts an optional function which will be used for determining, for each keyboard event, if it should be handled by this library. By default that function is: event => !event.defaultPrevented
.A shortcut descriptor looks like this:
{
handler?: ( event: KeyboardEvent ) => boolean | void,
shortcut: string
}
Usage:
import {Shortcuts} from 'shortcuts';
const shortcuts = new Shortcuts ();
function CtrlBHandler () {};
shortcuts.add ([ // Adding some shortcuts
{ shortcut: 'Ctrl+A', handler: event => {
console.log ( event );
return true; // Returning true because we don't want other handlers for the same shortcut to be called later
}},
{ shortcut: 'Ctrl+B', handler: CtrlBHandler },
{ shortcut: 'CmdOrCtrl+K Shift+B', handler: () => {
// Doing something...
return true; // Returning true because we don't want other handlers for the same shortcut to be called later
}},
{ shortcut: '-Ctrl+A' } // Removing the previous shortcut
]);
shortcuts.remove ({ shortcut: 'Ctrl-B', handler: CtrlBHandler }); // Removing a single handler
shortcuts.remove ({ shortcut: 'Ctrl-A' }); // Removing all handlers bound to this shortcut
shortcuts.reset (); // Removing all shortcuts
const dispose = shortcuts.record ( shortcut => { // Recording shortcuts
console.log ( 'Shortcut recorded:', shortcut );
});
dispose (); // Stopping recording
true
.-Ctrl-A
) will actually remove that shortcut.The Shortcut object provides some utilities that you might need in your application. This is its interface:
const Shortcut = {
shortcut2id ( shortcut: string ): number[];
shortcut2accelerator ( shortcut: string ): string;
shortcut2symbols ( shortcut: string ): string;
};
Usage:
import {Shortcut} from 'shortcuts';
Shortcut.shortcut2accelerator ( 'Meta+Del' ); // => 'Cmd+Delete'
Shortcut.shortcut2symbols ( 'Cmd+Shift+A' ); // => '⌘⇧A'
shortcuts
package name on NPM! If you're looking for the previous package published under that name you can find it here (v0.x
).MIT © Fabio Spampinato
FAQs
Super performant and feature rich shortcuts management library.
The npm package shortcuts receives a total of 1,457 weekly downloads. As such, shortcuts popularity was classified as popular.
We found that shortcuts demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.