UNPKG

2.81 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.RawKeybinding = exports.Keybinding = void 0;
4var Keybinding;
5(function (Keybinding) {
6 /**
7 * Compares two keybindings for equality.
8 * Can optionally ignore the keybinding and/or args property in the comparison.
9 * @param a The first Keybinding in the comparison
10 * @param b The second Keybinding in the comparison
11 * @param ignoreKeybinding Ignore the 'keybinding' property in the comparison
12 * @param ignoreArgs Ignore the 'args' property in the comparison
13 */
14 function equals(a, b, ignoreKeybinding = false, ignoreArgs = false) {
15 if (a.command === b.command &&
16 (a.context || '') === (b.context || '') &&
17 (a.when || '') === (b.when || '') &&
18 (ignoreKeybinding || a.keybinding === b.keybinding) &&
19 (ignoreArgs || (a.args || '') === (b.args || ''))) {
20 return true;
21 }
22 return false;
23 }
24 Keybinding.equals = equals;
25 /**
26 * Returns a new object only containing properties which
27 * are described on the `Keybinding` API.
28 *
29 * @param binding the binding to create an API object for.
30 */
31 function apiObjectify(binding) {
32 return {
33 command: binding.command,
34 keybinding: retrieveKeybinding(binding),
35 context: binding.context,
36 when: binding.when,
37 args: binding.args
38 };
39 }
40 Keybinding.apiObjectify = apiObjectify;
41 function retrieveKeybinding(binding) {
42 var _a, _b;
43 return (_b = (_a = binding.keybinding) !== null && _a !== void 0 ? _a : binding.key) !== null && _b !== void 0 ? _b : '';
44 }
45 Keybinding.retrieveKeybinding = retrieveKeybinding;
46 /**
47 * Returns with the string representation of the binding.
48 * Any additional properties which are not described on
49 * the `Keybinding` API will be ignored.
50 *
51 * @param binding the binding to stringify.
52 */
53 function stringify(binding) {
54 return JSON.stringify(apiObjectify(binding));
55 }
56 Keybinding.stringify = stringify;
57 /* Determine whether object is a KeyBinding */
58 // eslint-disable-next-line @typescript-eslint/no-explicit-any
59 function is(arg) {
60 return !!arg && arg === Object(arg) && 'command' in arg && 'keybinding' in arg;
61 }
62 Keybinding.is = is;
63})(Keybinding = exports.Keybinding || (exports.Keybinding = {}));
64var RawKeybinding;
65(function (RawKeybinding) {
66 function is(candidate) {
67 return typeof candidate === 'object' && !!candidate && 'command' in candidate && 'key' in candidate;
68 }
69 RawKeybinding.is = is;
70})(RawKeybinding = exports.RawKeybinding || (exports.RawKeybinding = {}));
71//# sourceMappingURL=keybinding.js.map
\No newline at end of file