unicode-input-toolconverter 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. package/.nyc_output/out.json +8980 -1849
  2. package/CHANGES.md +11 -1
  3. package/README.md +6 -11
  4. package/_locales/en-US/messages.json +153 -6
  5. package/_locales/hu-HU/messages.json +153 -6
  6. package/_locales/pt-BR/messages.json +153 -6
  7. package/_locales/sv-SE/messages.json +153 -6
  8. package/babel.config.json +0 -1
  9. package/browser_action/characterSelection.js +18 -11
  10. package/browser_action/charrefConverters.js +286 -79
  11. package/browser_action/chartBuild.js +97 -27
  12. package/browser_action/encodingBehaviors.js +10 -7
  13. package/browser_action/entityBehaviors.js +42 -16
  14. package/browser_action/index-es.html +13 -1
  15. package/browser_action/index-instrumented.html +13 -1
  16. package/browser_action/index-pages.html +13 -1
  17. package/browser_action/index.html +13 -1
  18. package/browser_action/index.iife.min.js +9 -1
  19. package/browser_action/index.iife.min.js.map +1 -1
  20. package/browser_action/index.instrumented.iife.min.js +1 -1
  21. package/browser_action/index.instrumented.iife.min.js.map +1 -1
  22. package/browser_action/index.js +5 -5
  23. package/browser_action/preferences/prefDefaults.js +12 -3
  24. package/browser_action/service-worker/sw-activateCallback.js +1 -2
  25. package/browser_action/service-worker/sw-resources.json +6 -4
  26. package/browser_action/templateUtils/elements.js +12 -1
  27. package/browser_action/templateUtils/fill.js +6 -0
  28. package/browser_action/templateUtils/validation.js +4 -1
  29. package/browser_action/templates/chartBuild.js +167 -102
  30. package/browser_action/templates/index.js +227 -53
  31. package/browser_action/templatesElementCustomization/widgets.js +40 -15
  32. package/browser_action/unicode/UnicodeConverter.js +99 -73
  33. package/browser_action/unicode/charrefunicodeDb.js +100 -50
  34. package/browser_action/unicode/getScriptInfoForCodePoint.js +13 -4
  35. package/browser_action/unicode/hangul.js +27 -20
  36. package/browser_action/unicode/lastScriptNames.json +1 -1
  37. package/browser_action/unicode/parseUnihanFromTextFileStrings.js +44 -25
  38. package/browser_action/unicode/unicodeFieldInfo.js +112 -90
  39. package/browser_action/unicode/unicodeScripts.js +409 -35
  40. package/browser_action/unicode/unihan.js +4 -3
  41. package/browser_action/unicode/unihanDbPopulate.js +7 -2
  42. package/browser_action/unicode/unihanFields.js +34 -0
  43. package/browser_action/unicodecharref.js +353 -190
  44. package/browser_action/utils/DOMUtils.js +95 -34
  45. package/browser_action/utils/FetchUtils.js +7 -6
  46. package/browser_action/utils/TextUtils.js +4 -4
  47. package/browser_action/utils/TypedArrayUtils.js +9 -5
  48. package/browser_action/utils/semicolonSeparatedToArray.js +3 -3
  49. package/browser_action/utils/setupServiceWorker.js +2 -2
  50. package/eslint.config.js +11 -0
  51. package/icons/openWindow16.png +0 -0
  52. package/icons/openWindow24.png +0 -0
  53. package/lib/background.html +7 -0
  54. package/lib/background.js +2 -2
  55. package/package.json +79 -70
  56. package/pnpm-workspace.yaml +8 -0
  57. package/server.js +66 -51
  58. package/sw.js +97 -56
  59. package/tools/entities-import.js +4 -1
  60. package/tools/findEsResources.js +33 -10
  61. package/tools/fix-sw-resources-vendor-paths.js +58 -0
  62. package/tools/list-locales.js +2 -2
  63. package/tools/parseUnicodeCharts.js +126 -60
  64. package/tools/ucd-import.js +1 -10
  65. package/tools/unicode-charts.html +49 -20
  66. package/tools/unihan-import.js +45 -15
  67. package/tools/write-sw-version.js +16 -0
  68. package/tsconfig.json +23 -0
  69. package/typings/__coverage__.d.ts +5 -0
  70. package/typings/apple-system-profiler.d.ts +17 -0
  71. package/typings/commands.d.ts +19 -0
  72. package/typings/json-6.d.ts +4 -0
  73. package/typings/rollup-plugin-istanbul.d.ts +3 -0
  74. package/vendor/camelcase/index.d.ts +154 -0
  75. package/vendor/camelcase/index.js +137 -23
  76. package/vendor/fflate/esm/browser.d.ts +1539 -0
  77. package/vendor/fflate/esm/browser.js +82 -55
  78. package/vendor/intl-dom/dist/Formatter.d.ts +120 -0
  79. package/vendor/intl-dom/dist/Formatter.d.ts.map +1 -0
  80. package/vendor/intl-dom/dist/collation.d.ts +42 -0
  81. package/vendor/intl-dom/dist/collation.d.ts.map +1 -0
  82. package/vendor/intl-dom/dist/defaultAllSubstitutions.d.ts +52 -0
  83. package/vendor/intl-dom/dist/defaultAllSubstitutions.d.ts.map +1 -0
  84. package/vendor/intl-dom/dist/defaultInsertNodes.d.ts +96 -0
  85. package/vendor/intl-dom/dist/defaultInsertNodes.d.ts.map +1 -0
  86. package/vendor/intl-dom/dist/defaultKeyCheckerConverter.d.ts +17 -0
  87. package/vendor/intl-dom/dist/defaultKeyCheckerConverter.d.ts.map +1 -0
  88. package/vendor/intl-dom/dist/defaultLocaleResolver.d.ts +285 -0
  89. package/vendor/intl-dom/dist/defaultLocaleResolver.d.ts.map +1 -0
  90. package/vendor/intl-dom/dist/findLocaleStrings.d.ts +88 -0
  91. package/vendor/intl-dom/dist/findLocaleStrings.d.ts.map +1 -0
  92. package/vendor/intl-dom/dist/getDOMForLocaleString.d.ts +67 -0
  93. package/vendor/intl-dom/dist/getDOMForLocaleString.d.ts.map +1 -0
  94. package/vendor/intl-dom/dist/getMessageForKeyByStyle.d.ts +73 -0
  95. package/vendor/intl-dom/dist/getMessageForKeyByStyle.d.ts.map +1 -0
  96. package/vendor/intl-dom/dist/getStringFromMessageAndDefaults.d.ts +26 -0
  97. package/vendor/intl-dom/dist/getStringFromMessageAndDefaults.d.ts.map +1 -0
  98. package/vendor/intl-dom/dist/i18n.d.ts +113 -0
  99. package/vendor/intl-dom/dist/i18n.d.ts.map +1 -0
  100. package/vendor/intl-dom/dist/index.d.ts +92 -0
  101. package/vendor/intl-dom/dist/index.d.ts.map +1 -0
  102. package/vendor/intl-dom/dist/index.esm.d.ts +34 -0
  103. package/vendor/intl-dom/dist/index.esm.js +854 -896
  104. package/vendor/intl-dom/dist/index.esm.min.js +4 -0
  105. package/vendor/intl-dom/dist/index.esm.min.js.map +1 -0
  106. package/vendor/intl-dom/dist/index.umd.js +2953 -0
  107. package/vendor/intl-dom/dist/index.umd.min.js +4 -0
  108. package/vendor/intl-dom/dist/index.umd.min.js.map +1 -0
  109. package/vendor/intl-dom/dist/promiseChainForValues.d.ts +34 -0
  110. package/vendor/intl-dom/dist/promiseChainForValues.d.ts.map +1 -0
  111. package/vendor/intl-dom/dist/shared.d.ts +20 -0
  112. package/vendor/intl-dom/dist/shared.d.ts.map +1 -0
  113. package/vendor/intl-dom/dist/utils.d.ts +53 -0
  114. package/vendor/intl-dom/dist/utils.d.ts.map +1 -0
  115. package/vendor/jamilih/dist/jml.d.mts +468 -0
  116. package/vendor/jamilih/dist/{jml-es.js → jml.mjs} +1489 -343
  117. package/vendor/jquery/dist/jquery.js +1677 -2713
  118. package/vendor/json-6/dist/index.mjs +2 -0
  119. package/vendor/miller-columns/CHANGES.md +185 -0
  120. package/vendor/miller-columns/LICENSE-MIT.txt +21 -0
  121. package/vendor/miller-columns/README.md +249 -0
  122. package/vendor/miller-columns/demos/index.html +69 -0
  123. package/vendor/miller-columns/demos/index.js +72 -0
  124. package/vendor/miller-columns/dist/index-es.js +748 -0
  125. package/vendor/miller-columns/dist/index-es.min.d.ts +25 -0
  126. package/vendor/miller-columns/dist/index-es.min.js +7 -1
  127. package/vendor/miller-columns/dist/index-umd.js +757 -0
  128. package/vendor/miller-columns/dist/index-umd.min.js +7 -0
  129. package/vendor/miller-columns/dist/index.d.ts +25 -0
  130. package/vendor/miller-columns/dist/millerColumns.d.ts +10 -0
  131. package/vendor/miller-columns/eslint.config.js +46 -0
  132. package/vendor/miller-columns/fix-declarations.js +18 -0
  133. package/vendor/miller-columns/miller-columns.css +24 -1
  134. package/vendor/miller-columns/package.json +73 -0
  135. package/vendor/miller-columns/pnpm-workspace.yaml +2 -0
  136. package/vendor/miller-columns/src/index.js +642 -0
  137. package/vendor/miller-columns/src/millerColumns.ts +12 -0
  138. package/vendor/miller-columns/tsconfig-prod.json +23 -0
  139. package/vendor/miller-columns/tsconfig.json +21 -0
  140. package/vendor/simple-prefs/dist/index.esm.d.ts +1 -0
  141. package/vendor/simple-prefs/dist/index.esm.js +164 -216
  142. package/vendor/simple-prefs/dist/simple-prefs.d.ts +117 -0
  143. package/lgtm.yml +0 -5
