unicode-input-toolconverter 0.2.0 → 0.2.3

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 +15 -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 +80 -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 +60 -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,19 +1,25 @@
1
1
  /* eslint-disable class-methods-use-this -- Todo: fix later */
2
+
3
+ import camelCase from 'camelcase';
4
+
2
5
  import {getUnicodeDefaults} from '../preferences/prefDefaults.js';
3
6
  import {getHangulName, getHangulFromName} from './hangul.js';
4
7
  import charrefunicodeDb from './charrefunicodeDb.js';
5
8
  import unicodecharref from '../unicodecharref.js';
6
- import camelCase from '../../vendor/camelcase/index.js';
7
9
 
8
10
  /**
9
- * @typedef {"php"|"css"|"javascript"} UnicodeEscapeMode
10
- */
11
+ * @typedef {"php"|"css"|"javascript"} UnicodeEscapeMode
12
+ */
13
+
14
+ /**
15
+ * @typedef {number} Integer
16
+ */
11
17
 
12
18
  /**
13
19
  * @namespace Converts from one string form to another
14
20
  */
15
- const decim = /&#(\d*);/gu;
16
- const hexadec = /&#[xX]([\da-fA-F]*);/gu;
21
+ const decim = /&#(\d*);/gv;
22
+ const hexadec = /&#[xX]([\da-fA-F]*);/gv;
17
23
 
18
24
  const builtinEntities = new Set(['apos', 'quot', 'lt', 'gt', 'amp']);
19
25
 
@@ -22,9 +28,9 @@ const builtinEntities = new Set(['apos', 'quot', 'lt', 'gt', 'amp']);
22
28
  // https://unicode.org/reports/tr31/ ;
23
29
  // Currently appears to be Tables 3, 3a, and 3b
24
30
  // (besides \u0027 and \u2019 per XML)
25
- const xmlName = /[\p{ID_Start}_][\p{ID_Continue}\u0024\u005F\u002D\u002E\u003A\u00B7\u058A\u05F4\u0F0B\u200C\u2010\u2027\u30A0\u30FB\u05F3\u200D]*/gui;
31
+ const xmlName = /[\p{ID_Start}_][\p{ID_Continue}\u{24}\u{5F}\u{2D}\u{2E}\u{3A}\u{B7}\u{58A}\u{5F4}\u{F0B}\u{200C}\u{2010}\u{2027}\u{30A0}\u{30FB}\u{5F3}\u{200D}]*/gvi;
26
32
  // const htmlOrXmlEnt = /&([a-z\d]+);/gui; // Works for basic HTML entitites
27
- const htmlOrXmlEnt = new RegExp('&(' + xmlName.source + ');', 'gui');
33
+ const htmlOrXmlEnt = new RegExp('&(' + xmlName.source + ');', 'gvi');
28
34
 
