Comparing version 0.1.2 to 0.1.3
@@ -95,7 +95,15 @@ 'use strict'; | ||
var object = parseHotkey(hotkey, options); | ||
var ret = event == null ? function (e) { | ||
return compareHotkey(object, e); | ||
} : compareHotkey(object, event); | ||
if (!Array.isArray(hotkey)) { | ||
hotkey = [hotkey]; | ||
} | ||
var array = hotkey.map(function (string) { | ||
return parseHotkey(string, options); | ||
}); | ||
var check = function check(e) { | ||
return array.some(function (object) { | ||
return compareHotkey(object, e); | ||
}); | ||
}; | ||
var ret = event == null ? check : check(event); | ||
return ret; | ||
@@ -139,2 +147,8 @@ } | ||
var optional = value.endsWith('?'); | ||
if (optional) { | ||
value = value.slice(0, -1); | ||
} | ||
var name = toKeyName(value); | ||
@@ -152,3 +166,3 @@ var modifier = MODIFIERS[name]; | ||
if (modifier) { | ||
ret[modifier] = true; | ||
ret[modifier] = optional ? null : true; | ||
} | ||
@@ -189,5 +203,7 @@ | ||
if (expected == null) continue; | ||
if (expected == null) { | ||
continue; | ||
} | ||
if (key == 'key') { | ||
if (key === 'key') { | ||
actual = event.key.toLowerCase(); | ||
@@ -200,4 +216,9 @@ } else if (key == 'which') { | ||
if (actual == null && expected == false) continue; | ||
if (actual != expected) return false; | ||
if (actual == null && expected === false) { | ||
continue; | ||
} | ||
if (actual !== expected) { | ||
return false; | ||
} | ||
} | ||
@@ -204,0 +225,0 @@ |
{ | ||
"name": "is-hotkey", | ||
"description": "Check whether a browser event matches a hotkey.", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"license": "MIT", | ||
@@ -18,6 +18,4 @@ "repository": "git://github.com/ianstormtaylor/is-hotkey.git", | ||
"babel-cli": "^6.10.1", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-stage-0": "^6.5.0", | ||
"mocha": "^3.2.0", | ||
"np": "^2.13.1" | ||
"babel-preset-env": "^1.6.1", | ||
"mocha": "^3.2.0" | ||
}, | ||
@@ -24,0 +22,0 @@ "keywords": [ |
@@ -93,7 +93,9 @@ | ||
const object = parseHotkey(hotkey, options) | ||
const ret = event == null | ||
? e => compareHotkey(object, e) | ||
: compareHotkey(object, event) | ||
if (!Array.isArray(hotkey)) { | ||
hotkey = [hotkey] | ||
} | ||
const array = hotkey.map(string => parseHotkey(string, options)) | ||
const check = e => array.some(object => compareHotkey(object, e)) | ||
const ret = event == null ? check : check(event) | ||
return ret | ||
@@ -129,2 +131,8 @@ } | ||
for (let value of values) { | ||
const optional = value.endsWith('?') | ||
if (optional) { | ||
value = value.slice(0, -1) | ||
} | ||
const name = toKeyName(value) | ||
@@ -142,3 +150,3 @@ const modifier = MODIFIERS[name] | ||
if (modifier) { | ||
ret[modifier] = true | ||
ret[modifier] = optional ? null : true | ||
} | ||
@@ -165,5 +173,7 @@ | ||
if (expected == null) continue | ||
if (expected == null) { | ||
continue | ||
} | ||
if (key == 'key') { | ||
if (key === 'key') { | ||
actual = event.key.toLowerCase() | ||
@@ -176,4 +186,9 @@ } else if (key == 'which') { | ||
if (actual == null && expected == false) continue | ||
if (actual != expected) return false | ||
if (actual == null && expected === false) { | ||
continue | ||
} | ||
if (actual !== expected) { | ||
return false | ||
} | ||
} | ||
@@ -180,0 +195,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
399
14296
7