diff options
author | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-09 16:43:17 +0900 |
---|---|---|
committer | Shin'ya Ueoka <ueokande@i-beam.org> | 2017-09-09 16:43:17 +0900 |
commit | eff7fe276b5a9d50037c7d965712dc24d226a984 (patch) | |
tree | 7060e8c56ec6e82820875f96910d150b025e13ad | |
parent | 15d39a479aa7f2c4b804bac8c4352dd0a120bc75 (diff) |
remove keys
-rw-r--r-- | src/background/keys.js | 28 | ||||
-rw-r--r-- | test/background/keys.test.js | 55 |
2 files changed, 0 insertions, 83 deletions
diff --git a/src/background/keys.js b/src/background/keys.js deleted file mode 100644 index 2fd00a2..0000000 --- a/src/background/keys.js +++ /dev/null @@ -1,28 +0,0 @@ -const identifyKey = (key1, key2) => { - return (key1.code === key2.code) && - ((key1.shift || false) === (key2.shift || false)) && - ((key1.ctrl || false) === (key2.ctrl || false)) && - ((key1.alt || false) === (key2.alt || false)) && - ((key1.meta || false) === (key2.meta || false)); -}; - -const hasPrefix = (keys, prefix) => { - if (keys.length < prefix.length) { - return false; - } - for (let i = 0; i < prefix.length; ++i) { - if (!identifyKey(keys[i], prefix[i])) { - return false; - } - } - return true; -} - -const identifyKeys = (keys1, keys2) => { - if (keys1.length !== keys2.length) { - return false; - } - return hasPrefix(keys1, keys2); -} - -export { identifyKey, identifyKeys, hasPrefix }; diff --git a/test/background/keys.test.js b/test/background/keys.test.js deleted file mode 100644 index da9d430..0000000 --- a/test/background/keys.test.js +++ /dev/null @@ -1,55 +0,0 @@ -import { expect } from "chai"; -import { identifyKey, identifyKeys, hasPrefix } from '../../src/background/keys'; - -describe('keys', () => { - describe('#identifyKey', () => { - it('return true if key matched', () => { - expect(identifyKey( - { code: 100 }, - { code: 100 })).to.be.true; - expect(identifyKey( - { code: 100, shift: true, ctrl: true }, - { code: 100, shift: true, ctrl: true })).to.be.true; - expect(identifyKey( - { code: 100, shift: false, ctrl: false }, - { code: 100 })).to.be.true; - }); - - it('return false if key not matched', () => { - expect(identifyKey( - { code: 100 }, - { code: 101 })).to.be.false; - expect(identifyKey( - { code: 100, shift: true, ctrl: true }, - { code: 100, shift: true })).to.be.false; - }); - }); - - describe('#identifyKeys', () => { - it ('return true if keys matched', () => { - let keys = [{ code: 100 }, { code: 101, ctrl: false}]; - let prefix = [{ code: 100, ctrl: false }, { code: 101 }]; - expect(hasPrefix(keys, prefix)).to.be.true; - }); - - it ('return false if keys matched', () => { - let keys = [{ code: 100 }, { code: 101, ctrl: true }]; - let prefix = [{ code: 100 }, { code: 101 }]; - expect(hasPrefix(keys, prefix)).to.be.false; - }); - }); - - describe('#hasPrefix', () => { - it ('return true if prefix matched', () => { - let keys = [{ code: 100 }, { code: 101 }, { code: 102 }]; - let prefix = [{ code: 100 }, { code: 101 }]; - expect(hasPrefix(keys, prefix)).to.be.true; - }); - - it ('return false if prefix not matched', () => { - let keys = [{ code: 100 }, { code: 101 }, { code: 102 }]; - let prefix = [{ code: 102 }]; - expect(hasPrefix(keys, prefix)).to.be.false; - }); - }); -}); |