| 'use strict'; | ||
| Object.defineProperty(exports, "__esModule", { | ||
| value: true | ||
| }); | ||
| exports.default = keycodes; | ||
| var keys = { | ||
| 'ctrl': 17, | ||
| 'control': 17, | ||
| 'alt': 18, | ||
| 'option': 18, | ||
| 'shift': 16, | ||
| 'windows': 91, | ||
| 'command': 91, | ||
| 'esc': 27, | ||
| 'escape': 27, | ||
| '`': 192, | ||
| '-': 189, | ||
| '=': 187, | ||
| 'backspace': 8, | ||
| 'tab': 9, | ||
| '\\': 220, | ||
| '[': 219, | ||
| ']': 221, | ||
| ';': 186, | ||
| '\'': 222, | ||
| 'enter': 13, | ||
| 'return': 13, | ||
| ',': 188, | ||
| '.': 190, | ||
| '/': 191, | ||
| 'space': 32, | ||
| 'pause': 19, | ||
| 'break': 19, | ||
| 'insert': 45, | ||
| 'delete': 46, | ||
| 'home': 36, | ||
| 'end': 35, | ||
| 'pageup': 33, | ||
| 'pagedown': 34, | ||
| 'left': 37, | ||
| 'up': 38, | ||
| 'right': 39, | ||
| 'down': 40, | ||
| 'capslock': 20, | ||
| 'numlock': 144, | ||
| 'scrolllock': 145 | ||
| }; | ||
| for (var f = 1; f < 20; f++) { | ||
| keys['f' + f] = 111 + f; | ||
| } | ||
| function keycodes(input) { | ||
| if (typeof input === 'string') { | ||
| return code(input); | ||
| } | ||
| if (typeof input === 'number') { | ||
| return key(input); | ||
| } | ||
| } | ||
| function code(input) { | ||
| var code = keys[input.toLowerCase()]; | ||
| if (code !== undefined) { | ||
| return code; | ||
| } | ||
| if (input.length === 1) { | ||
| return input.toUpperCase().charCodeAt(0); | ||
| } | ||
| return undefined; | ||
| } | ||
| function key(input) { | ||
| for (var k in keys) { | ||
| if (keys.hasOwnProperty(k)) { | ||
| if (keys[k] === input) { | ||
| return k; | ||
| } | ||
| } | ||
| } | ||
| return String.fromCharCode(input).toLowerCase(); | ||
| } | ||
| module.exports = exports['default']; |
+22
-17
@@ -1,4 +0,2 @@ | ||
| 'use strict'; | ||
| var keys = { | ||
| const keys = { | ||
| 'ctrl': 17, | ||
@@ -44,35 +42,42 @@ 'control': 17, | ||
| 'scrolllock': 145 | ||
| }; | ||
| } | ||
| for (var f = 1; f < 20; f++) { | ||
| keys['f' + f] = 111 + f; | ||
| keys['f' + f] = 111 + f | ||
| } | ||
| module.exports = function (input) { | ||
| if (typeof input === 'string') return code(input); | ||
| if (typeof input === 'number') return key(input); | ||
| }; | ||
| export default function keycodes (input) { | ||
| if (typeof input === 'string') { | ||
| return code(input) | ||
| } | ||
| if (typeof input === 'number') { | ||
| return key(input) | ||
| } | ||
| } | ||
| function code (input) { | ||
| var code = keys[input.toLowerCase()]; | ||
| var code = keys[input.toLowerCase()] | ||
| if (code !== undefined) { | ||
| return code; | ||
| return code | ||
| } | ||
| if (input.length === 1) { | ||
| return input.toUpperCase().charCodeAt(0); | ||
| return input.toUpperCase().charCodeAt(0) | ||
| } | ||
| return undefined; | ||
| return undefined | ||
| } | ||
| function key(input) { | ||
| function key (input) { | ||
| for (var k in keys) { | ||
| if (keys.hasOwnProperty(k)) { | ||
| if (keys[k] === input) return k; | ||
| if (keys[k] === input) { | ||
| return k | ||
| } | ||
| } | ||
| } | ||
| return String.fromCharCode(input).toLowerCase(); | ||
| return String.fromCharCode(input).toLowerCase() | ||
| } |
+50
-9
| { | ||
| "name": "keycodes", | ||
| "version": "1.0.0", | ||
| "description": "Key codes and names", | ||
| "version": "0.2.5", | ||
| "main": "dist", | ||
| "files": [ | ||
| "index.js", | ||
| "dist" | ||
| ], | ||
| "engines": { | ||
| "node": ">=4" | ||
| }, | ||
| "scripts": { | ||
| "test": "standard && ava", | ||
| "prepublish": "babel index.js --out-dir dist", | ||
| "postpublish": "rimraf dist && git push --follow-tags" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/andrepolischuk/keycodes.git" | ||
| }, | ||
| "keywords": [ | ||
@@ -10,13 +27,37 @@ "key", | ||
| ], | ||
| "repository": "andrepolischuk/keycodes", | ||
| "author": "Andrey Polischuk <me@andrepolischuk.com> (https://andrepolischuk.com)", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/andrepolischuk/keycodes/issues" | ||
| }, | ||
| "homepage": "https://github.com/andrepolischuk/keycodes#readme", | ||
| "devDependencies": { | ||
| "ava": "^0.11.0" | ||
| "ava": "^0.18.2", | ||
| "babel-cli": "^6.24.0", | ||
| "babel-eslint": "^7.2.3", | ||
| "babel-plugin-add-module-exports": "^0.2.1", | ||
| "babel-plugin-transform-object-rest-spread": "^6.23.0", | ||
| "babel-preset-es2015": "^6.24.1", | ||
| "babel-register": "^6.24.0", | ||
| "cross-env": "^5.0.1", | ||
| "rimraf": "^2.5.2", | ||
| "standard": "^10.0.2" | ||
| }, | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "ava", | ||
| "postpublish": "git push --follow-tags" | ||
| "standard": { | ||
| "parser": "babel-eslint" | ||
| }, | ||
| "author": "Andrey Polischuk <me@andrepolischuk.com> (https://andrepolischuk.com)", | ||
| "license": "MIT" | ||
| "babel": { | ||
| "presets": [ | ||
| "es2015" | ||
| ], | ||
| "plugins": [ | ||
| "add-module-exports", | ||
| "transform-object-rest-spread" | ||
| ] | ||
| }, | ||
| "ava": { | ||
| "require": [ | ||
| "babel-register" | ||
| ] | ||
| } | ||
| } |
| root = true | ||
| [*] | ||
| indent_style = space | ||
| indent_size = 2 | ||
| end_of_line = lf | ||
| charset = utf-8 | ||
| trim_trailing_whitespace = true | ||
| insert_final_newline = true | ||
| [*.md] | ||
| trim_trailing_whitespace = false |
Sorry, the diff of this file is not supported yet
| language: node_js | ||
| node_js: | ||
| - '0.10' | ||
| - '0.12' | ||
| - 'stable' |
-184
| 'use strict'; | ||
| var test = require('ava'); | ||
| var keycode = require('./'); | ||
| test('return code', function (t) { | ||
| t.is(keycode('ctrl'), 17); | ||
| t.is(keycode('control'), 17); | ||
| t.is(keycode('alt'), 18); | ||
| t.is(keycode('option'), 18); | ||
| t.is(keycode('shift'), 16); | ||
| t.is(keycode('windows'), 91); | ||
| t.is(keycode('command'), 91); | ||
| t.is(keycode('esc'), 27); | ||
| t.is(keycode('escape'), 27); | ||
| t.is(keycode('`'), 192); | ||
| t.is(keycode('-'), 189); | ||
| t.is(keycode('='), 187); | ||
| t.is(keycode('backspace'), 8); | ||
| t.is(keycode('tab'), 9); | ||
| t.is(keycode('\\'), 220); | ||
| t.is(keycode('['), 219); | ||
| t.is(keycode(']'), 221); | ||
| t.is(keycode(';'), 186); | ||
| t.is(keycode('\''), 222); | ||
| t.is(keycode('enter'), 13); | ||
| t.is(keycode('return'), 13); | ||
| t.is(keycode(','), 188); | ||
| t.is(keycode('.'), 190); | ||
| t.is(keycode('/'), 191); | ||
| t.is(keycode('space'), 32); | ||
| t.is(keycode('pause'), 19); | ||
| t.is(keycode('break'), 19); | ||
| t.is(keycode('insert'), 45); | ||
| t.is(keycode('delete'), 46); | ||
| t.is(keycode('home'), 36); | ||
| t.is(keycode('end'), 35); | ||
| t.is(keycode('pageup'), 33); | ||
| t.is(keycode('pagedown'), 34); | ||
| t.is(keycode('left'), 37); | ||
| t.is(keycode('up'), 38); | ||
| t.is(keycode('right'), 39); | ||
| t.is(keycode('down'), 40); | ||
| t.is(keycode('capslock'), 20); | ||
| t.is(keycode('numlock'), 144); | ||
| t.is(keycode('scrolllock'), 145); | ||
| t.is(keycode('f1'), 112); | ||
| t.is(keycode('f2'), 113); | ||
| t.is(keycode('f3'), 114); | ||
| t.is(keycode('f4'), 115); | ||
| t.is(keycode('f5'), 116); | ||
| t.is(keycode('f6'), 117); | ||
| t.is(keycode('f7'), 118); | ||
| t.is(keycode('f8'), 119); | ||
| t.is(keycode('f9'), 120); | ||
| t.is(keycode('f10'), 121); | ||
| t.is(keycode('f11'), 122); | ||
| t.is(keycode('f12'), 123); | ||
| t.is(keycode('0'), 48); | ||
| t.is(keycode('1'), 49); | ||
| t.is(keycode('2'), 50); | ||
| t.is(keycode('3'), 51); | ||
| t.is(keycode('4'), 52); | ||
| t.is(keycode('5'), 53); | ||
| t.is(keycode('6'), 54); | ||
| t.is(keycode('7'), 55); | ||
| t.is(keycode('8'), 56); | ||
| t.is(keycode('9'), 57); | ||
| t.is(keycode('a'), 65); | ||
| t.is(keycode('b'), 66); | ||
| t.is(keycode('c'), 67); | ||
| t.is(keycode('d'), 68); | ||
| t.is(keycode('e'), 69); | ||
| t.is(keycode('f'), 70); | ||
| t.is(keycode('g'), 71); | ||
| t.is(keycode('h'), 72); | ||
| t.is(keycode('i'), 73); | ||
| t.is(keycode('j'), 74); | ||
| t.is(keycode('k'), 75); | ||
| t.is(keycode('l'), 76); | ||
| t.is(keycode('m'), 77); | ||
| t.is(keycode('n'), 78); | ||
| t.is(keycode('o'), 79); | ||
| t.is(keycode('p'), 80); | ||
| t.is(keycode('q'), 81); | ||
| t.is(keycode('r'), 82); | ||
| t.is(keycode('s'), 83); | ||
| t.is(keycode('t'), 84); | ||
| t.is(keycode('u'), 85); | ||
| t.is(keycode('v'), 86); | ||
| t.is(keycode('w'), 87); | ||
| t.is(keycode('x'), 88); | ||
| t.is(keycode('y'), 89); | ||
| t.is(keycode('z'), 90); | ||
| }); | ||
| test('return key', function (t) { | ||
| t.is(keycode(17), 'ctrl'); | ||
| t.is(keycode(18), 'alt'); | ||
| t.is(keycode(16), 'shift'); | ||
| t.is(keycode(91), 'windows'); | ||
| t.is(keycode(27), 'esc'); | ||
| t.is(keycode(192), '`'); | ||
| t.is(keycode(189), '-'); | ||
| t.is(keycode(187), '='); | ||
| t.is(keycode(8), 'backspace'); | ||
| t.is(keycode(9), 'tab'); | ||
| t.is(keycode(220), '\\'); | ||
| t.is(keycode(219), '['); | ||
| t.is(keycode(221), ']'); | ||
| t.is(keycode(186), ';'); | ||
| t.is(keycode(222), '\''); | ||
| t.is(keycode(13), 'enter'); | ||
| t.is(keycode(188), ','); | ||
| t.is(keycode(190), '.'); | ||
| t.is(keycode(191), '/'); | ||
| t.is(keycode(32), 'space'); | ||
| t.is(keycode(19), 'pause'); | ||
| t.is(keycode(45), 'insert'); | ||
| t.is(keycode(46), 'delete'); | ||
| t.is(keycode(36), 'home'); | ||
| t.is(keycode(35), 'end'); | ||
| t.is(keycode(33), 'pageup'); | ||
| t.is(keycode(34), 'pagedown'); | ||
| t.is(keycode(37), 'left'); | ||
| t.is(keycode(38), 'up'); | ||
| t.is(keycode(39), 'right'); | ||
| t.is(keycode(40), 'down'); | ||
| t.is(keycode(20), 'capslock'); | ||
| t.is(keycode(144), 'numlock'); | ||
| t.is(keycode(145), 'scrolllock'); | ||
| t.is(keycode(112), 'f1'); | ||
| t.is(keycode(113), 'f2'); | ||
| t.is(keycode(114), 'f3'); | ||
| t.is(keycode(115), 'f4'); | ||
| t.is(keycode(116), 'f5'); | ||
| t.is(keycode(117), 'f6'); | ||
| t.is(keycode(118), 'f7'); | ||
| t.is(keycode(119), 'f8'); | ||
| t.is(keycode(120), 'f9'); | ||
| t.is(keycode(121), 'f10'); | ||
| t.is(keycode(122), 'f11'); | ||
| t.is(keycode(123), 'f12'); | ||
| t.is(keycode(48), '0'); | ||
| t.is(keycode(49), '1'); | ||
| t.is(keycode(50), '2'); | ||
| t.is(keycode(51), '3'); | ||
| t.is(keycode(52), '4'); | ||
| t.is(keycode(53), '5'); | ||
| t.is(keycode(54), '6'); | ||
| t.is(keycode(55), '7'); | ||
| t.is(keycode(56), '8'); | ||
| t.is(keycode(57), '9'); | ||
| t.is(keycode(65), 'a'); | ||
| t.is(keycode(66), 'b'); | ||
| t.is(keycode(67), 'c'); | ||
| t.is(keycode(68), 'd'); | ||
| t.is(keycode(69), 'e'); | ||
| t.is(keycode(70), 'f'); | ||
| t.is(keycode(71), 'g'); | ||
| t.is(keycode(72), 'h'); | ||
| t.is(keycode(73), 'i'); | ||
| t.is(keycode(74), 'j'); | ||
| t.is(keycode(75), 'k'); | ||
| t.is(keycode(76), 'l'); | ||
| t.is(keycode(77), 'm'); | ||
| t.is(keycode(78), 'n'); | ||
| t.is(keycode(79), 'o'); | ||
| t.is(keycode(80), 'p'); | ||
| t.is(keycode(81), 'q'); | ||
| t.is(keycode(82), 'r'); | ||
| t.is(keycode(83), 's'); | ||
| t.is(keycode(84), 't'); | ||
| t.is(keycode(85), 'u'); | ||
| t.is(keycode(86), 'v'); | ||
| t.is(keycode(87), 'w'); | ||
| t.is(keycode(88), 'x'); | ||
| t.is(keycode(89), 'y'); | ||
| t.is(keycode(90), 'z'); | ||
| }); | ||
| test('Bogus keycodes', function (t) { | ||
| t.is(keycode(Math.POSITIVE_INFINITY), undefined); | ||
| t.is(keycode('foo'), undefined); | ||
| }); |
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
1
-50%0
-100%5941
-33.3%10
900%5
-37.5%151
-39.36%2
Infinity%