diff --git a/index.js b/index.js index e837b2d..6d22141 100644 --- a/index.js +++ b/index.js @@ -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, @@ -92,6 +92,7 @@ var codes = exports.code = exports.codes = { // Helper aliases var aliases = exports.aliases = { + 'command': 91, 'windows': 91, '⇧': 16, '⌥': 18, @@ -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) { diff --git a/test/keycode.js b/test/keycode.js index 7485e77..0efe45a 100644 --- a/test/keycode.js +++ b/test/keycode.js @@ -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} + } +}) +