@@ -1,47 +1,18 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
5
- }
6
- function _defineProperties(target, props) {
7
- for (var i = 0; i < props.length; i++) {
8
- var descriptor = props[i];
9
- descriptor.enumerable = descriptor.enumerable || false;
10
- descriptor.configurable = true;
11
- if ("value" in descriptor) descriptor.writable = true;
12
- Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
13
- }
14
- }
15
- function _createClass(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- Object.defineProperty(Constructor, "prototype", {
19
- writable: false
20
- });
21
- return Constructor;
22
- }
23
- function _toPrimitive(input, hint) {
24
- if (typeof input !== "object" || input === null) return input;
25
- var prim = input[Symbol.toPrimitive];
26
- if (prim !== undefined) {
27
- var res = prim.call(input, hint || "default");
28
- if (typeof res !== "object") return res;
29
- throw new TypeError("@@toPrimitive must return a primitive value.");
30
- }
31
- return (hint === "string" ? String : Number)(input);
32
- }
33
- function _toPropertyKey(arg) {
34
- var key = _toPrimitive(arg, "string");
35
- return typeof key === "symbol" ? key : String(key);
36
- }
37
-
38
1
  /**
39
- * @typedef {{[key: string]: Value}} Defaults
40
- */
2
+ * @typedef {{[key: string]: JSONValue}} Defaults
3
+ */
41
4
 
