Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map 'meta' => 91, move 'command' to aliases #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var codes = exports.code = exports.codes = {
'down': 40,
'insert': 45,
'delete': 46,
'command': 91,
'meta': 91,
'right click': 93,
'numpad *': 106,
'numpad +': 107,
Expand All @@ -92,6 +92,7 @@ var codes = exports.code = exports.codes = {
// Helper aliases

var aliases = exports.aliases = {
'command': 91,
'windows': 91,
'⇧': 16,
'⌥': 18,
Expand Down Expand Up @@ -137,8 +138,13 @@ for (i = 0; i < 10; i++) codes['numpad '+i] = i + 96

var names = exports.names = exports.title = {} // title for backward compat

var canonicalCodes = exports._canonicalCodes = {} // for internal use

// Create reverse mapping
for (i in codes) names[codes[i]] = i
for (i in codes) {
names[codes[i]] = i
canonicalCodes[i] = codes[i]
}

// Add aliases
for (var alias in aliases) {
Expand Down
17 changes: 17 additions & 0 deletions test/keycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,20 @@ it('should return shift, ctrl, and alt for 16, 17, and 18', function() {
assert.strictEqual(keycode(17), 'ctrl')
assert.strictEqual(keycode(18), 'alt')
})

it('should not have mapping collisions in canonical codes', function() {
var dedupe = {}
var canon = keycode._canonicalCodes
for (var key in canon) {
var val = canon[key]
var isDupe = dedupe[val]
var dupeKey, dupeVal
if (isDupe) {
dupeKey = isDupe.key
dupeVal = isDupe.val
}
assert.ok(!isDupe, 'mapping conflict in canonical codes: ' + key + ' => ' + val + ', ' + dupeKey + ' => ' + dupeVal)
dedupe[val] = {key:key,val:val}
}
})