Permalink
Browse files

Initial commit

  • Loading branch information...
tj committed Oct 15, 2012
0 parents commit 5f8a38d0f3684a6e682a299b1bc16d477ff18e78
Showing with 115 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +11 −0 Makefile
  3. +49 −0 Readme.md
  4. +12 −0 component.json
  5. +41 −0 index.js
@@ -0,0 +1,2 @@
+components
+build
@@ -0,0 +1,11 @@
+
+build: components index.js
+ @component build --dev
+
+components:
+ @component install --dev
+
+clean:
+ rm -fr build components template.js
+
+.PHONY: clean
@@ -0,0 +1,49 @@
+
+# keyname
+
+ Keyboard event key name utility
+
+## Installation
+
+ $ component install component/keyname
+
+## API
+
+```js
+var keyname = require('keyname');
+
+keyname(27);
+// => "esc"
+
+keyname(23123123);
+// => undefined
+```
+
+## Keys
+
+ The following are supported:
+
+ - backspace
+ - tab
+ - enter
+ - shift
+ - ctrl
+ - alt
+ - capslock
+ - esc
+ - space
+ - pageup
+ - pagedown
+ - end
+ - home
+ - left
+ - up
+ - right
+ - down
+ - ins
+ - del
+ - meta
+
+## License
+
+ MIT
@@ -0,0 +1,12 @@
+{
+ "name": "keyname",
+ "repo": "component/keyname",
+ "description": "Keyboard event key name utility",
+ "version": "0.0.1",
+ "keywords": [],
+ "dependencies": {},
+ "development": {},
+ "scripts": [
+ "index.js"
+ ]
+}
@@ -0,0 +1,41 @@
+
+/**
+ * Key name map.
+ */
+
+var map = {
+ 8: 'backspace',
+ 9: 'tab',
+ 13: 'enter',
+ 16: 'shift',
+ 17: 'ctrl',
+ 18: 'alt',
+ 20: 'capslock',
+ 27: 'esc',
+ 32: 'space',
+ 33: 'pageup',
+ 34: 'pagedown',
+ 35: 'end',
+ 36: 'home',
+ 37: 'left',
+ 38: 'up',
+ 39: 'right',
+ 40: 'down',
+ 45: 'ins',
+ 46: 'del',
+ 91: 'meta',
+ 93: 'meta',
+ 224: 'meta'
+};
+
+/**
+ * Return key name for `n`.
+ *
+ * @param {Number} n
+ * @return {String}
+ * @api public
+ */
+
+module.exports = function(n){
+ return map[n];
+};

0 comments on commit 5f8a38d

Please sign in to comment.