42
5
  /**
43
- * @typedef {boolean|number|string} Value
44
- */
6
+ * @typedef {null|boolean|number|string} JSONPrimitive
7
+ */
8
+ /**
9
+ * @typedef {JSONValue[]} JSONArray
10
+ */
11
+ /**
12
+ * @typedef {JSONPrimitive | JSONArray | {
13
+ * [key in string]: JSONValue
14
+ * }} JSONValue
15
+ */
45
16
 
46
17
  /**
47
18
  * Preferences storage.
@@ -60,15 +31,23 @@ function _await(value, then, direct) {
60
31
  /**
61
32
  * Defaults for SimplePrefs.
62
33
  */
63
- var SimplePrefs = /*#__PURE__*/function () {
34
+
35
+ function _call(body, then, direct) {
36
+ try {
37
+ var result = Promise.resolve(body());
38
+ return then ? result.then(then) : result;
39
+ } catch (e) {
40
+ return Promise.reject(e);
41
+ }
42
+ }
43
+ class SimplePrefs {
64
44
  /**
65
45
  * @param {object} cfg
66
46
  * @param {string} [cfg.namespace] Avoid clashes with other apps
67
47
  * @param {Defaults} [cfg.defaults]
68
48
  * @param {SimplePrefsDefaults} [cfg.prefDefaults]
69
49
  */
70
- function SimplePrefs(cfg) {
71
- _classCallCheck(this, SimplePrefs);
50
+ constructor(cfg) {
72
51
  this.configurePrefs(cfg);
73
52
 
74
53
  /** @type {((e: StorageEvent) => void)[]} */
@@ -81,205 +60,174 @@ var SimplePrefs = /*#__PURE__*/function () {
81
60
  * @param {SimplePrefsDefaults} [cfg.prefDefaults]
82
61
  * @returns {void}
83
62
  */
84
- _createClass(SimplePrefs, [{
85
- key: "configurePrefs",
86
- value: function configurePrefs(_ref) {
87
- var namespace = _ref.namespace,
88
- defaults = _ref.defaults,
89
- _ref$prefDefaults = _ref.prefDefaults,
90
- prefDefaults = _ref$prefDefaults === void 0 ? simplePrefsDefaults(defaults) : _ref$prefDefaults;
91
- this.namespace = namespace !== null && namespace !== void 0 ? namespace : '';
92
- this.prefDefaults = prefDefaults;
93
- }
94
- /**
95
- * Get parsed preference value; returns `Promise` in anticipation
96
- * of https://domenic.github.io/async-local-storage/ .
97
- * @callback GetPref
98
- * @param {string} key Preference key (for Chrome-Compatibility, only `\w+`)
99
- * @returns {Promise<Value>} Resolves to the parsed
100
- * value (defaulting if necessary)
101
- */
102
-
103
- /** @type {GetPref} */
104
- }, {
105
- key: "getPref",
106
- value: function getPref(key) {
107
- try {
108
- var _this = this;
109
- var result = localStorage.getItem(_this.namespace + key);
110
- return _await(_await(result === null ? /** @type {SimplePrefsDefaults} */_this.prefDefaults.getPrefDefault(key) : JSON.parse(result), void 0, !(result === null)));
111
- } catch (e) {
112
- return Promise.reject(e);
113
- }
114
- }
115
- /**
116
- * Set a stringifiable preference value; returns `Promise` in anticipation
117
- * of https://domenic.github.io/async-local-storage/ .
118
- * @callback SetPref
119
- * @param {string} key Preference key (for Chrome-Compatibility, only `\w+`)
120
- * @param {Value} val Stringifiable value
121
- * @returns {Promise<void>} Resolves after setting the item (Not currently
122
- * in use)
123
- */
124
- /** @type {SetPref} */
125
- }, {
126
- key: "setPref",
127
- value: function setPref(key, val) {
128
- try {
129
- var _this2 = this;
130
- return _await(localStorage.setItem(_this2.namespace + key, JSON.stringify(val)));
131
- } catch (e) {
132
- return Promise.reject(e);
133
- }
134
- }
135
- /**
136
- * @typedef {object} GetPrefSetPref
137
- * @property {GetPref} getPref
138
- * @property {SetPref} setPref
139
- */
140
- /**
141
- * Convenience utility to return two main methods `getPref` and
142
- * `setPref` bound to the current object.
143
- * @returns {GetPrefSetPref}
144
- */
145
- }, {
146
- key: "bind",
147
- value: function bind() {
148
- return {
149
- getPref: this.getPref.bind(this),
150
- setPref: this.setPref.bind(this)
151
- };
152
- }
63
+ configurePrefs({
64
+ namespace,
65
+ defaults,
66
+ prefDefaults = simplePrefsDefaults(defaults)
67
+ }) {
68
+ this.namespace = namespace ?? '';
69
+ this.prefDefaults = prefDefaults;
70
+ }
71
+ /**
72
+ * Get parsed preference value; returns `Promise` in anticipation
73
+ * of https://domenic.github.io/async-local-storage/ .
74
+ * @callback GetPref
75
+ * @param {string} key Preference key (for Chrome-Compatibility, only `\w+`)
76
+ * @returns {Promise<JSONValue>} Resolves to the parsed
77
+ * value (defaulting if necessary)
78
+ */
153
79
 
154
- /**
155
- * @callback PreferenceCallback
156
- * @param {StorageEvent} e
157
- * @returns {void}
158
- */
80
+ /** @type {GetPref} */
81
+ getPref(key) {
82
+ const _this = this;
83
+ return _call(function () {
84
+ const result = localStorage.getItem(_this.namespace + key);
85
+ return _await(_await(result === null ? /** @type {SimplePrefsDefaults} */_this.prefDefaults.getPrefDefault(key) : JSON.parse(result), void 0, !(result === null)));
86
+ });
87
+ }
88
+ /**
89
+ * Set a stringifiable preference value; returns `Promise` in anticipation
90
+ * of https://domenic.github.io/async-local-storage/ .
91
+ * @callback SetPref
92
+ * @param {string} key Preference key (for Chrome-Compatibility, only `\w+`)
93
+ * @param {JSONValue} val Stringifiable value
94
+ * @returns {Promise<void>} Resolves after setting the item (Not currently
95
+ * in use)
96
+ */
97
+ /** @type {SetPref} */
98
+ setPref(key, val) {
99
+ const _this2 = this;
100
+ return _call(function () {
101
+ return _await(localStorage.setItem(_this2.namespace + key, JSON.stringify(val)));
102
+ });
103
+ }
104
+ /**
105
+ * @typedef {object} GetPrefSetPref
106
+ * @property {GetPref} getPref
107
+ * @property {SetPref} setPref
108
+ */
109
+ /**
110
+ * Convenience utility to return two main methods `getPref` and
111
+ * `setPref` bound to the current object.
112
+ * @returns {GetPrefSetPref}
113
+ */
114
+ bind() {
115
+ return {
116
+ getPref: this.getPref.bind(this),
117
+ setPref: this.setPref.bind(this)
118
+ };
119
+ }
159
120
 
160
- /* eslint-disable promise/prefer-await-to-callbacks -- Repeating event */
161
- /**
162
- * @param {string|PreferenceCallback|undefined} key
163
- * @param {PreferenceCallback} cb
164
- * @returns {PreferenceCallback}
165
- */
166
- }, {
167
- key: "listen",
168
- value: function listen(key, cb) {
169
- var _this3 = this;
170
- if (typeof key === 'function') {
171
- cb = key;
172
- key = undefined;
173
- }
121
+ /**
122
+ * @callback PreferenceCallback
123
+ * @param {StorageEvent} e
124
+ * @returns {void}
125
+ */
174
126
 
175
- /**
176
- * @param {StorageEvent} e
177
- */
178
- var listener = function listener(e) {
179
- if (e.key === null) {
180
- // `null` for clear browser action or user `clear()`
181
- if (key === undefined) {
182
- // Only trigger when no key supplied
183
- return;
184
- }
185
- } else {
186
- if (!e.key.startsWith( /** @type {string} */_this3.namespace)) {
187
- return;
188
- }
189
- if (key !== undefined && !e.key.startsWith( /** @type {string} */_this3.namespace + key)) {
190
- return;
191
- }
192
- }
193
- cb(e);
194
- };
195
- window.addEventListener('storage', listener);
196
- this.listeners.push(listener);
197
- return listener;
127
+ /* eslint-disable promise/prefer-await-to-callbacks -- Repeating event */
128
+ /**
129
+ * @param {string|PreferenceCallback|undefined} key
130
+ * @param {PreferenceCallback} cb
131
+ * @returns {PreferenceCallback}
132
+ */
133
+ listen(key, cb) {
134
+ if (typeof key === 'function') {
135
+ cb = key;
136
+ key = undefined;
198
137
  }
199
138
 
200
139
  /**
201
- * @param {EventListener} listener
202
- * @returns {void}
140
+ * @param {StorageEvent} e
203
141
  */
204
- }, {
205
- key: "unlisten",
206
- value: function unlisten(listener) {
207
- if (listener) {
208
- for (var i = 0; i < this.listeners.length; i++) {
209
- if (listener === this.listeners[i]) {
210
- this.listeners.splice(i, 1);
211
- window.removeEventListener('storage', listener);
212
- return;
213
- }
142
+ const listener = e => {
143
+ if (e.key === null) {
144
+ // `null` for clear browser action or user `clear()`
145
+ if (key === undefined) {
146
+ // Only trigger when no key supplied
147
+ return;
148
+ }
149
+ } else {
150
+ if (!e.key.startsWith(/** @type {string} */this.namespace)) {
151
+ return;
152
+ }
153
+ if (key !== undefined && !e.key.startsWith(/** @type {string} */this.namespace + key)) {
154
+ return;
155
+ }
156
+ }
157
+ cb(e);
158
+ };
159
+ globalThis.addEventListener('storage', listener);
160
+ this.listeners.push(listener);
161
+ return listener;
162
+ }
163
+
164
+ /**
165
+ * @param {EventListener} listener
166
+ * @returns {void}
167
+ */
168
+ unlisten(listener) {
169
+ if (listener) {
170
+ for (let i = 0; i < this.listeners.length; i++) {
171
+ if (listener === this.listeners[i]) {
172
+ this.listeners.splice(i, 1);
173
+ globalThis.removeEventListener('storage', listener);
174
+ return;
214
175
  }
215
176
  }
216
- this.listeners.forEach(function (listenerItem) {
217
- window.removeEventListener('storage', listenerItem);
218
- });
219
177
  }
220
- /* eslint-enable promise/prefer-await-to-callbacks -- Repeating event */
221
- }]);
222
- return SimplePrefs;
223
- }();
224
- var SimplePrefsDefaults = /*#__PURE__*/function () {
178
+ this.listeners.forEach(listenerItem => {
179
+ globalThis.removeEventListener('storage', listenerItem);
180
+ });
181
+ }
182
+ /* eslint-enable promise/prefer-await-to-callbacks -- Repeating event */
183
+ }
184
+ class SimplePrefsDefaults {
225
185
  /**
226
186
  *
227
187
  * @param {{defaults: Defaults}} defaults
228
188
  */
229
- function SimplePrefsDefaults(_ref2) {
230
- var defaults = _ref2.defaults;
231
- _classCallCheck(this, SimplePrefsDefaults);
189
+ constructor({
190
+ defaults
191
+ }) {
232
192
  this.defaults = defaults;
233
193
  }
234
194
  /**
235
195
  * Get parsed default value for a preference.
236
196
  * @param {string} key Preference key
237
- * @returns {Promise<Value>}
197
+ * @returns {Promise<JSONValue>}
238
198
  */
239
- _createClass(SimplePrefsDefaults, [{
240
- key: "getPrefDefault",
241
- value: function getPrefDefault(key) {
242
- try {
243
- var _this4 = this;
244
- return _await(_this4.defaults[key], function (_this4$defaults$key) {
245
- return _this4$defaults$key !== null && _this4$defaults$key !== void 0 ? _this4$defaults$key : null;
246
- });
247
- } catch (e) {
248
- return Promise.reject(e);
249
- }
250
- }
251
- /**
252
- * Set parsed default value for a preference.
253
- * @param {string} key Preference key
254
- * @param {Value} value
255
- * @returns {Promise<Value>} The old value
256
- */
257
- }, {
258
- key: "setPrefDefault",
259
- value: function setPrefDefault(key, value) {
260
- try {
261
- var _this5$defaults$key;
262
- var _this5 = this;
263
- var oldValue = (_this5$defaults$key = _this5.defaults[key]) !== null && _this5$defaults$key !== void 0 ? _this5$defaults$key : null;
264
- _this5.defaults[key] = value;
265
- return _await(oldValue);
266
- } catch (e) {
267
- return Promise.reject(e);
268
- }
269
- }
270
- }]);
271
- return SimplePrefsDefaults;
272
- }();
199
+ getPrefDefault(key) {
200
+ const _this3 = this;
201
+ return _call(function () {
202
+ return _await(_this3.defaults[key], function (_this3$defaults$key) {
203
+ return _this3$defaults$key ?? null;
204
+ });
205
+ });
206
+ }
207
+ /**
208
+ * Set parsed default value for a preference.
209
+ * @param {string} key Preference key
210
+ * @param {JSONValue} value
211
+ * @returns {Promise<JSONValue>} The old value
212
+ */
213
+ setPrefDefault(key, value) {
214
+ const _this4 = this;
215
+ return _call(function () {
216
+ const oldValue = _this4.defaults[key] ?? null;
217
+ _this4.defaults[key] = value;
218
+ return _await(oldValue);
219
+ });
220
+ }
221
+ }
273
222
 
274
223
  /**
275
224
  * Simplified factory for `SimplePrefsDefaults`
276
225
  * @param {Defaults} [defaults]
277
226
  * @returns {SimplePrefsDefaults}
278
227
  */
279
- function simplePrefsDefaults() {
280
- var defaults = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
228
+ function simplePrefsDefaults(defaults = {}) {
281
229
  return new SimplePrefsDefaults({
282
- defaults: defaults
230
+ defaults
283
231
  });
284
232
  }
285
233
 
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Simplified factory for `SimplePrefsDefaults`
3
+ * @param {Defaults} [defaults]
4
+ * @returns {SimplePrefsDefaults}
5
+ */
6
+ export function simplePrefsDefaults(defaults?: Defaults): SimplePrefsDefaults;
7
+ /**
8
+ * @typedef {{[key: string]: JSONValue}} Defaults
9
+ */
10
+ /**
11
+ * @typedef {null|boolean|number|string} JSONPrimitive
12
+ */
13
+ /**
14
+ * @typedef {JSONValue[]} JSONArray
15
+ */
16
+ /**
17
+ * @typedef {JSONPrimitive | JSONArray | {
18
+ * [key in string]: JSONValue
19
+ * }} JSONValue
20
+ */
21
+ /**
22
+ * Preferences storage.
23
+ */
24
+ export class SimplePrefs {
25
+ /**
26
+ * @param {object} cfg
27
+ * @param {string} [cfg.namespace] Avoid clashes with other apps
28
+ * @param {Defaults} [cfg.defaults]
29
+ * @param {SimplePrefsDefaults} [cfg.prefDefaults]
30
+ */
31
+ constructor(cfg: {
32
+ namespace?: string | undefined;
33
+ defaults?: Defaults | undefined;
34
+ prefDefaults?: SimplePrefsDefaults | undefined;
35
+ });
36
+ /** @type {((e: StorageEvent) => void)[]} */
37
+ listeners: ((e: StorageEvent) => void)[];
38
+ /**
39
+ * @param {object} cfg
40
+ * @param {string} [cfg.namespace] Avoid clashes with other apps
41
+ * @param {Defaults} [cfg.defaults]
42
+ * @param {SimplePrefsDefaults} [cfg.prefDefaults]
43
+ * @returns {void}
44
+ */
45
+ configurePrefs({ namespace, defaults, prefDefaults }: {
46
+ namespace?: string | undefined;
47
+ defaults?: Defaults | undefined;
48
+ prefDefaults?: SimplePrefsDefaults | undefined;
49
+ }): void;
50
+ namespace: string | undefined;
51
+ prefDefaults: SimplePrefsDefaults | undefined;
52
+ getPref(key: string): Promise<JSONValue>;
53
+ setPref(key: string, val: JSONValue): Promise<void>;
54
+ /**
55
+ * @typedef {object} GetPrefSetPref
56
+ * @property {GetPref} getPref
57
+ * @property {SetPref} setPref
58
+ */
59
+ /**
60
+ * Convenience utility to return two main methods `getPref` and
61
+ * `setPref` bound to the current object.
62
+ * @returns {GetPrefSetPref}
63
+ */
64
+ bind(): {
65
+ getPref: (key: string) => Promise<JSONValue>;
66
+ setPref: (key: string, val: JSONValue) => Promise<void>;
67
+ };
68
+ /**
69
+ * @callback PreferenceCallback
70
+ * @param {StorageEvent} e
71
+ * @returns {void}
72
+ */
73
+ /**
74
+ * @param {string|PreferenceCallback|undefined} key
75
+ * @param {PreferenceCallback} cb
76
+ * @returns {PreferenceCallback}
77
+ */
78
+ listen(key: string | ((e: StorageEvent) => void) | undefined, cb: (e: StorageEvent) => void): (e: StorageEvent) => void;
79
+ /**
80
+ * @param {EventListener} listener
81
+ * @returns {void}
82
+ */
83
+ unlisten(listener: EventListener): void;
84
+ }
85
+ /**
86
+ * Defaults for SimplePrefs.
87
+ */
88
+ export class SimplePrefsDefaults {
89
+ /**
90
+ *
91
+ * @param {{defaults: Defaults}} defaults
92
+ */
93
+ constructor({ defaults }: {
94
+ defaults: Defaults;
95
+ });
96
+ defaults: Defaults;
97
+ /**
98
+ * Get parsed default value for a preference.
99
+ * @param {string} key Preference key
100
+ * @returns {Promise<JSONValue>}
101
+ */
102
+ getPrefDefault(key: string): Promise<JSONValue>;
103
+ /**
104
+ * Set parsed default value for a preference.
105
+ * @param {string} key Preference key
106
+ * @param {JSONValue} value
107
+ * @returns {Promise<JSONValue>} The old value
108
+ */
109
+ setPrefDefault(key: string, value: JSONValue): Promise<JSONValue>;
110
+ }
111
+ export type Defaults = {
112
+ [key: string]: JSONValue;
113
+ };
114
+ export type JSONPrimitive = null | boolean | number | string;
115
+ export type JSONArray = JSONValue[];
116
+ export type JSONValue = JSONPrimitive | JSONArray | { [key in string]: JSONValue; };
117
+ //# sourceMappingURL=simple-prefs.d.ts.map
package/lgtm.yml DELETED
@@ -1,5 +0,0 @@
1
- extraction:
2
- javascript:
3
- index:
4
- filters:
5
- - exclude: "old"