29
35
  export const getUnicodeConverter = () => {
30
36
  const {getPref} = getUnicodeDefaults();
@@ -34,14 +40,21 @@ export const getUnicodeConverter = () => {
34
40
  */
35
41
  return class UnicodeConverter {
36
42
  /**
37
- * @param {IntlDom} _
43
+ * @param {{_: import('intl-dom').I18NCallback<string>}} cfg
38
44
  */
39
45
  constructor ({_}) {
40
46
  this._ = _;
47
+
48
+ /** @type {string[]} */
41
49
  this.newents = [];
50
+
51
+ /** @type {(string|number)[]} */
42
52
  this.newcharrefs = [];
43
53
 
54
+ /** @type {string[]} */
44
55
  this.entities = [];
56
+
57
+ /** @type {number[]} */
45
58
  this.numericCharacterReferences = [];
46
59
  }
47
60
 
@@ -75,7 +88,7 @@ export const getUnicodeConverter = () => {
75
88
 
76
89
  /**
77
90
  * @param {string} out
78
- * @returns {string}
91
+ * @returns {Promise<string>}
79
92
  */
80
93
  async charref2htmlentsval (out) {
81
94
  // If true, should allow conversion to &apos;
@@ -83,11 +96,11 @@ export const getUnicodeConverter = () => {
83
96
 
84
97
  out = out.replaceAll(decim, (match, match1) => {
85
98
  const matched = this.numericCharacterReferences.indexOf(
86
- Number.parseInt(match1)
99
+ Number.parseInt(match1, 10)
87
100
  );
88
101
  if (
89
102
  matched !== -1 &&
90
- (matched !== this.getAposPos() || xhtmlentmode)
103
+ (xhtmlentmode || matched !== this.getAposPos())
91
104
  ) {
92
105
  return '&' + this.entities[matched] + ';';
93
106
  }
@@ -98,7 +111,7 @@ export const getUnicodeConverter = () => {
98
111
  );
99
112
  if (
100
113
  matched !== -1 && (
101
- matched !== this.getAposPos() || xhtmlentmode
114
+ xhtmlentmode || matched !== this.getAposPos()
102
115
  )
103
116
  ) {
104
117
  return '&' + this.entities[matched] + ';';
@@ -110,8 +123,8 @@ export const getUnicodeConverter = () => {
110
123
 
111
124
  /**
112
125
  * @param {string} unicodeToConvert
113
- * @param {boolean} leaveSurrogates
114
- * @returns {string}
126
+ * @param {boolean} [leaveSurrogates]
127
+ * @returns {Promise<string>}
115
128
  */
116
129
  async unicode2charrefDecval (unicodeToConvert, leaveSurrogates) {
117
130
  let out = '';
@@ -129,7 +142,7 @@ export const getUnicodeConverter = () => {
129
142
 
130
143
  // Replace this 'if' condition and remove the 'else' if also
131
144
  // want ascii
132
- } else if (temp >= 128 || asciiLt128) {
145
+ } else if (asciiLt128 || temp >= 128) {
133
146
  out += '&#' + temp + ';';
134
147
  } else {
135
148
  out += unicodeToConvert.charAt(i);
@@ -140,9 +153,9 @@ export const getUnicodeConverter = () => {
140
153
 
141
154
  /**
142
155
  * @param {string} unicodeToConvert
143
- * @param {boolean} leaveSurrogates
144
- * @param {UnicodeEscapeMode} type
145
- * @returns {string}
156
+ * @param {boolean} [leaveSurrogates]
157
+ * @param {UnicodeEscapeMode} [type]
158
+ * @returns {Promise<string>}
146
159
  */
147
160
  async unicode2charrefHexval (unicodeToConvert, leaveSurrogates, type) {
148
161
  // alert(unicodeToConvert + '::' + leaveSurrogates + '::' + type);
@@ -192,7 +205,7 @@ export const getUnicodeConverter = () => {
192
205
  }
193
206
  out += beginEscape + xstyle + hexletters + endEscape;
194
207
  // Replace this 'if' condition and remove the 'else' if also want ascii
195
- } else if (temp >= 128 || asciiLt128) {
208
+ } else if (asciiLt128 || temp >= 128) {
196
209
  hexletters = temp.toString(16);
197
210
  if (hexLettersUpper) {
198
211
  hexletters = hexletters.toUpperCase();
@@ -215,12 +228,14 @@ export const getUnicodeConverter = () => {
215
228
 
216
229
  /**
217
230
  * @param {string} unicodeToConvert
218
- * @returns {string}
231
+ * @returns {Promise<string>}
219
232
  */
220
233
  async unicode2htmlentsval (unicodeToConvert) {
221
234
  for (let i = 0; i < this.newents.length; i++) {
222
235
  unicodeToConvert = unicodeToConvert.replaceAll(
223
- this.newcharrefs[i], '&' + this.newents[i] + ';'
236
+ // eslint-disable-next-line @stylistic/max-len -- Long
237
+ // eslint-disable-next-line unicorn/no-unsafe-string-replacement -- Safe here
238
+ String(this.newcharrefs[i]), '&' + this.newents[i] + ';'
224
239
  );
225
240
  }
226
241
 
@@ -231,9 +246,9 @@ export const getUnicodeConverter = () => {
231
246
  const ampkeep = await getPref('ampkeep');
232
247
 
233
248
  for (const ch of unicodeToConvert) {
234
- const codePoint = ch.codePointAt();
249
+ const codePoint = ch.codePointAt(0);
235
250
  const tempcharref = this.numericCharacterReferences.indexOf(
236
- codePoint
251
+ /** @type {number} */ (codePoint)
237
252
  );
238
253
 
239
254
  out += tempcharref !== -1 &&
@@ -247,7 +262,7 @@ export const getUnicodeConverter = () => {
247
262
 
248
263
  /**
249
264
  * @param {string} out
250
- * @returns {string}
265
+ * @returns {Promise<string>}
251
266
  */
252
267
  async htmlents2charrefDecval (out) {
253
268
  // If true, don't convert &apos;, &quot;, &lt;, &gt;, and &amp;
@@ -256,7 +271,7 @@ export const getUnicodeConverter = () => {
256
271
  if (!xmlentkeep || !builtinEntities.has(match1)) {
257
272
  // If recognized multiple char ent. (won't convert these to decimal)
258
273
  if (this.newents.includes(match1)) {
259
- return this.newcharrefs[this.newents.indexOf(match1)];
274
+ return String(this.newcharrefs[this.newents.indexOf(match1)]);
260
275
  }
261
276
  // If recognized single char. ent.
262
277
  if (this.entities.includes(match1)) {
@@ -274,7 +289,7 @@ export const getUnicodeConverter = () => {
274
289
 
275
290
  /**
276
291
  * @param {string} out
277
- * @returns {string}
292
+ * @returns {Promise<string>}
278
293
  */
279
294
  async htmlents2charrefHexval (out) {
280
295
  const xstyle = 'x';
@@ -296,7 +311,7 @@ export const getUnicodeConverter = () => {
296
311
  // If recognized multiple char. ent. (won't convert these to
297
312
  // hexadecimal)
298
313
  if (c !== -1) {
299
- return this.newcharrefs[c];
314
+ return String(this.newcharrefs[c]);
300
315
  }
301
316
 
302
317
  // If recognized single char. ent.
@@ -316,7 +331,7 @@ export const getUnicodeConverter = () => {
316
331
 
317
332
  /**
318
333
  * @param {string} out
319
- * @returns {string}
334
+ * @returns {Promise<string>}
320
335
  */
321
336
  async htmlents2unicodeval (out) {
322
337
  // If true, don't convert &apos;, &quot;, &lt;, &gt;, and &amp;
@@ -329,7 +344,7 @@ export const getUnicodeConverter = () => {
329
344
 
330
345
  // If recognized multiple char ent.
331
346
  if (this.newents.includes(match1)) {
332
- return this.newcharrefs[this.newents.indexOf(match1)];
347
+ return String(this.newcharrefs[this.newents.indexOf(match1)]);
333
348
  }
334
349
  // If recognized single char. ent.
335
350
  if (this.entities.includes(match1)) {
@@ -355,7 +370,7 @@ export const getUnicodeConverter = () => {
355
370
 
356
371
  /**
357
372
  * @param {string} out
358
- * @returns {string}
373
+ * @returns {Promise<string>}
359
374
  */
360
375
  async dec2hexval (out) {
361
376
  const xstyle = 'x';
@@ -405,7 +420,7 @@ export const getUnicodeConverter = () => {
405
420
  unicode += s + next;
406
421
  break;
407
422
  default: {
408
- const hexEsc = toconvert.slice(i + 1).match(/^([A-Fa-f\d]{1,5})(?:([A-Fa-f\d])|(\r\n|[ \t\r\n\f])?)/u); // 1-5 hex and WS, or 6 hex
423
+ const hexEsc = toconvert.slice(i + 1).match(/^([A-Fa-f\d]{1,5})(?:([A-Fa-f\d])|(\r\n|[ \t\r\n\f])?)/v); // 1-5 hex and WS, or 6 hex
409
424
  if (hexEsc) {
410
425
  i += hexEsc[0].length - 1; // We want to skip the whole structure
411
426
  const hex = hexEsc[1] + (hexEsc[2] || ''); // [2] only if is 6-digit
@@ -414,9 +429,9 @@ export const getUnicodeConverter = () => {
414
429
  // \u000 is disallowed in CSS 2.1 (behavior undefined) and above
415
430
  // 0x10FFFF is beyond valid Unicode; fix: disallow non-characters
416
431
  // too?
417
- if (dec > 0x10FFFF || dec === 0) {
432
+ if (dec === 0 || dec > 0x10FFFF) {
418
433
  // Replacement character since not valid Unicode
419
- unicode += '\uFFFD';
434
+ unicode += '\u{FFFD}';
420
435
  break;
421
436
  }
422
437
 
@@ -425,7 +440,7 @@ export const getUnicodeConverter = () => {
425
440
  // Too low ASCII to be converted (not a letter, digit,
426
441
  // underscore, or hyphen)
427
442
  // eslint-disable-next-line unicorn/prefer-ternary -- Structure
428
- if (dec < 0xA1 && (/[^\w-]/u).test(hexStr)) {
443
+ if (dec < 0xA1 && (/[^\w\-]/v).test(hexStr)) {
429
444
  // Don't convert since won't be valid if unescaped
430
445
  // Although https://www.w3.org/TR/CSS21/grammar.html#scanner
431
446
  // (under "nonascii" which is a possible (indirect) component
@@ -462,7 +477,7 @@ export const getUnicodeConverter = () => {
462
477
 
463
478
  /**
464
479
  * @param {string} toconvert
465
- * @param {UnicodeEscapeMode} mode
480
+ * @param {UnicodeEscapeMode} [mode]
466
481
  * @returns {string}
467
482
  */
468
483
  jsescape2unicodeval (toconvert, mode) {
@@ -479,7 +494,8 @@ export const getUnicodeConverter = () => {
479
494
  unicode += s;
480
495
  break;
481
496
  case 'u':
482
- hexChrs = (/^[a-fA-F\d]{6}|[a-fA-F\d]{4}/u).exec(toconvert.slice(i + 2));
497
+ // eslint-disable-next-line sonarjs/anchor-precedence -- Intended
498
+ hexChrs = (/^[a-fA-F\d]{6}|[a-fA-F\d]{4}/v).exec(toconvert.slice(i + 2));
483
499
  if (hexChrs) {
484
500
  unicode += String.fromCodePoint(
485
501
  Number.parseInt(hexChrs[0], 16)
@@ -498,7 +514,7 @@ export const getUnicodeConverter = () => {
498
514
  unicode += s;
499
515
  break;
500
516
  case 'r':
501
- unicode += '\u000D';
517
+ unicode += '\u{D}';
502
518
  break;
503
519
  case 'n':
504
520
  unicode += '\n';
@@ -516,7 +532,7 @@ export const getUnicodeConverter = () => {
516
532
  unicode += '\b';
517
533
  break;
518
534
  case 'u':
519
- hexChrs = (/^[a-fA-F\d]{4}/u).exec(toconvert.slice(i + 2));
535
+ hexChrs = (/^[a-fA-F\d]{4}/v).exec(toconvert.slice(i + 2));
520
536
  if (hexChrs) {
521
537
  unicode += String.fromCharCode(Number.parseInt(hexChrs[0], 16));
522
538
  i += hexChrs[0].length; // 4
@@ -536,7 +552,7 @@ export const getUnicodeConverter = () => {
536
552
 
537
553
  /**
538
554
  * @param {string} toconvert
539
- * @returns {string}
555
+ * @returns {Promise<string>}
540
556
  */
541
557
  async unicode2jsescapeval (toconvert) {
542
558
  return await this.unicode2charrefHexval(toconvert, true, 'javascript');
@@ -544,7 +560,7 @@ export const getUnicodeConverter = () => {
544
560
 
545
561
  /**
546
562
  * @param {string} toconvert
547
- * @returns {string}
563
+ * @returns {Promise<string>}
548
564
  */
549
565
  async unicodeTo6DigitVal (toconvert) {
550
566
  return await this.unicode2charrefHexval(toconvert, false, 'php');
@@ -552,7 +568,7 @@ export const getUnicodeConverter = () => {
552
568
 
553
569
  /**
554
570
  * @param {string} toconvert
555
- * @returns {string}
571
+ * @returns {Promise<string>}
556
572
  */
557
573
  async unicode2cssescapeval (toconvert) {
558
574
  return await this.unicode2charrefHexval(toconvert, false, 'css');
@@ -570,13 +586,13 @@ export const getUnicodeConverter = () => {
570
586
 
571
587
  /**
572
588
  * @param {string} toconvert
573
- * @returns {string}
589
+ * @returns {Promise<string>}
574
590
  */
575
591
  async unicode2CharDescVal (toconvert) {
576
592
  const asciiLt128 = await getPref('asciiLt128');
577
593
  return (await Promise.all([...toconvert].map(async (ch) => {
578
- const codePoint = ch.codePointAt();
579
- if (codePoint >= 128 || asciiLt128) {
594
+ const codePoint = /** @type {number} */ (ch.codePointAt(0));
595
+ if (asciiLt128 || codePoint >= 128) {
580
596
  const charDesc = await this.getCharDescForCodePoint(codePoint);
581
597
  if (charDesc) { // Skip if no description in database
582
598
  return String.raw`\C{` + charDesc + '}';
@@ -591,19 +607,21 @@ export const getUnicodeConverter = () => {
591
607
  * @returns {Promise<string>}
592
608
  */
593
609
  async charDesc2UnicodeVal (toconvert) {
610
+ /** @type {Promise<number|false|void>[]} */
594
611
  const promises = [];
595
- toconvert.replaceAll(/\\C\{([^}]*)\}/gu, (n, n1) => {
612
+ toconvert.replaceAll(/\\C\{([^\}]*)\}/gv, (n, n1) => {
596
613
  promises.push(this.lookupUnicodeValueByCharName(n1));
614
+ return ''; // No-op
597
615
  });
598
616
 
599
617
  const unicodeVals = await Promise.all(promises);
600
618
 
601
619
  let i = -1;
602
- return toconvert.replaceAll(/\\C\{([^}]*)\}/gu, () => {
620
+ return toconvert.replaceAll(/\\C\{([^\}]*)\}/gv, () => {
603
621
  ++i;
604
- return unicodeVals[i]
605
- ? String.fromCodePoint(unicodeVals[i])
606
- : '\uFFFD'; // Replacement character if not found?
622
+ return Object.hasOwn(unicodeVals, i)
623
+ ? String.fromCodePoint(/** @type {number} */ (unicodeVals[i]))
624
+ : '\u{FFFD}'; // Replacement character if not found?
607
625
  });
608
626
  }
609
627
 
@@ -611,7 +629,7 @@ export const getUnicodeConverter = () => {
611
629
  * Obtain a Unicode character description for a given decimal-expressed
612
630
  * code point.
613
631
  * @param {Integer} dec The code point of the description to obtain
614
- * @returns {string} The Unicode character description
632
+ * @returns {Promise<string|void>} The Unicode character description
615
633
  */
616
634
  async getCharDescForCodePoint (dec) {
617
635
  // Todo: This should support CJK and those which are only marked by
@@ -651,7 +669,7 @@ export const getUnicodeConverter = () => {
651
669
  /**
652
670
  * Search for a Unicode character value matching a given description.
653
671
  * @param {string} value
654
- * @returns {Integer}
672
+ * @returns {Promise<Integer|false|void>}
655
673
  */
656
674
  async lookupUnicodeValueByCharName (value) {
657
675
  // todo: Character names for Unihan
@@ -665,23 +683,23 @@ export const getUnicodeConverter = () => {
665
683
  /* istanbul ignore next -- Known todo */
666
684
  : 'searchkDefinition';
667
685
  await this.searchUnicode(
668
- {id, value}, table, 'noChart=true', 'strict=true'
686
+ {id, value}, table, true, true
669
687
  );
670
- if (!this.descripts[0] && value.length <= 7) {
688
+ if (!this.descripts?.[0] && value.length <= 7) {
671
689
  // Try Hangul (if possible size for Hangul)
672
690
  // Fix: Is Hangul allowed in PHP 6 Unicode escape names?
673
691
  const ret = getHangulFromName(value);
674
692
  return ret ? ret.charCodeAt(0) : false;
675
693
  }
676
- return this.descripts[0];
694
+ return this.descripts?.[0];
677
695
  }
678
696
 
679
697
  // Used for conversions, so included here (also used externally)
680
698
  /**
681
699
  * @param {{id: string, value: string}} obj E.g., an input element
682
- * @param {string} table
683
- * @param {boolean} nochart
684
- * @param {boolean} strict
700
+ * @param {string} [table]
701
+ * @param {boolean} [nochart]
702
+ * @param {boolean} [strict]
685
703
  * @returns {Promise<void>}
686
704
  */
687
705
  async searchUnicode (obj, table, nochart, strict) { // Fix: allow Jamo!
@@ -694,26 +712,34 @@ export const getUnicodeConverter = () => {
694
712
  /* istanbul ignore next -- Just a guard */
695
713
  if (
696
714
  // Don't query the other databases here
697
- (obj.id.startsWith('searchk') && table === 'UnicodeData') ||
698
- ((/^search[^k]/u).test(obj.id) && table === 'Unihan')
715
+ (table === 'UnicodeData' && obj.id.startsWith('searchk')) ||
716
+ (table === 'Unihan' && (/^search[^k]/v).test(obj.id))
699
717
  ) {
700
718
  return;
701
719
  }
702
- const nameDesc = obj.id.replace(/^search/u, '');
703
-
704
- // const nameDesc = (table === 'Unihan') ? 'kDefinition'
705
- // : 'Name'; // Fix: let Unihan search Mandarin, etc.
706
-
707
- const conn = table === 'Unihan'
708
- ? unicodecharref.unihanDatabase
709
- : charrefunicodeDb;
710
-
711
720
  if (table === 'Unihan' && !nochart && !unicodecharref.unihanDb_exists) {
712
721
  alert(this._('need_download_unihan'));
713
722
  return;
714
723
  }
715
724
 
725
+ const nameDesc = obj.id.replace(/^search/v, '');
726
+
727
+ // const nameDesc = (table === 'Unihan') ? 'kDefinition'
728
+ // : 'Name'; // Fix: let Unihan search Mandarin, etc.
729
+
730
+ const conn =
731
+ /**
732
+ * @type {import('./charrefunicodeDb.js').UnicodeDatabase|
733
+ * import('./charrefunicodeDb.js').UnihanDatabase}
734
+ */ (
735
+ table === 'Unihan'
736
+ ? unicodecharref.unihanDatabase
737
+ : charrefunicodeDb
738
+ );
739
+
716
740
  await conn.connect();
741
+
742
+ /** @type {number[]} */
717
743
  this.descripts = [];
718
744
 
719
745
  try {
@@ -753,18 +779,18 @@ export const getUnicodeConverter = () => {
753
779
  ? chars.filter((chr) => {
754
780
  const cell = table === 'Unihan'
755
781
  /* istanbul ignore next -- Not yet using strict checking */
756
- ? chr.columns[
782
+ ? /** @type {{columns: string[]}} */ (chr).columns[
757
783
  unicodecharref.Unihan.indexOf(field)
758
784
  ]
759
- : chr[camelizedField];
785
+ : /** @type {Record<string, string>}} */ (chr)[camelizedField];
760
786
  return cell.toLowerCase() === nameDescVal.toLowerCase();
761
787
  })
762
788
  : chars.filter((chr) => {
763
789
  const cell = table === 'Unihan'
764
- ? chr.columns[
790
+ ? /** @type {{columns: string[]}} */ (chr).columns[
765
791
  unicodecharref.Unihan.indexOf(field)
766
792
  ]
767
- : chr[camelizedField];
793
+ : /** @type {Record<string, string>}} */ (chr)[camelizedField];
768
794
  return cell.toLowerCase().includes(
769
795
  nameDescVal.toLowerCase()
770
796
  );
@@ -779,7 +805,7 @@ export const getUnicodeConverter = () => {
779
805
  return;
780
806
  }
781
807
  // Fix: inefficient, but fits more easily into current pattern
782
- this.descripts.push(hex);
808
+ this.descripts?.push(hex);
783
809
  });
784
810
  /* istanbul ignore next -- Debugging */
785
811
  } catch (e) {