UNPKG

key

Version:

A tiny little keycode library

66 lines (55 loc) 1.48 kB
// Generated by CoffeeScript 1.3.3 (function() { 'use strict'; var isRef, iterator, key, _this = this, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }, __hasProp = {}.hasOwnProperty; isRef = require('./ref').isRef; key = {}; key.code = { special: require('./code/special'), arrow: require('./code/arrow'), punctuation: require('./code/punctuation'), alnum: require('./code/alnum'), brand: require('./code/brand') }; key.get = function(pressed) { return iterator(key.code, pressed); }; key.is = function(ref, pressed) { if (!isRef(ref)) { ref = iterator(ref, pressed); } if (isRef(ref)) { if (isRef(pressed)) { return pressed === ref; } else { return pressed === ref.code || __indexOf.call(ref.code, pressed) >= 0; } } else { return pressed === ref; } }; iterator = function(context, pressed) { var i, out, ref; for (i in context) { if (!__hasProp.call(context, i)) continue; ref = context[i]; if (isRef(ref)) { if (key.is(ref, pressed)) { return ref; } } else { out = iterator(ref, pressed); if (isRef(out)) { return out; } } } }; if (typeof window !== 'undefined') { window.key = key; } module.exports = key; }).call(this);