New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@codexteam/shortcuts

Package Overview
Dependencies
Maintainers
5
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@codexteam/shortcuts - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

dist/shortcuts.js

2

bundleComment.js
var pkg = require('./package');
module.exports = `${pkg.description}
@copyright ${pkg.copyright}
@copyright ${pkg.author}
@license ${pkg.license}
@author ${pkg.author}
@version ${pkg.version}`;
{
"name": "@codexteam/shortcuts",
"version": "1.0.0",
"version": "1.1.0",
"description": "Library for handling keyboard shortcuts",
"main": "./lib/shortcuts.js",
"directories": {
"lib": "lib"
},
"main": "./dist/shortcuts.js",
"scripts": {
"test": "test",
"build": "webpack"
"build:dev": "webpack --mode development",
"build:watch": "webpack --mode development --watch",
"build": "webpack --mode production"
},

@@ -17,3 +16,3 @@ "repository": {

},
"author": "CodeX (https://ifmo.su)",
"author": "CodeX (https://codex.so)",
"license": "MIT",

@@ -25,9 +24,21 @@ "bugs": {

"devDependencies": {
"babel": "^6.23.0",
"babel-env": "^2.4.1",
"babel-loader": "^7.1.2",
"eslint": "^4.17.0",
"eslint-loader": "^1.9.0",
"webpack": "^3.10.0"
"@babel/core": "^7.3.4",
"@babel/plugin-proposal-decorators": "^7.4.0",
"@babel/plugin-transform-runtime": "^7.3.4",
"@babel/polyfill": "^7.2.5",
"@babel/preset-env": "^7.3.4",
"@babel/register": "^7.0.0",
"@babel/runtime": "^7.3.4",
"babel-eslint": "^10.0.1",
"babel-loader": "^8.0.5",
"babel-plugin-add-module-exports": "^1.0.0",
"babel-plugin-class-display-name": "^2.1.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"eslint": "^5.16.0",
"eslint-loader": "^2.1.2",
"path": "^0.12.7",
"uglifyjs-webpack-plugin": "^2.1.2",
"webpack": "^4.23.1",
"webpack-cli": "^3.1.2"
}
}

@@ -5,3 +5,3 @@ /**

*
* @copyright CodeX <team@ifmo.su>
* @copyright CodeX <team@codex.so>
* @license MIT https://github.com/codex-team/dispatcher/LICENSE

@@ -22,58 +22,8 @@ * @author @khaydarovm https://github.com/khaydarov

/**
* List of key codes
* @typedef {ShortcutConfig} ShortcutConfig
* @property {String} name - shortcut name
* @property {Element} on - element that passed on shortcut creation
* @property {Function} callback - custom user function
*/
const keyCodes = {
'0' : 48,
'1' : 49,
'2' : 50,
'3' : 51,
'4' : 52,
'5' : 53,
'6' : 54,
'7' : 55,
'8' : 56,
'9' : 57,
'A' : 65,
'B' : 66,
'C' : 67,
'D' : 68,
'E' : 69,
'F' : 70,
'G' : 71,
'H' : 72,
'I' : 73,
'J' : 74,
'K' : 75,
'L' : 76,
'M' : 77,
'N' : 78,
'O' : 79,
'P' : 80,
'Q' : 81,
'R' : 82,
'S' : 83,
'T' : 84,
'U' : 85,
'V' : 86,
'W' : 87,
'X' : 88,
'Y' : 89,
'Z' : 90,
'BACKSPACE' : 8,
'ENTER' : 13,
'ESCAPE' : 27,
'LEFT' : 37,
'UP' : 38,
'RIGHT' : 39,
'DOWN' : 40,
'INSERT' : 45,
'DELETE' : 46
};
const supportedCommands = {
'CMD' : ['CMD', 'CONTROL', 'COMMAND', 'WINDOWS', 'CTRL'],
'SHIFT' : [ 'SHIFT' ],
'ALT' : ['ALT', 'OPTION']
};
/**

@@ -84,90 +34,163 @@ * @class Shortcut

* - target: element which registered on shortcut creation
*
* @typedef {ShortcutConfig} ShortcutConfig
* @property {String} name - shortcut name
* @property {Element} on - element that passed on shortcut creation
* @property {Function} callback - custom user function
*/
export default class Shortcut {
/**
* Create new shortcut
* @param {ShortcutConfig} shortcut
* @constructor
*/
constructor(shortcut) {
this.commands = {};
this.keys = {};
class Shortcut {
/**
* @return {{SHIFT: string[], CMD: string[], ALT: string[]}}
*/
static get supportedCommands() {
return {
'SHIFT': [ 'SHIFT' ],
'CMD': ['CMD', 'CONTROL', 'COMMAND', 'WINDOWS', 'CTRL'],
'ALT': ['ALT', 'OPTION'],
};
}
this.parseShortcutName(shortcut.name);
/**
* List of key codes
*/
static get keyCodes() {
return {
'0' : 48,
'1' : 49,
'2' : 50,
'3' : 51,
'4' : 52,
'5' : 53,
'6' : 54,
'7' : 55,
'8' : 56,
'9' : 57,
'A' : 65,
'B' : 66,
'C' : 67,
'D' : 68,
'E' : 69,
'F' : 70,
'G' : 71,
'H' : 72,
'I' : 73,
'J' : 74,
'K' : 75,
'L' : 76,
'M' : 77,
'N' : 78,
'O' : 79,
'P' : 80,
'Q' : 81,
'R' : 82,
'S' : 83,
'T' : 84,
'U' : 85,
'V' : 86,
'W' : 87,
'X' : 88,
'Y' : 89,
'Z' : 90,
'BACKSPACE' : 8,
'ENTER' : 13,
'ESCAPE' : 27,
'LEFT' : 37,
'UP' : 38,
'RIGHT' : 39,
'DOWN' : 40,
'INSERT' : 45,
'DELETE' : 46
};
}
this.element = shortcut.on;
this.callback = shortcut.callback;
/**
* @constructor
*
* Create new shortcut
* @param {ShortcutConfig} shortcut
*/
constructor(shortcut) {
this.commands = {};
this.keys = {};
this.name = shortcut.name;
this.executeShortcut = (event) => {
this.execute(event);
};
this.element.addEventListener('keydown', this.executeShortcut, false);
}
this.parseShortcutName(shortcut.name);
/**
* Parses string to get shortcut commands in uppercase
* @param {String} shortcut
*/
parseShortcutName(shortcut) {
shortcut = shortcut.split('+');
this.element = shortcut.on;
this.callback = shortcut.callback;
for (let key = 0; key < shortcut.length; key++) {
shortcut[key] = shortcut[key].toUpperCase();
this.executeShortcut = (event) => {
this.execute(event);
};
this.element.addEventListener('keydown', this.executeShortcut, false);
}
if (shortcut[key].length > 1) {
for (let command in supportedCommands) {
if (supportedCommands[command].includes(shortcut[key])) {
this.commands[command] = true;
}
}
} else {
this.keys[shortcut[key]] = true;
}
/**
* Parses string to get shortcut commands in uppercase
* @param {String} shortcut
*/
parseShortcutName(shortcut) {
shortcut = shortcut.split('+');
for (let key = 0; key < shortcut.length; key++) {
shortcut[key] = shortcut[key].toUpperCase();
let isCommand = false;
for (let command in Shortcut.supportedCommands) {
if (Shortcut.supportedCommands[command].includes(shortcut[key])) {
this.commands[command] = true;
isCommand = true;
break;
}
}
if (!isCommand) {
this.keys[shortcut[key]] = true;
}
}
/**
* Check all passed commands and keys before firing callback
* @param event
*/
execute(event) {
let cmdKey = event.ctrlKey || event.metaKey,
shiftKey = event.shiftKey,
altKey = event.altKey,
passed = {
'CMD': cmdKey,
'SHIFT': shiftKey,
'ALT': altKey
};
for(let command in Shortcut.supportedCommands) {
if (!this.commands[command]) {
this.commands[command] = false;
}
}
}
let command,
allCommandsPassed = true;
/**
* Check all passed commands and keys before firing callback
* @param event
*/
execute(event) {
let cmdKey = event.ctrlKey || event.metaKey,
shiftKey = event.shiftKey,
altKey = event.altKey,
passed = {
'CMD': cmdKey,
'SHIFT': shiftKey,
'ALT': altKey
};
for (command in this.commands) {
allCommandsPassed = allCommandsPassed && passed[command];
}
let command,
allCommandsPassed = true;
let key,
allKeysPassed = true;
for (command in this.commands) {
if (this.commands[command] !== passed[command]) {
allCommandsPassed = false;
}
}
let key,
allKeysPassed = true;
for (key in this.keys) {
allKeysPassed = allKeysPassed && ( event.keyCode === keyCodes[key] );
}
for (key in this.keys) {
allKeysPassed = allKeysPassed && (event.keyCode === Shortcut.keyCodes[key]);
}
if (allCommandsPassed && allKeysPassed) {
this.callback(event);
}
if (allCommandsPassed && allKeysPassed) {
this.callback(event);
}
}
/**
* Destroy shortcut: remove listener from element
*/
remove() {
this.element.removeEventListener('keydown', this.executeShortcut);
}
}
/**
* Destroy shortcut: remove listener from element
*/
remove() {
this.element.removeEventListener('keydown', this.executeShortcut);
}
}
export default Shortcut;

@@ -8,74 +8,66 @@ /**

const path = require('path');
const webpack = require('webpack');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
/**
* Get package params
*/
var pkg = require('./package');
/**
* Define entry point
*/
var entry = './src/shortcuts.js';
/**
* @return {String} Bundle header with Module description
*/
var bundleComment = require('./bundleComment.js');
const bundleComment = require('./bundleComment.js');
/**
* Set bundle params
*
* filename - main bundle file from package.json
* library - module name from package.json
* libraryTarget - "umd" is a way for your library to work with all the module
* definitions (and where aren't modules at all).
* It will work with CommonJS, AMD and as global variable.
* Final webpack config
*/
var output = {
filename: pkg.main,
library: pkg.exportModuleName,
var config = {
/**
* Entry point
*/
entry: './src/shortcuts.js',
/**
* Set bundle params
*
* filename - main bundle file from package.json
* library - module name from package.json
* libraryTarget - 'umd' is a way for your library to work with all the module
* definitions (and where aren't modules at all).
* It will work with CommonJS, AMD and as global variable.
*/
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'shortcuts.js',
library: 'Shortcut',
libraryTarget: 'umd',
};
var useModule = {
libraryExport: 'default'
},
/**
* Tell webpack what directories should be searched when resolving modules.
*/
resolve: {
modules: [path.join(__dirname, 'src'), 'node_modules'],
extensions: [ '.js' ]
},
module: {
rules: [
/**
* Process JS files
*/
{
test : /\.js$/,
use : [
/** Babel loader */
{
loader: 'babel-loader',
options: {
presets: [ 'env' ]
}
},
/** ES lint For webpack build */
{
loader: 'eslint-loader',
options: {
fix: true
}
}
]
}
/**
* Process JS files
*/
{
test : /\.js$/,
exclude: /node_modules/,
use : [
{
loader: 'babel-loader',
options: {
cacheDirectory: true,
}
},
{
loader: 'eslint-loader',
}
]
}
]
};
/**
* List of plugins to run
*/
var plugins = [
/** Minify JS and CSS */
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
}),
/** Block biuld if errors found */
new webpack.NoEmitOnErrorsPlugin(),
},
plugins: [
/**

@@ -86,18 +78,11 @@ * Add comments before output file lib/moduleDispatcher.js

new webpack.BannerPlugin({
banner: bundleComment
banner: bundleComment
})
],
];
/**
* Final webpack config
*/
var config = {
entry: entry,
output: output,
module: useModule,
plugins: plugins,
watch: true
optimization: {
minimizer: [ new UglifyJsPlugin() ],
},
};
module.exports = config;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc