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,34 +1,49 @@
1
1
  // Todo: Review `fromCharCode`, `charCodeAt`, and `charAt` on whether
2
2
  // need modern substitutions
3
3
 
4
+ /**
5
+ * @typedef {number} PositiveInteger
6
+ */
7
+
8
+ /* eslint-disable jsdoc/reject-any-type -- Arbitrary */
9
+ /**
10
+ * @typedef {any} AnyValue
11
+ */
12
+ /* eslint-enable jsdoc/reject-any-type -- Arbitrary */
13
+
4
14
  /**
5
15
  *
6
16
  */
7
17
  class UnicodeDB {
8
18
  /**
9
- * @param {PlainObject} cfg
10
- * @param {string} cfg.name
19
+ * @param {object} cfg
20
+ * @param {string} [cfg.name]
11
21
  * @param {PositiveInteger} [cfg.version]
12
22
  */
13
23
  constructor ({name = 'unicode', version = 1} = {}) {
14
- Object.assign(this, {name, version});
24
+ this.name = name;
25
+ this.version = version;
15
26
  this.db = null;
16
27
  }
17
28
 
18
29
  /**
19
- * @returns {void}
20
- */
30
+ * @returns {void}
31
+ */
21
32
  close () {
22
- this.db.close();
33
+ this.db?.close();
23
34
  }
24
35
 
25
36
  /**
26
37
  * @param {string} storeName
27
- * @param {string} key
28
- * @returns {Promise<object>}
38
+ * @param {string} [key]
39
+ * @returns {Promise<{
40
+ * codePoint: string, columns?: string[], [key: string]: unknown
41
+ * }[]>}
29
42
  */
30
43
  getAll (storeName, key) {
31
- const tx = this.db.transaction(storeName, 'readonly');
44
+ const tx = /** @type {IDBDatabase} */ (
45
+ this.db
46
+ ).transaction(storeName, 'readonly');
32
47
  const store = tx.objectStore(storeName);
33
48
 
34
49
  const req = store.getAll(key);
@@ -47,17 +62,21 @@ class UnicodeDB {
47
62
  /* eslint-disable class-methods-use-this -- Abstract */
48
63
  /**
49
64
  * @abstract
65
+ * @param {AnyValue} cfg
50
66
  */
51
- upgradeneeded () {
67
+ upgradeneeded (
68
+ // eslint-disable-next-line no-unused-vars -- Needed as base method
69
+ cfg
70
+ ) {
52
71
  throw new Error('`UnicodeDB.upgradeneeded` is an abstract method');
53
72
  }
54
73
  /* eslint-enable class-methods-use-this -- Abstract */
55
74
 
56
75
  /**
57
76
  * @param {object} [cfg]
58
- * @param {JSON} [cfg.updateUnicodeData]
59
- * @param {GenericFunction} [cfg.versionchange]
60
- * @returns {Promise<void>}
77
+ * @param {AnyValue} [cfg.updateUnicodeData]
78
+ * @param {(e: Event) => void} [cfg.versionchange]
79
+ * @returns {Promise<IDBDatabase>}
61
80
  */
62
81
  connect ({updateUnicodeData, versionchange} = {}) {
63
82
  /* eslint-disable promise/avoid-new -- No Promise API */
@@ -67,13 +86,18 @@ class UnicodeDB {
67
86
  );
68
87
  if (updateUnicodeData) {
69
88
  req.addEventListener('upgradeneeded', (e) => {
70
- const {result: db} = e.target;
89
+ const db = /** @type {EventTarget & {result: IDBDatabase}} */ (
90
+ e.target
91
+ )?.result;
71
92
  this.db = db;
72
93
  this.upgradeneeded({updateUnicodeData});
73
94
  });
74
95
  }
75
- req.addEventListener('success', ({target}) => {
76
- this.db = target.result;
96
+ req.addEventListener('success', (e) => {
97
+ const db = /** @type {EventTarget & {result: IDBDatabase}} */ (
98
+ e.target
99
+ )?.result;
100
+ this.db = db;
77
101
  if (versionchange) {
78
102
  this.db.addEventListener('versionchange', (ev) => {
79
103
  versionchange(ev);
@@ -97,20 +121,22 @@ class UnicodeDB {
97
121
  */
98
122
  export class UnihanDatabase extends UnicodeDB {
99
123
  /**
100
- * @param {PlainObject} cfg
101
- * @param {PositiveInteger} cfg.version
124
+ * @param {object} [cfg]
125
+ * @param {PositiveInteger} [cfg.version]
102
126
  */
103
127
  constructor ({version} = {}) {
104
128
  // We create a separate database so updates do not clobber both databases
105
129
  super({name: 'unicode-input-toolconverter-Unihan', version});
106
130
  }
107
131
  /**
108
- * @param {string} codePoint
109
- * @throws {Error}
110
- * @returns {Promise<string[]>}
111
- */
132
+ * @param {string} codePoint
133
+ * @throws {Error}
134
+ * @returns {Promise<string[]>}
135
+ */
112
136
  getUnicodeFields (codePoint) {
113
- const tx = this.db.transaction(['Unihan'], 'readonly');
137
+ const tx = /** @type {IDBDatabase} */ (
138
+ this.db
139
+ ).transaction(['Unihan'], 'readonly');
114
140
  const store = tx.objectStore('Unihan');
115
141
 
116
142
  const request = store.get(codePoint);
@@ -126,19 +152,30 @@ export class UnihanDatabase extends UnicodeDB {
126
152
  }
127
153
 
128
154
  /**
129
- * @param {string} key
130
- * @returns {Promise<object>}
155
+ * @param {string} [key]
156
+ * @returns {Promise<{
157
+ * codePoint: string, columns?: string[], [key: string]: unknown
158
+ * }[]>}
131
159
  */
132
160
  getAll (key) {
133
161
  return super.getAll('Unihan', key);
134
162
  }
135
163
 
136
164
  /**
137
- * @param {JSON} updateUnicodeData
165
+ * @param {AnyValue} cfg
138
166
  * @returns {void}
139
167
  */
140
- upgradeneeded ({updateUnicodeData}) {
141
- const store = this.db.createObjectStore('Unihan', {
168
+ upgradeneeded (cfg) {
169
+ // eslint-disable-next-line prefer-destructuring -- TS
170
+ const updateUnicodeData =
171
+ /**
172
+ * @type {{
173
+ * updateUnicodeData: [codePoint: string, ...info: string[]][]
174
+ * }}
175
+ */ (cfg).updateUnicodeData;
176
+ const store = /** @type {IDBDatabase} */ (
177
+ this.db
178
+ ).createObjectStore('Unihan', {
142
179
  keyPath: 'codePoint'
143
180
  });
144
181
  store.createIndex('code-point', 'codePoint', {
@@ -161,48 +198,59 @@ export class UnihanDatabase extends UnicodeDB {
161
198
  */
162
199
  export class UnicodeDatabase extends UnicodeDB {
163
200
  /**
164
- * @param {PlainObject} cfg
165
- * @param {PositiveInteger} cfg.version
201
+ * @param {object} [cfg]
202
+ * @param {PositiveInteger} [cfg.version]
166
203
  */
167
204
  constructor ({version} = {}) {
168
205
  super({name: 'unicode-input-toolconverter', version});
169
206
  }
170
207
 
171
208
  /**
172
- * @param {string} key
173
- * @returns {Promise<object>}
209
+ * @param {string} [key]
210
+ * @returns {Promise<{
211
+ * codePoint: string, columns?: string[], [key: string]: unknown
212
+ * }[]>}
174
213
  */
175
214
  getAll (key) {
176
215
  return super.getAll('UnicodeData', key);
177
216
  }
178
217
 
179
218
  /**
180
- * @param {JSON} updateUnicodeData
219
+ * @param {AnyValue} cfg
181
220
  * @returns {void}
182
221
  */
183
- upgradeneeded ({updateUnicodeData}) {
184
- const store = this.db.createObjectStore('UnicodeData', {
222
+ upgradeneeded (cfg) {
223
+ // eslint-disable-next-line prefer-destructuring -- TS
224
+ const updateUnicodeData =
225
+ /**
226
+ * @type {{
227
+ * updateUnicodeData: [codePoint: string, ...info: string[]][]
228
+ * }}
229
+ */ (cfg).updateUnicodeData;
230
+ const store = /** @type {IDBDatabase} */ (
231
+ this.db
232
+ ).createObjectStore('UnicodeData', {
185
233
  keyPath: 'codePoint'
186
234
  });
187
235
  store.createIndex('code-point', 'codePoint', {
188
236
  unique: true
189
237
  });
190
238
  updateUnicodeData.forEach((codePointInfoRow) => {
191
- // http://www.unicode.org/reports/tr44/#UnicodeData.txt
239
+ // https://www.unicode.org/reports/tr44/#UnicodeData.txt
192
240
  const [
193
241
  codePoint, name, generalCategory, canonicalCombiningClass, bidiClass,
194
242
  decomposition, numeric6, numeric7, numeric8,
195
243
  bidiMirrored, unicode1Name, isoComment,
196
244
  simpleUppercaseMapping, simpleLowercaseMapping, simpleTitlecaseMapping
197
245
  ] = codePointInfoRow;
198
- const {groups: {
199
- decompositionType,
200
- decompositionMapping
201
- }} = (
202
- /<(?<decompositionType>[^>]*)>\s+(?<decompositionMapping>.*)/u
246
+ const groups = (
247
+ /<(?<decompositionType>[^>]*)>\s+(?<decompositionMapping>.*)/v
203
248
  ).exec(
204
249
  decomposition
205
- ) ?? {groups: {}};
250
+ )?.groups ?? {};
251
+
252
+ const {decompositionType, decompositionMapping} = groups;
253
+
206
254
  let numericType = 'None';
207
255
  if (numeric6) {
208
256
  numericType = 'Decimal';
@@ -211,7 +259,7 @@ export class UnicodeDatabase extends UnicodeDB {
211
259
  } else if (numeric8) {
212
260
  numericType = 'Numeric';
213
261
  }
214
- const numericValue = numericType ? numeric8 : Number.NaN;
262
+ const numericValue = numericType ? numeric8 : NaN;
215
263
 
216
264
  store.put({
217
265
  codePoint, name, generalCategory, canonicalCombiningClass, bidiClass,
@@ -223,15 +271,19 @@ export class UnicodeDatabase extends UnicodeDB {
223
271
  }
224
272
 
225
273
  /**
226
- * @param {string} codePoint
227
- * @returns {Promise<string[]>}
228
- */
274
+ * @param {string} codePoint
275
+ * @returns {Promise<{
276
+ * name: string, unicode1Name: string, [key: string]: string
277
+ * }>}
278
+ */
229
279
  getUnicodeFields (codePoint) {
230
280
  // const entityInParentheses = '(' + entity + ') ';
231
281
  // Todo: Should this not be padded to 6??
232
282
  // const currentStartCharCodeUpperCaseHexPadded =
233
283
  // currentStartCharCode.toString(16).toUpperCase().padStart(4, '0');
234
- const tx = this.db.transaction(['UnicodeData'], 'readonly');
284
+ const tx = /** @type {IDBDatabase} */ (
285
+ this.db
286
+ ).transaction(['UnicodeData'], 'readonly');
235
287
  const store = tx.objectStore('UnicodeData');
236
288
  const request = store.get(codePoint);
237
289
  // eslint-disable-next-line promise/avoid-new -- No Promise API
@@ -251,8 +303,6 @@ export class UnicodeDatabase extends UnicodeDB {
251
303
  }
252
304
 
253
305
  const charrefunicodeDb = new UnicodeDatabase();
254
- /*
255
- const unihanDb = new UnihanDatabase();
256
- */
306
+ /* const unihanDb = new UnihanDatabase(); */
257
307
 
258
308
  export default charrefunicodeDb;
@@ -1,17 +1,26 @@
1
1
  // Todo: Auto-generate this function
2
2
 
3
+ /**
4
+ * @typedef {number} PositiveInteger
5
+ */
6
+
3
7
  /**
4
8
  * @param {PositiveInteger} num
5
- * @param {IntlDom} _
9
+ * @param {import('intl-dom').I18NCallback<string>} _
6
10
  * @returns {{
7
11
  * codePointStart: string, script: string, plane: PositiveInteger,
8
- * privateuse: boolean, surrogate: boolean|string
12
+ * privateuse: boolean, surrogate: false|string
9
13
  * }}
10
14
  */
11
15
  export default function getScriptInfoForCodePoint (num, _) {
12
- let privateuse = false, surrogate = false;
16
+ let privateuse = false;
17
+ /** @type {false|string} */
18
+ let surrogate = false;
13
19
  let plane = num >= 0x10000 && num <= 0x1FFFF ? 1 : 0;
14
- let script = '', codePointStart = '';
20
+ // eslint-disable-next-line no-useless-assignment -- Ok
21
+ let script = '';
22
+ // eslint-disable-next-line no-useless-assignment -- Ok
23
+ let codePointStart = '';
15
24
  if (num < 0x0080) {
16
25
  codePointStart = '0000';
17
26
  script = _('Basic_Latin'); // + _ ('comma') + ' ' +
@@ -1,10 +1,14 @@
1
1
  /* eslint-disable unicorn/prefer-string-slice -- Easier */
2
2
  // Function can also be used standalone
3
3
  /**
4
- * @namespace This contains methods for translating Korean Hangul/Jamo,
5
- * since these are obtained programmatically and not through the Unicode (or
6
- * Unihan) database
7
- */
4
+ * @namespace This contains methods for translating Korean Hangul/Jamo,
5
+ * since these are obtained programmatically and not through the Unicode (or
6
+ * Unihan) database
7
+ */
8
+
9
+ /**
10
+ * @typedef {number} Integer
11
+ */
8
12
 
9
13
  // Private static
10
14
  const JAMO_L_TABLE = [
@@ -36,7 +40,7 @@ const sBase = 0xAC00,
36
40
  * Currently unused.
37
41
  * @param {Integer} syllableCode Decimal code point for Hangul syllable
38
42
  * to decompose
39
- * @returns {Integer[]|string} An array of the numeric value of each
43
+ * @returns {string[]|string} An array of the numeric value of each
40
44
  * component or string if unchanged
41
45
  */
42
46
  function decomposeHangul (syllableCode) {
@@ -57,8 +61,8 @@ function decomposeHangul (syllableCode) {
57
61
  }
58
62
  /**
59
63
  *
60
- * @param {string[]} source
61
- * @returns {string[]}
64
+ * @param {string} source
65
+ * @returns {string|string[]}
62
66
  */
63
67
  function composeHangul (source) {
64
68
  const len = source.length;
@@ -75,9 +79,9 @@ function composeHangul (source) {
75
79
 
76
80
  chars.slice(1).forEach((ch) => {
77
81
  // 1. check to see if two current characters are L and V
78
- const lIndex = last.codePointAt() - lBase;
82
+ const lIndex = /** @type {number} */ (last.codePointAt(0)) - lBase;
79
83
  if (lIndex > 0 && lIndex < lCount) {
80
- const vIndex = ch.codePointAt() - vBase;
84
+ const vIndex = /** @type {number} */ (ch.codePointAt(0)) - vBase;
81
85
  if (vIndex > 0 && vIndex < vCount) {
82
86
  // make syllable of form LV
83
87
  last = String.fromCodePoint(
@@ -89,12 +93,14 @@ function composeHangul (source) {
89
93
  }
90
94
 
91
95
  // 2. check to see if two current characters are LV and T
92
- const sIndex = last.codePointAt() - sBase;
96
+ const sIndex = /** @type {number} */ (last.codePointAt(0)) - sBase;
93
97
  if (sIndex > 0 && sIndex < sCount && (sIndex % tCount) === 0) {
94
- const tIndex = ch.codePointAt() - tBase;
98
+ const tIndex = /** @type {number} */ (ch.codePointAt(0)) - tBase;
95
99
  if (tIndex >= 0 && tIndex < tCount) {
96
100
  // make syllable of form LVT
97
- last = String.fromCodePoint(last.codePointAt() + tIndex);
101
+ last = String.fromCodePoint(
102
+ /** @type {number} */ (last.codePointAt(0)) + tIndex
103
+ );
98
104
  result[result.length - 1] = last; // reset last
99
105
  return; // discard ch
100
106
  }
@@ -110,12 +116,12 @@ function composeHangul (source) {
110
116
  * Gets a Unicode character for the passed-in Hangul syllable name.
111
117
  * @param {string} name The name of the syllable to find
112
118
  * @author Brett Zamir (others adapted directly from Unicode)
113
- * @returns {string|boolean} False if invalid, or otherwise the Hangul
119
+ * @returns {string|false} False if invalid, or otherwise the Hangul
114
120
  * character represented by the supplied name
115
121
  */
116
122
  function getHangulFromName (name) {
117
123
  // Turn indices into individual Jamo characters
118
- let t, lIndex, vIndex, tIndex;
124
+ let lIndex, vIndex, tIndex;
119
125
  let ptr = 1;
120
126
 
121
127
  // L (can be 1-2 in name length)
@@ -159,20 +165,17 @@ function getHangulFromName (name) {
159
165
  const v = getJamoForIndex(vIndex, 'v');
160
166
 
161
167
  // May only be LV
162
- t = '';
163
- if (tIndex) {
164
- t = getJamoForIndex(tIndex, 't');
165
- }
168
+ const t = tIndex ? getJamoForIndex(tIndex, 't') : '';
166
169
 
167
170
  // Join Jamo characters together
168
171
  const jamo = l + v + t;
169
172
  // Convert Jamo into composite Hangul syllable
170
- return composeHangul(jamo).join('');
173
+ return /** @type {string[]} */ (composeHangul(jamo)).join('');
171
174
  }
172
175
 
173
176
  /**
174
177
  * Utility (could be adapted to accept the letter(s)).
175
- * @param {string} index
178
+ * @param {number} index
176
179
  * @param {'l'|'v'|'t'} type
177
180
  * @throws {TypeError}
178
181
  * @returns {string}
@@ -190,6 +193,10 @@ function getJamoForIndex (index, type) {
190
193
  }
191
194
  }
192
195
 
196
+ /**
197
+ * @typedef {number} PositiveInteger
198
+ */
199
+
193
200
  /**
194
201
  * @param {PositiveInteger} syllableCode
195
202
  * @throws {Error}
@@ -1,5 +1,5 @@
1
1
 
2
2
  {
3
3
  "$comment": "Do not edit this file; this is an auto-generated file used to track script names, some of which may end up needing to be deleted from locale files if no longer in use",
4
- "lastScriptNames": ["European_Scripts","Armenian","Armenian_Ligatures","Carian","Caucasian_Albanian","Cypriot_Syllabary","Cypro_Minoan","Cyrillic","Cyrillic_Supplement","Cyrillic_Extended_A","Cyrillic_Extended_B","Cyrillic_Extended_C","Cyrillic_Extended_D","Elbasan","Georgian","Georgian_Extended","Georgian_Supplement","Glagolitic","Glagolitic_Supplement","Gothic","Greek","Greek_Extended","Ancient_Greek_Numbers","Latin","Basic_Latin","Latin_1_Supplement","Latin_Extended_A","Latin_Extended_B","Latin_Extended_C","Latin_Extended_D","Latin_Extended_E","Latin_Extended_F","Latin_Extended_G","Latin_Extended_Additional","Latin_Ligatures","Fullwidth_Latin_Letters","IPA_Extensions","Phonetic_Extensions","Phonetic_Extensions_Supplement","Linear_A","Linear_B","Linear_B_Syllabary","Linear_B_Ideograms","Aegean_Numbers","Lycian","Lydian","Ogham","Old_Hungarian","Old_Italic","Old_Permic","Phaistos_Disc","Runic","Shavian","Vithkuqi","Modifier_Letters","Modifier_Tone_Letters","Spacing_Modifier_Letters","Superscripts_and_Subscripts","Combining_Marks","Combining_Diacritical_Marks","Combining_Diacritical_Marks_Extended","Combining_Diacritical_Marks_Supplement","Combining_Diacritical_Marks_for_Symbols","Combining_Half_Marks","Miscellaneous","Alphabetic_Presentation_Forms","ASCII_Characters","Halfwidth_and_Fullwidth_Forms","African_Scripts","Adlam","Bamum","Bamum_Supplement","Bassa_Vah","Coptic","Coptic_in_Greek_block","Coptic_Epact_Numbers","Egyptian_Hieroglyphs","Egyptian_Hieroglyph_Format_Controls","Ethiopic","Ethiopic_Supplement","Ethiopic_Extended","Ethiopic_Extended_A","Ethiopic_Extended_B","Medefaidrin","Mende_Kikakui","Meroitic","Meroitic_Cursive","Meroitic_Hieroglyphs","N_Ko","Osmanya","Tifinagh","Vai","Middle_Eastern_Scripts","Anatolian_Hieroglyphs","Arabic","Arabic_Supplement","Arabic_Extended_A","Arabic_Extended_B","Arabic_Extended_C","Arabic_Presentation_Forms_A","Arabic_Presentation_Forms_B","Aramaic__Imperial","Avestan","Chorasmian","Cuneiform","Cuneiform_Numbers_and_Punctuation","Early_Dynastic_Cuneiform","Old_Persian","Ugaritic","Elymaic","Hatran","Hebrew","Hebrew_Presentation_Forms","Mandaic","Nabataean","Old_North_Arabian","Old_South_Arabian","Pahlavi__Inscriptional","Pahlavi__Psalter","Palmyrene","Parthian__Inscriptional","Phoenician","Samaritan","Syriac","Syriac_Supplement","Yezidi","Central_Asian_Scripts","Manichaean","Marchen","Mongolian","Mongolian_Supplement","Old_Sogdian","Old_Turkic","Old_Uyghur","Phags_Pa","Sogdian","Soyombo","Tibetan","Zanabazar_Square","South_Asian_Scripts","Ahom","Bengali_and_Assamese","Bhaiksuki","Brahmi","Chakma","Devanagari","Devanagari_Extended","Devanagari_Extended_A","Dives_Akuru","Dogra","Grantha","Gujarati","Gunjala_Gondi","Gurmukhi","Kaithi","Kannada","Kharoshthi","Khojki","Khudawadi","Lepcha","Limbu","Mahajani","Malayalam","Masaram_Gondi","Meetei_Mayek","Meetei_Mayek_Extensions","Modi","Mro","Multani","Nag_Mundari","Nandinagari","Newa","Ol_Chiki","Oriya","Saurashtra","Sharada","Siddham","Sinhala","Sinhala_Archaic_Numbers","Sora_Sompeng","Syloti_Nagri","Takri","Tamil","Tamil_Supplement","Telugu","Thaana","Tirhuta","Toto","Vedic_Extensions","Wancho","Warang_Citi","Southeast_Asian_Scripts","Cham","Hanifi_Rohingya","Kayah_Li","Khmer","Khmer_Symbols","Lao","Myanmar","Myanmar_Extended_A","Myanmar_Extended_B","New_Tai_Lue","Nyiakeng_Puachue_Hmong","Pahawh_Hmong","Pau_Cin_Hau","Tai_Le","Tai_Tham","Tai_Viet","Tangsa","Thai","Indonesian___Philippine_Scripts","Balinese","Batak","Buginese","Buhid","Hanunoo","Javanese","Kawi","Makasar","Rejang","Sundanese","Sundanese_Supplement","Tagalog","Tagbanwa","East_Asian_Scripts","Bopomofo","Bopomofo_Extended","CJK_Unified_Ideographs__Han_","CJK_Extension_A","CJK_Extension_B","CJK_Extension_C","CJK_Extension_D","CJK_Extension_E","CJK_Extension_F","CJK_Extension_G","CJK_Extension_H","CJK_Extension_I","_see_also_Unihan_Database_","CJK_Compatibility_Ideographs","CJK_Compatibility_Ideographs_Supplement","CJK_Radicals___Kangxi_Radicals","CJK_Radicals_Supplement","CJK_Strokes","Ideographic_Description_Characters","Hangul_Jamo","Hangul_Jamo_Extended_A","Hangul_Jamo_Extended_B","Hangul_Compatibility_Jamo","Halfwidth_Jamo","Hangul_Syllables","Hiragana","Kana_Extended_A","Kana_Extended_B","Kana_Supplement","Small_Kana_Extension","Kanbun","Katakana","Katakana_Phonetic_Extensions","Halfwidth_Katakana","Khitan_Small_Script","Lisu","Lisu_Supplement","Miao","Nushu","Tangut","Tangut_Components","Tangut_Supplement","Yi","Yi_Syllables","Yi_Radicals","American_Scripts","Cherokee","Cherokee_Supplement","Deseret","Osage","Unified_Canadian_Aboriginal_Syllabics","UCAS_Extended","UCAS_Extended_A","Notational_Systems","Braille_Patterns","Musical_Symbols","Ancient_Greek_Musical_Notation","Byzantine_Musical_Symbols","Znamenny_Musical_Notation","Duployan","Shorthand_Format_Controls","Sutton_SignWriting","Punctuation","General_Punctuation","ASCII_Punctuation","Latin_1_Punctuation","Supplemental_Punctuation","CJK_Symbols_and_Punctuation","Ideographic_Symbols_and_Punctuation","CJK_Compatibility_Forms","Halfwidth_and_Fullwidth_Forms","Small_Form_Variants","Vertical_Forms","Alphanumeric_Symbols","Letterlike_Symbols","Roman_Symbols","Mathematical_Alphanumeric_Symbols","Arabic_Mathematical_Alphabetic_Symbols","Enclosed_Alphanumerics","Enclosed_Alphanumeric_Supplement","Enclosed_CJK_Letters_and_Months","Enclosed_Ideographic_Supplement","CJK_Compatibility","Additional_Squared_Symbols","Technical_Symbols","APL_symbols","Control_Pictures","Miscellaneous_Technical","Optical_Character_Recognition__OCR_","Numbers___Digits","_see_also_specific_scripts_","ASCII_Digits","Fullwidth_ASCII_Digits","Common_Indic_Number_Forms","Coptic_Epact_Numbers","Counting_Rod_Numerals","Cuneiform_Numbers_and_Punctuation","Indic_Siyaq_Numbers","Kaktovik_Numerals","Mayan_Numerals","Number_Forms","Ottoman_Siyaq_Numbers","Rumi_Numeral_Symbols","Sinhala_Archaic_Numbers","Super_and_Subscripts","Mathematical_Symbols","Arrows","Supplemental_Arrows_A","Supplemental_Arrows_B","Supplemental_Arrows_C","Additional_Arrows","Miscellaneous_Symbols_and_Arrows","Mathematical_Alphanumeric_Symbols","Arabic_Mathematical_Alphabetic_Symbols","Letterlike_Symbols","Mathematical_Operators","Basic_operators__Plus__Factorial__Division__Multiplication","Supplemental_Mathematical_Operators","Miscellaneous_Mathematical_Symbols_A","Miscellaneous_Mathematical_Symbols_B","Floors_and_Ceilings","Invisible_Operators","Geometric_Shapes","Additional_Shapes","Box_Drawing","Block_Elements","Geometric_Shapes_Extended","Emoji___Pictographs","Dingbats","Ornamental_Dingbats","Emoticons","Miscellaneous_Symbols","Miscellaneous_Symbols_And_Pictographs","Supplemental_Symbols_and_Pictographs","Symbols_and_Pictographs_Extended_A","Transport_and_Map_Symbols","Other_Symbols","Alchemical_Symbols","Ancient_Symbols","Currency_Symbols","_see_also_specific_scripts_","Dollar_Sign__Euro_Sign","Yen__Pound_and_Cent","Fullwidth_Currency_Symbols","Rial_Sign","Game_Symbols","Chess__Checkers_Draughts","Chess_Symbols","Domino_Tiles","Japanese_Chess","Mahjong_Tiles","Playing_Cards","Card_suits","Miscellaneous_Symbols_and_Arrows","Symbols_for_Legacy_Computing","Yijing_Symbols","Yijing_Mono___Di__and_Trigrams","Yijing_Hexagram_Symbols","Tai_Xuan_Jing_Symbols","Specials","Controls__tC0__tC1","Layout_Controls","Invisible_Operators","Specials","Tags","Variation_Selectors","Variation_Selectors_Supplement","Private_Use","Private_Use_Area","Supplementary_Private_Use_Area_A","Supplementary_Private_Use_Area_B","Surrogates","High_Surrogates","Low_Surrogates","Noncharacters_in_Charts","Noncharacters_in_blocks","Range_in_Arabic_Presentation_Forms_A","Range_in_Specials","Noncharacters_at_end_of____","BMP__Plane_1__Plane_2__Plane_3__Plane_4__Plane_5__Plane_6__Plane_7__Plane_8__Plane_9__Plane_10__Plane_11__Plane_12__Plane_13__Plane_14__Plane_15__Plane_16"]
4
+ "lastScriptNames": ["European_Scripts","Armenian","Armenian_Ligatures","Caucasian_Albanian","Cypriot_Syllabary","Cypro_Minoan","Cyrillic","Cyrillic_Supplement","Cyrillic_Extended_A","Cyrillic_Extended_B","Cyrillic_Extended_C","Cyrillic_Extended_D","Elbasan","Georgian","Georgian_Extended","Georgian_Supplement","Glagolitic","Glagolitic_Supplement","Gothic","Greek","Greek_Extended","Ancient_Greek_Numbers","Latin","Basic_Latin","Latin_1_Supplement","Latin_Extended_A","Latin_Extended_B","Latin_Extended_C","Latin_Extended_D","Latin_Extended_E","Latin_Extended_F","Latin_Extended_G","Latin_Extended_Additional","Latin_Ligatures","Fullwidth_Latin_Letters","IPA_Extensions","Phonetic_Extensions","Phonetic_Extensions_Supplement","Linear_A","Linear_B","Linear_B_Syllabary","Linear_B_Ideograms","Aegean_Numbers","Ogham","Old_Hungarian","Old_Italic","Old_Permic","Phaistos_Disc","Runic","Shavian","Todhri","Vithkuqi","Modifier_Letters","Modifier_Tone_Letters","Spacing_Modifier_Letters","Superscripts_and_Subscripts","Combining_Marks","Combining_Diacritical_Marks","Combining_Diacritical_Marks_Extended","Combining_Diacritical_Marks_Supplement","Combining_Diacritical_Marks_for_Symbols","Combining_Half_Marks","Miscellaneous","Alphabetic_Presentation_Forms","ASCII_Characters","Halfwidth_and_Fullwidth_Forms","African_Scripts","Adlam","Bamum","Bamum_Supplement","Bassa_Vah","Beria_Erfe","Coptic","Coptic_in_Greek_block","Coptic_Epact_Numbers","Egyptian_Hieroglyphs","Egyptian_Hieroglyph_Format_Controls","Egyptian_Hieroglyphs_Extended_A","Ethiopic","Ethiopic_Supplement","Ethiopic_Extended","Ethiopic_Extended_A","Ethiopic_Extended_B","Garay","Medefaidrin","Mende_Kikakui","Meroitic","Meroitic_Cursive","Meroitic_Hieroglyphs","N_Ko","Osmanya","Tifinagh","Vai","West_Asian_Scripts","Anatolian_Hieroglyphs","Arabic","Arabic_Supplement","Arabic_Extended_A","Arabic_Extended_B","Arabic_Extended_C","Arabic_Presentation_Forms_A","Arabic_Presentation_Forms_B","Aramaic__Imperial","Avestan","Carian","Chorasmian","Cuneiform","Cuneiform_Numbers_and_Punctuation","Archaic_Cuneiform_Numbers","Early_Dynastic_Cuneiform","Old_Persian","Ugaritic","Elymaic","Hatran","Hebrew","Hebrew_Presentation_Forms","Lycian","Lydian","Mandaic","Nabataean","Old_North_Arabian","Old_South_Arabian","Pahlavi__Inscriptional","Pahlavi__Psalter","Palmyrene","Parthian__Inscriptional","Phoenician","Samaritan","Sidetic","Syriac","Syriac_Supplement","Yezidi","Central_Asian_Scripts","Manichaean","Marchen","Mongolian","Mongolian_Supplement","Old_Sogdian","Old_Turkic","Old_Uyghur","Phags_Pa","Sogdian","Soyombo","Tibetan","Zanabazar_Square","South_Asian_Scripts","Ahom","Bengali_and_Assamese","Bengali_Supplement","Bhaiksuki","Brahmi","Chakma","Devanagari","Devanagari_Extended","Devanagari_Extended_A","Dives_Akuru","Dogra","Grantha","Gujarati","Gunjala_Gondi","Gurmukhi","Gurung_Khema","Kaithi","Kannada","Kharoshthi","Khojki","Kirat_Rai","Khudawadi","Lepcha","Limbu","Mahajani","Malayalam","Masaram_Gondi","Meetei_Mayek","Meetei_Mayek_Extensions","Modi","Mro","Multani","Nag_Mundari","Nandinagari","Newa","Ol_Chiki","Ol_Onal","Oriya","Saurashtra","Sharada","Sharada_Supplement","Siddham","Sinhala","Sinhala_Archaic_Numbers","Sora_Sompeng","Sunuwar","Syloti_Nagri","Takri","Tamil","Tamil_Supplement","Telugu","Thaana","Tirhuta","Tolong_Siki","Toto","Tulu_Tigalari","Vedic_Extensions","Wancho","Warang_Citi","Southeast_Asian_Scripts","Cham","Hanifi_Rohingya","Kayah_Li","Khmer","Khmer_Symbols","Lao","Myanmar","Myanmar_Extended_A","Myanmar_Extended_B","Myanmar_Extended_C","New_Tai_Lue","Nyiakeng_Puachue_Hmong","Pahawh_Hmong","Pau_Cin_Hau","Tai_Le","Tai_Tham","Tai_Viet","Tai_Yo","Tangsa","Thai","Indonesian___Philippine_Scripts","Balinese","Batak","Buginese","Buhid","Hanunoo","Javanese","Kawi","Makasar","Rejang","Sundanese","Sundanese_Supplement","Tagalog","Tagbanwa","East_Asian_Scripts","Bopomofo","Bopomofo_Extended","CJK_Unified_Ideographs__Han_","CJK_Extension_A","CJK_Extension_B","CJK_Extension_C","CJK_Extension_D","CJK_Extension_E","CJK_Extension_F","CJK_Extension_G","CJK_Extension_H","CJK_Extension_I","CJK_Extension_J","Full_Radical_Stroke_Index__PDF__35MB_","Full_Radical_Stroke_Index__txt_","_see_also_Unihan_Database_Lookup_","CJK_Compatibility_Ideographs","CJK_Compatibility_Ideographs_Supplement","CJK_Radicals___Kangxi_Radicals","CJK_Radicals_Supplement","CJK_Strokes","Ideographic_Description_Characters","Hangul_Jamo","Hangul_Jamo_Extended_A","Hangul_Jamo_Extended_B","Hangul_Compatibility_Jamo","Halfwidth_Jamo","Hangul_Syllables","Hiragana","Jurchen","Jurchen_Radicals","Kana_Extended_A","Kana_Extended_B","Kana_Supplement","Small_Kana_Extension","Kanbun","Katakana","Katakana_Phonetic_Extensions","Halfwidth_Katakana","Khitan_Small_Script","Lisu","Lisu_Supplement","Miao","Nushu","Small_Seal","Tangut","Tangut_Components","Tangut_Supplement","Tangut_Components_Supplement","Yi","Yi_Syllables","Yi_Radicals","American_Scripts","Cherokee","Cherokee_Supplement","Deseret","Osage","Unified_Canadian_Aboriginal_Syllabics","UCAS_Extended","UCAS_Extended_A","Notational_Systems","Braille_Patterns","Musical_Symbols","Musical_Symbols_Supplement","Ancient_Greek_Musical_Notation","Byzantine_Musical_Symbols","Znamenny_Musical_Notation","Duployan","Shorthand_Format_Controls","Sutton_SignWriting","Punctuation","General_Punctuation","ASCII_Punctuation","Latin_1_Punctuation","Supplemental_Punctuation","CJK_Symbols_and_Punctuation","Ideographic_Symbols_and_Punctuation","CJK_Compatibility_Forms","Halfwidth_and_Fullwidth_Forms","Small_Form_Variants","Vertical_Forms","Alphanumeric_Symbols","Letterlike_Symbols","Roman_Symbols","Mathematical_Alphanumeric_Symbols","Arabic_Mathematical_Alphabetic_Symbols","Enclosed_Alphanumerics","Enclosed_Alphanumeric_Supplement","Enclosed_CJK_Letters_and_Months","Enclosed_Ideographic_Supplement","CJK_Compatibility","Additional_Squared_Symbols","Technical_Symbols","APL_symbols","Control_Pictures","Miscellaneous_Technical","Optical_Character_Recognition__OCR_","Numbers___Digits","_see_also_specific_scripts_","ASCII_Digits","Fullwidth_ASCII_Digits","Common_Indic_Number_Forms","Coptic_Epact_Numbers","Counting_Rod_Numerals","Cuneiform_Numbers_and_Punctuation","Archaic_Cuneiform_Numbers","Indic_Siyaq_Numbers","Kaktovik_Numerals","Mayan_Numerals","Number_Forms","Ottoman_Siyaq_Numbers","Rumi_Numeral_Symbols","Sinhala_Archaic_Numbers","Super_and_Subscripts","Mathematical_Symbols","Arrows","Supplemental_Arrows_A","Supplemental_Arrows_B","Supplemental_Arrows_C","Additional_Arrows","Miscellaneous_Symbols_and_Arrows","Miscellaneous_Symbols_and_Arrows_Extended","Mathematical_Alphanumeric_Symbols","Arabic_Mathematical_Alphabetic_Symbols","Letterlike_Symbols","Mathematical_Operators","Basic_operators__Plus__Factorial__Division__Multiplication","Supplemental_Mathematical_Operators","Miscellaneous_Mathematical_Symbols_A","Miscellaneous_Mathematical_Symbols_B","Floors_and_Ceilings","Invisible_Operators","Geometric_Shapes","Additional_Shapes","Box_Drawing","Block_Elements","Geometric_Shapes_Extended","Emoji___Pictographs","Dingbats","Ornamental_Dingbats","Emoticons","Miscellaneous_Symbols","Miscellaneous_Symbols_And_Pictographs","Supplemental_Symbols_and_Pictographs","Symbols_and_Pictographs_Extended_A","Transport_and_Map_Symbols","Other_Symbols","Alchemical_Symbols","Ancient_Symbols","Currency_Symbols","_see_also_specific_scripts_","Dollar_Sign__Euro_Sign","Yen__Pound_and_Cent","Fullwidth_Currency_Symbols","Rial_Sign","Game_Symbols","Chess__Checkers_Draughts","Chess_Symbols","Domino_Tiles","Japanese_Chess","Mahjong_Tiles","Playing_Cards","Card_suits","Miscellaneous_Symbols_and_Arrows","Miscellaneous_Symbols_Supplement","Miscellaneous_Symbols_and_Arrows_Extended","Symbols_for_Legacy_Computing","Symbols_for_Legacy_Computing_Supplement","Yijing_Symbols","Yijing_Mono___Di__and_Trigrams","Yijing_Hexagram_Symbols","Tai_Xuan_Jing_Symbols","Specials","Controls__tC0__tC1","Layout_Controls","Invisible_Operators","Specials","Tags","Variation_Selectors","Variation_Selectors_Supplement","Private_Use","Private_Use_Area","Supplementary_Private_Use_Area_A","Supplementary_Private_Use_Area_B","Surrogates","High_Surrogates","Low_Surrogates","Noncharacters_in_Charts","Noncharacters_in_blocks","Range_in_Arabic_Presentation_Forms_A","Range_in_Specials","Noncharacters_at_end_of____","BMP__Plane_1__Plane_2__Plane_3__Plane_4__Plane_5__Plane_6__Plane_7__Plane_8__Plane_9__Plane_10__Plane_11__Plane_12__Plane_13__Plane_14__Plane_15__Plane_16"]
5
5
  }
@@ -1,7 +1,13 @@
1
- // Todo: We might consider auto-building these fields in another file and/or
2
- // merging with `unicodeFieldInfo.js`.
1
+ // The known, stable column order historically used to build
2
+ // `download/unihan/unihan.json`. `parseUnihanFromTextFileStrings` below
3
+ // auto-appends any newly encountered field (e.g., from a Unihan standard
4
+ // update) after this base order, keeping existing field positions stable
5
+ // across re-downloads while never silently dropping new data. The
6
+ // resulting order is returned so callers (see `tools/unihan-import.js`)
7
+ // can persist it for `browser_action/unicodecharref.js`'s display code,
8
+ // which must stay in sync since it reads values by position.
3
9
  /* eslint-disable @stylistic/max-len -- Long */
4
- const fields = ['code_pt', 'kAccountingNumeric', 'kAlternateTotalStrokes', 'kBigFive', 'kCCCII', 'kCNS1986', 'kCNS1992', 'kCangjie', 'kCantonese',
10
+ const baseFields = ['code_pt', 'kAccountingNumeric', 'kAlternateTotalStrokes', 'kBigFive', 'kCCCII', 'kCNS1986', 'kCNS1992', 'kCangjie', 'kCantonese',
5
11
  'kCheungBauer', 'kCheungBauerIndex', 'kCihaiT', 'kCompatibilityVariant', 'kCowles', 'kDaeJaweon',
6
12
  'kDefinition', 'kEACC', 'kFenn', 'kFennIndex', 'kFourCornerCode', 'kFrequency', 'kGB0', 'kGB1', 'kGB3',
7
13
  'kGB5', 'kGB7', 'kGB8', 'kGSR', 'kGradeLevel', 'kHDZRadBreak', 'kHKGlyph', 'kHKSCS', 'kHanYu', 'kHangul',
@@ -14,43 +20,56 @@ const fields = ['code_pt', 'kAccountingNumeric', 'kAlternateTotalStrokes', 'kBig
14
20
  'kRSKorean', 'kRSUnicode', 'kSBGY', 'kSemanticVariant', 'kSimplifiedVariant', 'kSpecializedSemanticVariant',
15
21
  'kTaiwanTelegraph', 'kTang', 'kTotalStrokes', 'kTraditionalVariant', 'kVietnamese', 'kXHC1983', 'kXerox', 'kZVariant',
16
22
  'kUnihanCore2020', 'kIRG_UKSource', 'kIRG_SSource', 'kTGH', 'kKoreanName', 'kJa', 'kJoyoKanji', 'kKoreanEducationHanja',
17
- 'kJinmeiyoKanji', 'kTGHZ2013', 'kSpoofingVariant', 'kStrange'];
23
+ 'kJinmeiyoKanji', 'kTGHZ2013', 'kSpoofingVariant', 'kStrange',
24
+ 'kSMSZD2003Index', 'kMojiJoho', 'kVietnameseNumeric', 'kZhuangNumeric', 'kTayNumeric',
25
+ 'kJapanese', 'kFanqie', 'kSMSZD2003Readings', 'kZhuang', 'kJapaneseOldVariant', 'kJapaneseNewVariant'];
18
26
  /* eslint-enable @stylistic/max-len -- Long */
19
27
 
20
28
  /**
21
- * @param {string[]} scriptFileAsStrings
22
- * @returns {Object<string,string[]>}
23
- */
29
+ * @param {string[]} scriptFileAsStrings
30
+ * @returns {{rows: string[][], fields: string[]}} `fields` includes the
31
+ * leading `code_pt` entry; each `rows[n][0]` is the code point.
32
+ */
24
33
  function parseUnihanFromTextFileStrings (scriptFileAsStrings) {
25
34
  const scriptFileAsStr = scriptFileAsStrings.join('');
26
- const notPresent = {};
35
+ const lineRegex = /^U\+(?<cdpt>[\da-fA-F]{4,6})\t(?<col>\w+?)\t(?<value>.*)$/gvm;
36
+
37
+ // Pass 1: discover the full field set before populating any rows, so
38
+ // every row ends up uniformly sized regardless of when a given field
39
+ // is first encountered.
40
+ const knownFields = new Set(baseFields);
41
+ const fields = [...baseFields];
27
42
  let line;
43
+ while ((line = lineRegex.exec(scriptFileAsStr)) !== null) {
44
+ const {col} = /** @type {{col: string}} */ (line.groups);
45
+ if (!knownFields.has(col)) {
46
+ knownFields.add(col);
47
+ fields.push(col);
48
+ }
49
+ }
50
+ const fieldPositions = new Map(fields.map((field, idx) => [field, idx]));
51
+
52
+ // Pass 2: populate rows now that `fields` (and thus each row's length)
53
+ // is final.
54
+ /** @type {Record<string, string[]>} */
28
55
  const obj = {};
29
- const lineRegex = /^U\+(?<cdpt>[\da-fA-F]{4,6})\t(?<col>\w+?)\t(?<value>.*)$/gum;
30
- while ((line = (lineRegex).exec(scriptFileAsStr)) !== null) {
31
- const {cdpt, col, value} = line.groups;
32
- if (!obj[cdpt]) {
56
+ lineRegex.lastIndex = 0;
57
+ while ((line = lineRegex.exec(scriptFileAsStr)) !== null) {
58
+ // eslint-disable-next-line @stylistic/max-len -- Long
59
+ const {cdpt, col, value} = /** @type {{cdpt: string, col: string, value: string}} */ (
60
+ line.groups
61
+ );
62
+ if (!Object.hasOwn(obj, cdpt)) {
33
63
  obj[cdpt] = [];
34
64
  fields.forEach(function (val, idx) {
35
65
  obj[cdpt][idx] = '';
36
66
  });
37
67
  obj[cdpt][0] = cdpt;
38
68
  }
39
- const pos = fields.indexOf(col);
40
- if (pos === -1) {
41
- // Todo: Even if not inserting, should auto-add locales as in
42
- // parseUnicodeCharts.js
43
- if (!notPresent[col]) {
44
- // eslint-disable-next-line no-console -- CLI
45
- console.error(`Not present: ${col}\n`);
46
- notPresent[col] = 1;
47
- }
48
- continue;
49
- }
50
- obj[cdpt][pos] = value;
69
+ obj[cdpt][/** @type {number} */ (fieldPositions.get(col))] = value;
51
70
  }
52
71
 
53
- return Object.values(obj);
72
+ return {rows: Object.values(obj), fields};
54
73
  }
55
74
 
56
75
  export default parseUnihanFromTextFileStrings;