@kensio/pinyinjs 1.7.4 → 1.7.5

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 (695) hide show
  1. package/dist/accuracy/score-case.d.ts +23 -0
  2. package/dist/accuracy/score-case.d.ts.map +1 -0
  3. package/dist/accuracy/score-case.js +63 -0
  4. package/dist/accuracy/score-case.js.map +1 -0
  5. package/dist/accuracy/score.d.ts +1 -8
  6. package/dist/accuracy/score.d.ts.map +1 -1
  7. package/dist/accuracy/score.js +1 -55
  8. package/dist/accuracy/score.js.map +1 -1
  9. package/dist/cli/arguments.d.ts +4 -290
  10. package/dist/cli/arguments.d.ts.map +1 -1
  11. package/dist/cli/arguments.js +5 -357
  12. package/dist/cli/arguments.js.map +1 -1
  13. package/dist/cli/check-command.d.ts +9 -0
  14. package/dist/cli/check-command.d.ts.map +1 -0
  15. package/dist/cli/check-command.js +95 -0
  16. package/dist/cli/check-command.js.map +1 -0
  17. package/dist/cli/cli-input.d.ts +49 -0
  18. package/dist/cli/cli-input.d.ts.map +1 -0
  19. package/dist/cli/cli-input.js +31 -0
  20. package/dist/cli/cli-input.js.map +1 -0
  21. package/dist/cli/command.d.ts +97 -0
  22. package/dist/cli/command.d.ts.map +1 -0
  23. package/dist/cli/command.js +40 -0
  24. package/dist/cli/command.js.map +1 -0
  25. package/dist/cli/commands.d.ts +7 -110
  26. package/dist/cli/commands.d.ts.map +1 -1
  27. package/dist/cli/commands.js +14 -991
  28. package/dist/cli/commands.js.map +1 -1
  29. package/dist/cli/convert-command.d.ts +6 -0
  30. package/dist/cli/convert-command.d.ts.map +1 -0
  31. package/dist/cli/convert-command.js +52 -0
  32. package/dist/cli/convert-command.js.map +1 -0
  33. package/dist/cli/environment.d.ts +1 -1
  34. package/dist/cli/environment.d.ts.map +1 -1
  35. package/dist/cli/explain-command.d.ts +6 -0
  36. package/dist/cli/explain-command.d.ts.map +1 -0
  37. package/dist/cli/explain-command.js +40 -0
  38. package/dist/cli/explain-command.js.map +1 -0
  39. package/dist/cli/explain-syllable.d.ts +10 -0
  40. package/dist/cli/explain-syllable.d.ts.map +1 -0
  41. package/dist/cli/explain-syllable.js +70 -0
  42. package/dist/cli/explain-syllable.js.map +1 -0
  43. package/dist/cli/flag-help.d.ts +18 -0
  44. package/dist/cli/flag-help.d.ts.map +1 -0
  45. package/dist/cli/flag-help.js +78 -0
  46. package/dist/cli/flag-help.js.map +1 -0
  47. package/dist/cli/flag-lists.d.ts +49 -0
  48. package/dist/cli/flag-lists.d.ts.map +1 -0
  49. package/dist/cli/flag-lists.js +58 -0
  50. package/dist/cli/flag-lists.js.map +1 -0
  51. package/dist/cli/flag-values.d.ts +44 -0
  52. package/dist/cli/flag-values.d.ts.map +1 -0
  53. package/dist/cli/flag-values.js +56 -0
  54. package/dist/cli/flag-values.js.map +1 -0
  55. package/dist/cli/flags.d.ts +193 -0
  56. package/dist/cli/flags.d.ts.map +1 -0
  57. package/dist/cli/flags.js +133 -0
  58. package/dist/cli/flags.js.map +1 -0
  59. package/dist/cli/format-options.d.ts +29 -0
  60. package/dist/cli/format-options.d.ts.map +1 -0
  61. package/dist/cli/format-options.js +72 -0
  62. package/dist/cli/format-options.js.map +1 -0
  63. package/dist/cli/global-help.d.ts +23 -0
  64. package/dist/cli/global-help.d.ts.map +1 -0
  65. package/dist/cli/global-help.js +40 -0
  66. package/dist/cli/global-help.js.map +1 -0
  67. package/dist/cli/help.d.ts +1 -1
  68. package/dist/cli/help.d.ts.map +1 -1
  69. package/dist/cli/help.js +5 -99
  70. package/dist/cli/help.js.map +1 -1
  71. package/dist/cli/html-commands.d.ts +13 -0
  72. package/dist/cli/html-commands.d.ts.map +1 -0
  73. package/dist/cli/html-commands.js +49 -0
  74. package/dist/cli/html-commands.js.map +1 -0
  75. package/dist/cli/info-command.d.ts +7 -0
  76. package/dist/cli/info-command.d.ts.map +1 -0
  77. package/dist/cli/info-command.js +39 -0
  78. package/dist/cli/info-command.js.map +1 -0
  79. package/dist/cli/lookup-commands.d.ts +10 -0
  80. package/dist/cli/lookup-commands.d.ts.map +1 -0
  81. package/dist/cli/lookup-commands.js +101 -0
  82. package/dist/cli/lookup-commands.js.map +1 -0
  83. package/dist/cli/match-command.d.ts +11 -0
  84. package/dist/cli/match-command.d.ts.map +1 -0
  85. package/dist/cli/match-command.js +76 -0
  86. package/dist/cli/match-command.js.map +1 -0
  87. package/dist/cli/number-command.d.ts +12 -0
  88. package/dist/cli/number-command.d.ts.map +1 -0
  89. package/dist/cli/number-command.js +89 -0
  90. package/dist/cli/number-command.js.map +1 -0
  91. package/dist/cli/options.d.ts +30 -0
  92. package/dist/cli/options.d.ts.map +1 -0
  93. package/dist/cli/options.js +54 -0
  94. package/dist/cli/options.js.map +1 -0
  95. package/dist/cli/run-command.d.ts +24 -0
  96. package/dist/cli/run-command.d.ts.map +1 -0
  97. package/dist/cli/run-command.js +40 -0
  98. package/dist/cli/run-command.js.map +1 -0
  99. package/dist/cli/run.d.ts +4 -42
  100. package/dist/cli/run.d.ts.map +1 -1
  101. package/dist/cli/run.js +6 -61
  102. package/dist/cli/run.js.map +1 -1
  103. package/dist/cli/script-command.d.ts +10 -0
  104. package/dist/cli/script-command.d.ts.map +1 -0
  105. package/dist/cli/script-command.js +58 -0
  106. package/dist/cli/script-command.js.map +1 -0
  107. package/dist/cli/segment-command.d.ts +11 -0
  108. package/dist/cli/segment-command.d.ts.map +1 -0
  109. package/dist/cli/segment-command.js +53 -0
  110. package/dist/cli/segment-command.js.map +1 -0
  111. package/dist/cli/slug-command.d.ts +10 -0
  112. package/dist/cli/slug-command.d.ts.map +1 -0
  113. package/dist/cli/slug-command.js +28 -0
  114. package/dist/cli/slug-command.js.map +1 -0
  115. package/dist/cli/syllable-command.d.ts +14 -0
  116. package/dist/cli/syllable-command.d.ts.map +1 -0
  117. package/dist/cli/syllable-command.js +82 -0
  118. package/dist/cli/syllable-command.js.map +1 -0
  119. package/dist/cli/system-table.d.ts +12 -0
  120. package/dist/cli/system-table.d.ts.map +1 -0
  121. package/dist/cli/system-table.js +48 -0
  122. package/dist/cli/system-table.js.map +1 -0
  123. package/dist/cli/systems.d.ts +57 -0
  124. package/dist/cli/systems.d.ts.map +1 -0
  125. package/dist/cli/systems.js +27 -0
  126. package/dist/cli/systems.js.map +1 -0
  127. package/dist/cli/transcribe-command.d.ts +18 -0
  128. package/dist/cli/transcribe-command.d.ts.map +1 -0
  129. package/dist/cli/transcribe-command.js +86 -0
  130. package/dist/cli/transcribe-command.js.map +1 -0
  131. package/dist/cli/transcribe-reading.d.ts +15 -0
  132. package/dist/cli/transcribe-reading.d.ts.map +1 -0
  133. package/dist/cli/transcribe-reading.js +90 -0
  134. package/dist/cli/transcribe-reading.js.map +1 -0
  135. package/dist/cli/transcribe-rows.d.ts +26 -0
  136. package/dist/cli/transcribe-rows.d.ts.map +1 -0
  137. package/dist/cli/transcribe-rows.js +30 -0
  138. package/dist/cli/transcribe-rows.js.map +1 -0
  139. package/dist/cli/usage-error.d.ts +9 -0
  140. package/dist/cli/usage-error.d.ts.map +1 -0
  141. package/dist/cli/usage-error.js +9 -0
  142. package/dist/cli/usage-error.js.map +1 -0
  143. package/dist/decode/alternatives.d.ts +16 -0
  144. package/dist/decode/alternatives.d.ts.map +1 -0
  145. package/dist/decode/alternatives.js +31 -0
  146. package/dist/decode/alternatives.js.map +1 -0
  147. package/dist/decode/confidence.d.ts.map +1 -1
  148. package/dist/decode/confidence.js +3 -118
  149. package/dist/decode/confidence.js.map +1 -1
  150. package/dist/decode/convert-options.d.ts +116 -0
  151. package/dist/decode/convert-options.d.ts.map +1 -0
  152. package/dist/decode/convert-options.js +2 -0
  153. package/dist/decode/convert-options.js.map +1 -0
  154. package/dist/decode/convert-pipeline.d.ts +18 -0
  155. package/dist/decode/convert-pipeline.d.ts.map +1 -0
  156. package/dist/decode/convert-pipeline.js +66 -0
  157. package/dist/decode/convert-pipeline.js.map +1 -0
  158. package/dist/decode/convert.d.ts +9 -118
  159. package/dist/decode/convert.d.ts.map +1 -1
  160. package/dist/decode/convert.js +5 -453
  161. package/dist/decode/convert.js.map +1 -1
  162. package/dist/decode/decode.d.ts +2 -15
  163. package/dist/decode/decode.d.ts.map +1 -1
  164. package/dist/decode/decode.js +2 -121
  165. package/dist/decode/decode.js.map +1 -1
  166. package/dist/decode/decoders.d.ts +32 -0
  167. package/dist/decode/decoders.d.ts.map +1 -0
  168. package/dist/decode/decoders.js +29 -0
  169. package/dist/decode/decoders.js.map +1 -0
  170. package/dist/decode/edge-context.d.ts +38 -0
  171. package/dist/decode/edge-context.d.ts.map +1 -0
  172. package/dist/decode/edge-context.js +57 -0
  173. package/dist/decode/edge-context.js.map +1 -0
  174. package/dist/decode/hint-lattice.d.ts +45 -0
  175. package/dist/decode/hint-lattice.d.ts.map +1 -0
  176. package/dist/decode/hint-lattice.js +140 -0
  177. package/dist/decode/hint-lattice.js.map +1 -0
  178. package/dist/decode/hints.d.ts +2 -45
  179. package/dist/decode/hints.d.ts.map +1 -1
  180. package/dist/decode/hints.js +1 -139
  181. package/dist/decode/hints.js.map +1 -1
  182. package/dist/decode/jiao-rule.d.ts +58 -0
  183. package/dist/decode/jiao-rule.d.ts.map +1 -0
  184. package/dist/decode/jiao-rule.js +76 -0
  185. package/dist/decode/jiao-rule.js.map +1 -0
  186. package/dist/decode/lattice-costs.d.ts +55 -0
  187. package/dist/decode/lattice-costs.d.ts.map +1 -0
  188. package/dist/decode/lattice-costs.js +90 -0
  189. package/dist/decode/lattice-costs.js.map +1 -0
  190. package/dist/decode/lattice-edges.d.ts +29 -0
  191. package/dist/decode/lattice-edges.d.ts.map +1 -0
  192. package/dist/decode/lattice-edges.js +78 -0
  193. package/dist/decode/lattice-edges.js.map +1 -0
  194. package/dist/decode/lattice-slice.d.ts +37 -0
  195. package/dist/decode/lattice-slice.d.ts.map +1 -0
  196. package/dist/decode/lattice-slice.js +43 -0
  197. package/dist/decode/lattice-slice.js.map +1 -0
  198. package/dist/decode/lattice-types.d.ts +82 -0
  199. package/dist/decode/lattice-types.d.ts.map +1 -0
  200. package/dist/decode/lattice-types.js +44 -0
  201. package/dist/decode/lattice-types.js.map +1 -0
  202. package/dist/decode/lattice.d.ts +2 -59
  203. package/dist/decode/lattice.d.ts.map +1 -1
  204. package/dist/decode/lattice.js +2 -118
  205. package/dist/decode/lattice.js.map +1 -1
  206. package/dist/decode/number-pieces.d.ts +62 -0
  207. package/dist/decode/number-pieces.d.ts.map +1 -0
  208. package/dist/decode/number-pieces.js +106 -0
  209. package/dist/decode/number-pieces.js.map +1 -0
  210. package/dist/decode/numbers.d.ts +53 -0
  211. package/dist/decode/numbers.d.ts.map +1 -0
  212. package/dist/decode/numbers.js +69 -0
  213. package/dist/decode/numbers.js.map +1 -0
  214. package/dist/decode/pieces.d.ts +78 -0
  215. package/dist/decode/pieces.d.ts.map +1 -0
  216. package/dist/decode/pieces.js +136 -0
  217. package/dist/decode/pieces.js.map +1 -0
  218. package/dist/decode/polyphone-rules.d.ts +31 -0
  219. package/dist/decode/polyphone-rules.d.ts.map +1 -0
  220. package/dist/decode/polyphone-rules.js +159 -0
  221. package/dist/decode/polyphone-rules.js.map +1 -0
  222. package/dist/decode/reading-rules.d.ts +2 -97
  223. package/dist/decode/reading-rules.d.ts.map +1 -1
  224. package/dist/decode/reading-rules.js +4 -365
  225. package/dist/decode/reading-rules.js.map +1 -1
  226. package/dist/decode/rules.d.ts +1 -17
  227. package/dist/decode/rules.d.ts.map +1 -1
  228. package/dist/decode/rules.js +1 -43
  229. package/dist/decode/rules.js.map +1 -1
  230. package/dist/decode/run-lattice.d.ts +52 -0
  231. package/dist/decode/run-lattice.d.ts.map +1 -0
  232. package/dist/decode/run-lattice.js +91 -0
  233. package/dist/decode/run-lattice.js.map +1 -0
  234. package/dist/decode/sandhi-tones.d.ts +69 -0
  235. package/dist/decode/sandhi-tones.d.ts.map +1 -0
  236. package/dist/decode/sandhi-tones.js +88 -0
  237. package/dist/decode/sandhi-tones.js.map +1 -0
  238. package/dist/decode/sandhi.d.ts +1 -1
  239. package/dist/decode/sandhi.d.ts.map +1 -1
  240. package/dist/decode/sandhi.js +1 -81
  241. package/dist/decode/sandhi.js.map +1 -1
  242. package/dist/decode/script-types.d.ts +76 -0
  243. package/dist/decode/script-types.d.ts.map +1 -0
  244. package/dist/decode/script-types.js +35 -0
  245. package/dist/decode/script-types.js.map +1 -0
  246. package/dist/decode/script-words.d.ts +32 -0
  247. package/dist/decode/script-words.d.ts.map +1 -0
  248. package/dist/decode/script-words.js +77 -0
  249. package/dist/decode/script-words.js.map +1 -0
  250. package/dist/decode/script.d.ts +3 -73
  251. package/dist/decode/script.d.ts.map +1 -1
  252. package/dist/decode/script.js +3 -109
  253. package/dist/decode/script.js.map +1 -1
  254. package/dist/decode/tan-rule.d.ts +68 -0
  255. package/dist/decode/tan-rule.d.ts.map +1 -0
  256. package/dist/decode/tan-rule.js +131 -0
  257. package/dist/decode/tan-rule.js.map +1 -0
  258. package/dist/decode/write-run.d.ts +28 -0
  259. package/dist/decode/write-run.d.ts.map +1 -0
  260. package/dist/decode/write-run.js +77 -0
  261. package/dist/decode/write-run.js.map +1 -0
  262. package/dist/dictionary/artifact-claims.d.ts +25 -0
  263. package/dist/dictionary/artifact-claims.d.ts.map +1 -0
  264. package/dist/dictionary/artifact-claims.js +47 -0
  265. package/dist/dictionary/artifact-claims.js.map +1 -0
  266. package/dist/dictionary/artifact-format.d.ts +86 -0
  267. package/dist/dictionary/artifact-format.d.ts.map +1 -0
  268. package/dist/dictionary/artifact-format.js +91 -0
  269. package/dist/dictionary/artifact-format.js.map +1 -0
  270. package/dist/dictionary/artifact-read.d.ts +34 -0
  271. package/dist/dictionary/artifact-read.d.ts.map +1 -0
  272. package/dist/dictionary/artifact-read.js +114 -0
  273. package/dist/dictionary/artifact-read.js.map +1 -0
  274. package/dist/dictionary/artifact.d.ts +4 -63
  275. package/dist/dictionary/artifact.d.ts.map +1 -1
  276. package/dist/dictionary/artifact.js +12 -229
  277. package/dist/dictionary/artifact.js.map +1 -1
  278. package/dist/dictionary/assertions.d.ts +5 -57
  279. package/dist/dictionary/assertions.d.ts.map +1 -1
  280. package/dist/dictionary/assertions.js +4 -317
  281. package/dist/dictionary/assertions.js.map +1 -1
  282. package/dist/dictionary/build-assertions.d.ts +12 -0
  283. package/dist/dictionary/build-assertions.d.ts.map +1 -0
  284. package/dist/dictionary/build-assertions.js +13 -0
  285. package/dist/dictionary/build-assertions.js.map +1 -0
  286. package/dist/dictionary/built-dictionary.d.ts +46 -0
  287. package/dist/dictionary/built-dictionary.d.ts.map +1 -0
  288. package/dist/dictionary/built-dictionary.js +97 -0
  289. package/dist/dictionary/built-dictionary.js.map +1 -0
  290. package/dist/dictionary/cedict-senses.d.ts +80 -0
  291. package/dist/dictionary/cedict-senses.d.ts.map +1 -0
  292. package/dist/dictionary/cedict-senses.js +114 -0
  293. package/dist/dictionary/cedict-senses.js.map +1 -0
  294. package/dist/dictionary/character-defaults.d.ts +26 -0
  295. package/dist/dictionary/character-defaults.d.ts.map +1 -0
  296. package/dist/dictionary/character-defaults.js +67 -0
  297. package/dist/dictionary/character-defaults.js.map +1 -0
  298. package/dist/dictionary/character-readings.d.ts +10 -0
  299. package/dist/dictionary/character-readings.d.ts.map +1 -0
  300. package/dist/dictionary/character-readings.js +25 -0
  301. package/dist/dictionary/character-readings.js.map +1 -0
  302. package/dist/dictionary/dictionary-entry.d.ts +37 -0
  303. package/dist/dictionary/dictionary-entry.d.ts.map +1 -0
  304. package/dist/dictionary/dictionary-entry.js +41 -0
  305. package/dist/dictionary/dictionary-entry.js.map +1 -0
  306. package/dist/dictionary/dictionary-readings.d.ts +56 -0
  307. package/dist/dictionary/dictionary-readings.d.ts.map +1 -0
  308. package/dist/dictionary/dictionary-readings.js +93 -0
  309. package/dist/dictionary/dictionary-readings.js.map +1 -0
  310. package/dist/dictionary/dictionary.d.ts +6 -60
  311. package/dist/dictionary/dictionary.d.ts.map +1 -1
  312. package/dist/dictionary/dictionary.js +9 -169
  313. package/dist/dictionary/dictionary.js.map +1 -1
  314. package/dist/dictionary/entry-invariants.d.ts +3 -0
  315. package/dist/dictionary/entry-invariants.d.ts.map +1 -0
  316. package/dist/dictionary/entry-invariants.js +67 -0
  317. package/dist/dictionary/entry-invariants.js.map +1 -0
  318. package/dist/dictionary/entry-lines.d.ts +35 -0
  319. package/dist/dictionary/entry-lines.d.ts.map +1 -0
  320. package/dist/dictionary/entry-lines.js +70 -0
  321. package/dist/dictionary/entry-lines.js.map +1 -0
  322. package/dist/dictionary/erhua-repair.d.ts +26 -0
  323. package/dist/dictionary/erhua-repair.d.ts.map +1 -0
  324. package/dist/dictionary/erhua-repair.js +49 -0
  325. package/dist/dictionary/erhua-repair.js.map +1 -0
  326. package/dist/dictionary/frequency-tones.d.ts +74 -0
  327. package/dist/dictionary/frequency-tones.d.ts.map +1 -0
  328. package/dist/dictionary/frequency-tones.js +128 -0
  329. package/dist/dictionary/frequency-tones.js.map +1 -0
  330. package/dist/dictionary/inventory-invariants.d.ts +3 -0
  331. package/dist/dictionary/inventory-invariants.d.ts.map +1 -0
  332. package/dist/dictionary/inventory-invariants.js +54 -0
  333. package/dist/dictionary/inventory-invariants.js.map +1 -0
  334. package/dist/dictionary/locale-candidates.d.ts +40 -0
  335. package/dist/dictionary/locale-candidates.d.ts.map +1 -0
  336. package/dist/dictionary/locale-candidates.js +77 -0
  337. package/dist/dictionary/locale-candidates.js.map +1 -0
  338. package/dist/dictionary/locale-segments.d.ts +47 -0
  339. package/dist/dictionary/locale-segments.d.ts.map +1 -0
  340. package/dist/dictionary/locale-segments.js +141 -0
  341. package/dist/dictionary/locale-segments.js.map +1 -0
  342. package/dist/dictionary/locale.d.ts +1 -21
  343. package/dist/dictionary/locale.d.ts.map +1 -1
  344. package/dist/dictionary/locale.js +9 -198
  345. package/dist/dictionary/locale.js.map +1 -1
  346. package/dist/dictionary/merge-types.d.ts +121 -0
  347. package/dist/dictionary/merge-types.d.ts.map +1 -0
  348. package/dist/dictionary/merge-types.js +35 -0
  349. package/dist/dictionary/merge-types.js.map +1 -0
  350. package/dist/dictionary/merge-word.d.ts +7 -0
  351. package/dist/dictionary/merge-word.d.ts.map +1 -0
  352. package/dist/dictionary/merge-word.js +91 -0
  353. package/dist/dictionary/merge-word.js.map +1 -0
  354. package/dist/dictionary/merge.d.ts +5 -62
  355. package/dist/dictionary/merge.d.ts.map +1 -1
  356. package/dist/dictionary/merge.js +30 -713
  357. package/dist/dictionary/merge.js.map +1 -1
  358. package/dist/dictionary/proper-noun.d.ts +28 -0
  359. package/dist/dictionary/proper-noun.d.ts.map +1 -0
  360. package/dist/dictionary/proper-noun.js +43 -0
  361. package/dist/dictionary/proper-noun.js.map +1 -0
  362. package/dist/dictionary/reading-agreement.d.ts +71 -0
  363. package/dist/dictionary/reading-agreement.d.ts.map +1 -0
  364. package/dist/dictionary/reading-agreement.js +156 -0
  365. package/dist/dictionary/reading-agreement.js.map +1 -0
  366. package/dist/dictionary/script-conversion.d.ts +28 -0
  367. package/dist/dictionary/script-conversion.d.ts.map +1 -0
  368. package/dist/dictionary/script-conversion.js +58 -0
  369. package/dist/dictionary/script-conversion.js.map +1 -0
  370. package/dist/dictionary/script-pairings.d.ts +74 -0
  371. package/dist/dictionary/script-pairings.d.ts.map +1 -0
  372. package/dist/dictionary/script-pairings.js +120 -0
  373. package/dist/dictionary/script-pairings.js.map +1 -0
  374. package/dist/dictionary/script-tables.d.ts.map +1 -1
  375. package/dist/dictionary/script-tables.js +2 -165
  376. package/dist/dictionary/script-tables.js.map +1 -1
  377. package/dist/dictionary/taiwan-reading.d.ts +8 -0
  378. package/dist/dictionary/taiwan-reading.d.ts.map +1 -0
  379. package/dist/dictionary/taiwan-reading.js +38 -0
  380. package/dist/dictionary/taiwan-reading.js.map +1 -0
  381. package/dist/dictionary/tone-invariants.d.ts +3 -0
  382. package/dist/dictionary/tone-invariants.d.ts.map +1 -0
  383. package/dist/dictionary/tone-invariants.js +64 -0
  384. package/dist/dictionary/tone-invariants.js.map +1 -0
  385. package/dist/dictionary/traditional-form.d.ts +21 -0
  386. package/dist/dictionary/traditional-form.d.ts.map +1 -0
  387. package/dist/dictionary/traditional-form.js +59 -0
  388. package/dist/dictionary/traditional-form.js.map +1 -0
  389. package/dist/dictionary/traditional-ranking.d.ts +22 -0
  390. package/dist/dictionary/traditional-ranking.d.ts.map +1 -0
  391. package/dist/dictionary/traditional-ranking.js +74 -0
  392. package/dist/dictionary/traditional-ranking.js.map +1 -0
  393. package/dist/dictionary/traditional-table.d.ts +51 -0
  394. package/dist/dictionary/traditional-table.d.ts.map +1 -0
  395. package/dist/dictionary/traditional-table.js +98 -0
  396. package/dist/dictionary/traditional-table.js.map +1 -0
  397. package/dist/dictionary/traditional.d.ts +3 -56
  398. package/dist/dictionary/traditional.d.ts.map +1 -1
  399. package/dist/dictionary/traditional.js +3 -186
  400. package/dist/dictionary/traditional.js.map +1 -1
  401. package/dist/dictionary/variant-counts.d.ts +39 -0
  402. package/dist/dictionary/variant-counts.d.ts.map +1 -0
  403. package/dist/dictionary/variant-counts.js +38 -0
  404. package/dist/dictionary/variant-counts.js.map +1 -0
  405. package/dist/dictionary/word-reading.d.ts +26 -0
  406. package/dist/dictionary/word-reading.d.ts.map +1 -0
  407. package/dist/dictionary/word-reading.js +76 -0
  408. package/dist/dictionary/word-reading.js.map +1 -0
  409. package/dist/dictionary/word-readings.d.ts +15 -0
  410. package/dist/dictionary/word-readings.d.ts.map +1 -0
  411. package/dist/dictionary/word-readings.js +38 -0
  412. package/dist/dictionary/word-readings.js.map +1 -0
  413. package/dist/format/annotate.d.ts +90 -0
  414. package/dist/format/annotate.d.ts.map +1 -0
  415. package/dist/format/annotate.js +168 -0
  416. package/dist/format/annotate.js.map +1 -0
  417. package/dist/format/html.d.ts +15 -46
  418. package/dist/format/html.d.ts.map +1 -1
  419. package/dist/format/html.js +3 -162
  420. package/dist/format/html.js.map +1 -1
  421. package/dist/format/slug-hash.d.ts +51 -0
  422. package/dist/format/slug-hash.d.ts.map +1 -0
  423. package/dist/format/slug-hash.js +74 -0
  424. package/dist/format/slug-hash.js.map +1 -0
  425. package/dist/format/slug-options.d.ts +98 -0
  426. package/dist/format/slug-options.d.ts.map +1 -0
  427. package/dist/format/slug-options.js +2 -0
  428. package/dist/format/slug-options.js.map +1 -0
  429. package/dist/format/slug-words.d.ts +27 -0
  430. package/dist/format/slug-words.d.ts.map +1 -0
  431. package/dist/format/slug-words.js +0 -0
  432. package/dist/format/slug-words.js.map +1 -0
  433. package/dist/format/slug.d.ts +3 -128
  434. package/dist/format/slug.d.ts.map +1 -1
  435. package/dist/format/slug.js +0 -0
  436. package/dist/format/slug.js.map +1 -1
  437. package/dist/grade/check-readings.d.ts +41 -0
  438. package/dist/grade/check-readings.d.ts.map +1 -0
  439. package/dist/grade/check-readings.js +36 -0
  440. package/dist/grade/check-readings.js.map +1 -0
  441. package/dist/grade/check.d.ts +4 -4
  442. package/dist/grade/check.d.ts.map +1 -1
  443. package/dist/grade/check.js +5 -270
  444. package/dist/grade/check.js.map +1 -1
  445. package/dist/grade/pair-syllables.d.ts +48 -0
  446. package/dist/grade/pair-syllables.d.ts.map +1 -0
  447. package/dist/grade/pair-syllables.js +71 -0
  448. package/dist/grade/pair-syllables.js.map +1 -0
  449. package/dist/grade/reading-syllables.d.ts +62 -0
  450. package/dist/grade/reading-syllables.d.ts.map +1 -0
  451. package/dist/grade/reading-syllables.js +58 -0
  452. package/dist/grade/reading-syllables.js.map +1 -0
  453. package/dist/grade/reading-tolerance.d.ts +72 -0
  454. package/dist/grade/reading-tolerance.d.ts.map +1 -0
  455. package/dist/grade/reading-tolerance.js +107 -0
  456. package/dist/grade/reading-tolerance.js.map +1 -0
  457. package/dist/grade/typed-reading.d.ts +28 -0
  458. package/dist/grade/typed-reading.d.ts.map +1 -0
  459. package/dist/grade/typed-reading.js +36 -0
  460. package/dist/grade/typed-reading.js.map +1 -0
  461. package/dist/numerals/numeral-parse.d.ts +32 -0
  462. package/dist/numerals/numeral-parse.d.ts.map +1 -0
  463. package/dist/numerals/numeral-parse.js +44 -0
  464. package/dist/numerals/numeral-parse.js.map +1 -0
  465. package/dist/numerals/numeral-shapes.d.ts +89 -0
  466. package/dist/numerals/numeral-shapes.d.ts.map +1 -0
  467. package/dist/numerals/numeral-shapes.js +99 -0
  468. package/dist/numerals/numeral-shapes.js.map +1 -0
  469. package/dist/numerals/numerals.d.ts.map +1 -1
  470. package/dist/numerals/numerals.js +2 -36
  471. package/dist/numerals/numerals.js.map +1 -1
  472. package/dist/numerals/read-numeral.d.ts +76 -0
  473. package/dist/numerals/read-numeral.d.ts.map +1 -0
  474. package/dist/numerals/read-numeral.js +88 -0
  475. package/dist/numerals/read-numeral.js.map +1 -0
  476. package/dist/numerals/text.d.ts +3 -37
  477. package/dist/numerals/text.d.ts.map +1 -1
  478. package/dist/numerals/text.js +3 -254
  479. package/dist/numerals/text.js.map +1 -1
  480. package/dist/numerals/time.d.ts +34 -0
  481. package/dist/numerals/time.d.ts.map +1 -0
  482. package/dist/numerals/time.js +93 -0
  483. package/dist/numerals/time.js.map +1 -0
  484. package/dist/orthography/address-grouping.d.ts +34 -0
  485. package/dist/orthography/address-grouping.d.ts.map +1 -0
  486. package/dist/orthography/address-grouping.js +52 -0
  487. package/dist/orthography/address-grouping.js.map +1 -0
  488. package/dist/orthography/grouping.d.ts +3 -87
  489. package/dist/orthography/grouping.d.ts.map +1 -1
  490. package/dist/orthography/grouping.js +4 -270
  491. package/dist/orthography/grouping.js.map +1 -1
  492. package/dist/orthography/place-grouping.d.ts +39 -0
  493. package/dist/orthography/place-grouping.d.ts.map +1 -0
  494. package/dist/orthography/place-grouping.js +83 -0
  495. package/dist/orthography/place-grouping.js.map +1 -0
  496. package/dist/orthography/word-grouping.d.ts +48 -0
  497. package/dist/orthography/word-grouping.d.ts.map +1 -0
  498. package/dist/orthography/word-grouping.js +147 -0
  499. package/dist/orthography/word-grouping.js.map +1 -0
  500. package/dist/script/conversion-format.d.ts +22 -0
  501. package/dist/script/conversion-format.d.ts.map +1 -0
  502. package/dist/script/conversion-format.js +22 -0
  503. package/dist/script/conversion-format.js.map +1 -0
  504. package/dist/script/conversion-read.d.ts +9 -0
  505. package/dist/script/conversion-read.d.ts.map +1 -0
  506. package/dist/script/conversion-read.js +69 -0
  507. package/dist/script/conversion-read.js.map +1 -0
  508. package/dist/script/conversion-write.d.ts +14 -0
  509. package/dist/script/conversion-write.d.ts.map +1 -0
  510. package/dist/script/conversion-write.js +34 -0
  511. package/dist/script/conversion-write.js.map +1 -0
  512. package/dist/script/conversion.d.ts +10 -16
  513. package/dist/script/conversion.d.ts.map +1 -1
  514. package/dist/script/conversion.js +2 -115
  515. package/dist/script/conversion.js.map +1 -1
  516. package/dist/search/candidate-narrowing.d.ts +56 -0
  517. package/dist/search/candidate-narrowing.d.ts.map +1 -0
  518. package/dist/search/candidate-narrowing.js +55 -0
  519. package/dist/search/candidate-narrowing.js.map +1 -0
  520. package/dist/search/candidate-query.d.ts +25 -0
  521. package/dist/search/candidate-query.d.ts.map +1 -0
  522. package/dist/search/candidate-query.js +28 -0
  523. package/dist/search/candidate-query.js.map +1 -0
  524. package/dist/search/candidate-writings.d.ts +24 -0
  525. package/dist/search/candidate-writings.d.ts.map +1 -0
  526. package/dist/search/candidate-writings.js +114 -0
  527. package/dist/search/candidate-writings.js.map +1 -0
  528. package/dist/search/candidates.d.ts +7 -41
  529. package/dist/search/candidates.d.ts.map +1 -1
  530. package/dist/search/candidates.js +10 -164
  531. package/dist/search/candidates.js.map +1 -1
  532. package/dist/search/match-chunks.d.ts +19 -0
  533. package/dist/search/match-chunks.d.ts.map +1 -0
  534. package/dist/search/match-chunks.js +30 -0
  535. package/dist/search/match-chunks.js.map +1 -0
  536. package/dist/search/match-ranking.d.ts +39 -0
  537. package/dist/search/match-ranking.d.ts.map +1 -0
  538. package/dist/search/match-ranking.js +51 -0
  539. package/dist/search/match-ranking.js.map +1 -0
  540. package/dist/search/match-readings.d.ts +43 -0
  541. package/dist/search/match-readings.d.ts.map +1 -0
  542. package/dist/search/match-readings.js +83 -0
  543. package/dist/search/match-readings.js.map +1 -0
  544. package/dist/search/match-scoring.d.ts +146 -0
  545. package/dist/search/match-scoring.d.ts.map +1 -0
  546. package/dist/search/match-scoring.js +114 -0
  547. package/dist/search/match-scoring.js.map +1 -0
  548. package/dist/search/match-search.d.ts +28 -0
  549. package/dist/search/match-search.d.ts.map +1 -0
  550. package/dist/search/match-search.js +128 -0
  551. package/dist/search/match-search.js.map +1 -0
  552. package/dist/search/match.d.ts +5 -36
  553. package/dist/search/match.d.ts.map +1 -1
  554. package/dist/search/match.js +2 -379
  555. package/dist/search/match.js.map +1 -1
  556. package/dist/search/reverse-index-build.d.ts +30 -0
  557. package/dist/search/reverse-index-build.d.ts.map +1 -0
  558. package/dist/search/reverse-index-build.js +72 -0
  559. package/dist/search/reverse-index-build.js.map +1 -0
  560. package/dist/search/reverse-index-format.d.ts +60 -0
  561. package/dist/search/reverse-index-format.d.ts.map +1 -0
  562. package/dist/search/reverse-index-format.js +54 -0
  563. package/dist/search/reverse-index-format.js.map +1 -0
  564. package/dist/search/reverse-index-groups.d.ts +37 -0
  565. package/dist/search/reverse-index-groups.d.ts.map +1 -0
  566. package/dist/search/reverse-index-groups.js +71 -0
  567. package/dist/search/reverse-index-groups.js.map +1 -0
  568. package/dist/search/reverse-index-passes.d.ts +78 -0
  569. package/dist/search/reverse-index-passes.d.ts.map +1 -0
  570. package/dist/search/reverse-index-passes.js +59 -0
  571. package/dist/search/reverse-index-passes.js.map +1 -0
  572. package/dist/search/reverse-index-state.d.ts +36 -0
  573. package/dist/search/reverse-index-state.d.ts.map +1 -0
  574. package/dist/search/reverse-index-state.js +95 -0
  575. package/dist/search/reverse-index-state.js.map +1 -0
  576. package/dist/search/reverse-index.d.ts +8 -67
  577. package/dist/search/reverse-index.d.ts.map +1 -1
  578. package/dist/search/reverse-index.js +4 -255
  579. package/dist/search/reverse-index.js.map +1 -1
  580. package/dist/sources/unihan-readings.d.ts +58 -0
  581. package/dist/sources/unihan-readings.d.ts.map +1 -0
  582. package/dist/sources/unihan-readings.js +95 -0
  583. package/dist/sources/unihan-readings.js.map +1 -0
  584. package/dist/sources/unihan.d.ts +6 -9
  585. package/dist/sources/unihan.d.ts.map +1 -1
  586. package/dist/sources/unihan.js +2 -85
  587. package/dist/sources/unihan.js.map +1 -1
  588. package/dist/syllable/final-tables.d.ts +23 -0
  589. package/dist/syllable/final-tables.d.ts.map +1 -0
  590. package/dist/syllable/final-tables.js +50 -0
  591. package/dist/syllable/final-tables.js.map +1 -0
  592. package/dist/syllable/inventory.d.ts +8 -42
  593. package/dist/syllable/inventory.d.ts.map +1 -1
  594. package/dist/syllable/inventory.js +9 -918
  595. package/dist/syllable/inventory.js.map +1 -1
  596. package/dist/syllable/spellings.d.ts +40 -0
  597. package/dist/syllable/spellings.d.ts.map +1 -0
  598. package/dist/syllable/spellings.js +469 -0
  599. package/dist/syllable/spellings.js.map +1 -0
  600. package/dist/syllable/syllable-parts.d.ts +31 -0
  601. package/dist/syllable/syllable-parts.d.ts.map +1 -0
  602. package/dist/syllable/syllable-parts.js +105 -0
  603. package/dist/syllable/syllable-parts.js.map +1 -0
  604. package/dist/syllable/syllable.d.ts +1 -14
  605. package/dist/syllable/syllable.d.ts.map +1 -1
  606. package/dist/syllable/syllable.js +3 -144
  607. package/dist/syllable/syllable.js.map +1 -1
  608. package/dist/syllable/written-tones.d.ts +6 -0
  609. package/dist/syllable/written-tones.d.ts.map +1 -0
  610. package/dist/syllable/written-tones.js +453 -0
  611. package/dist/syllable/written-tones.js.map +1 -0
  612. package/dist/transcription/bopomofo-parse.d.ts +42 -0
  613. package/dist/transcription/bopomofo-parse.d.ts.map +1 -0
  614. package/dist/transcription/bopomofo-parse.js +92 -0
  615. package/dist/transcription/bopomofo-parse.js.map +1 -0
  616. package/dist/transcription/bopomofo-reverse.d.ts +31 -0
  617. package/dist/transcription/bopomofo-reverse.d.ts.map +1 -0
  618. package/dist/transcription/bopomofo-reverse.js +48 -0
  619. package/dist/transcription/bopomofo-reverse.js.map +1 -0
  620. package/dist/transcription/bopomofo-symbols.d.ts +36 -0
  621. package/dist/transcription/bopomofo-symbols.d.ts.map +1 -0
  622. package/dist/transcription/bopomofo-symbols.js +41 -0
  623. package/dist/transcription/bopomofo-symbols.js.map +1 -0
  624. package/dist/transcription/bopomofo-tables.d.ts +87 -0
  625. package/dist/transcription/bopomofo-tables.d.ts.map +1 -0
  626. package/dist/transcription/bopomofo-tables.js +180 -0
  627. package/dist/transcription/bopomofo-tables.js.map +1 -0
  628. package/dist/transcription/bopomofo.d.ts +14 -32
  629. package/dist/transcription/bopomofo.d.ts.map +1 -1
  630. package/dist/transcription/bopomofo.js +5 -343
  631. package/dist/transcription/bopomofo.js.map +1 -1
  632. package/dist/transcription/gwoyeu-first-second.d.ts +36 -0
  633. package/dist/transcription/gwoyeu-first-second.d.ts.map +1 -0
  634. package/dist/transcription/gwoyeu-first-second.js +75 -0
  635. package/dist/transcription/gwoyeu-first-second.js.map +1 -0
  636. package/dist/transcription/gwoyeu-spelling.d.ts +38 -0
  637. package/dist/transcription/gwoyeu-spelling.d.ts.map +1 -0
  638. package/dist/transcription/gwoyeu-spelling.js +124 -0
  639. package/dist/transcription/gwoyeu-spelling.js.map +1 -0
  640. package/dist/transcription/gwoyeu-tables.d.ts +93 -0
  641. package/dist/transcription/gwoyeu-tables.d.ts.map +1 -0
  642. package/dist/transcription/gwoyeu-tables.js +205 -0
  643. package/dist/transcription/gwoyeu-tables.js.map +1 -0
  644. package/dist/transcription/gwoyeu-tonal-forms.d.ts +49 -0
  645. package/dist/transcription/gwoyeu-tonal-forms.d.ts.map +1 -0
  646. package/dist/transcription/gwoyeu-tonal-forms.js +89 -0
  647. package/dist/transcription/gwoyeu-tonal-forms.js.map +1 -0
  648. package/dist/transcription/gwoyeu-vowels.d.ts +51 -0
  649. package/dist/transcription/gwoyeu-vowels.d.ts.map +1 -0
  650. package/dist/transcription/gwoyeu-vowels.js +58 -0
  651. package/dist/transcription/gwoyeu-vowels.js.map +1 -0
  652. package/dist/transcription/gwoyeu.d.ts +1 -26
  653. package/dist/transcription/gwoyeu.d.ts.map +1 -1
  654. package/dist/transcription/gwoyeu.js +2 -540
  655. package/dist/transcription/gwoyeu.js.map +1 -1
  656. package/dist/transcription/ipa-symbols.d.ts +67 -0
  657. package/dist/transcription/ipa-symbols.d.ts.map +1 -0
  658. package/dist/transcription/ipa-symbols.js +135 -0
  659. package/dist/transcription/ipa-symbols.js.map +1 -0
  660. package/dist/transcription/ipa.d.ts +2 -10
  661. package/dist/transcription/ipa.d.ts.map +1 -1
  662. package/dist/transcription/ipa.js +2 -134
  663. package/dist/transcription/ipa.js.map +1 -1
  664. package/dist/transcription/wade-giles-index.d.ts +35 -0
  665. package/dist/transcription/wade-giles-index.d.ts.map +1 -0
  666. package/dist/transcription/wade-giles-index.js +110 -0
  667. package/dist/transcription/wade-giles-index.js.map +1 -0
  668. package/dist/transcription/wade-giles-parse.d.ts +36 -0
  669. package/dist/transcription/wade-giles-parse.d.ts.map +1 -0
  670. package/dist/transcription/wade-giles-parse.js +84 -0
  671. package/dist/transcription/wade-giles-parse.js.map +1 -0
  672. package/dist/transcription/wade-giles-spelling.d.ts +61 -0
  673. package/dist/transcription/wade-giles-spelling.d.ts.map +1 -0
  674. package/dist/transcription/wade-giles-spelling.js +107 -0
  675. package/dist/transcription/wade-giles-spelling.js.map +1 -0
  676. package/dist/transcription/wade-giles-syllable.d.ts +29 -0
  677. package/dist/transcription/wade-giles-syllable.d.ts.map +1 -0
  678. package/dist/transcription/wade-giles-syllable.js +90 -0
  679. package/dist/transcription/wade-giles-syllable.js.map +1 -0
  680. package/dist/transcription/wade-giles-tables.d.ts +80 -0
  681. package/dist/transcription/wade-giles-tables.d.ts.map +1 -0
  682. package/dist/transcription/wade-giles-tables.js +178 -0
  683. package/dist/transcription/wade-giles-tables.js.map +1 -0
  684. package/dist/transcription/wade-giles.d.ts +9 -60
  685. package/dist/transcription/wade-giles.d.ts.map +1 -1
  686. package/dist/transcription/wade-giles.js +6 -543
  687. package/dist/transcription/wade-giles.js.map +1 -1
  688. package/dist/transcription/yale-tables.d.ts +54 -0
  689. package/dist/transcription/yale-tables.d.ts.map +1 -0
  690. package/dist/transcription/yale-tables.js +125 -0
  691. package/dist/transcription/yale-tables.js.map +1 -0
  692. package/dist/transcription/yale.d.ts.map +1 -1
  693. package/dist/transcription/yale.js +1 -124
  694. package/dist/transcription/yale.js.map +1 -1
  695. package/package.json +1 -1
@@ -1,6 +1,6 @@
1
1
  import { isUncertain } from "../decode/confidence.js";
2
+ export { convertToAnnotatedHtml, convertToHtml, toAnnotatedHtml, } from "./annotate.js";
2
3
  import { READING_CHARGE } from "../decode/lattice.js";
3
- import { convertPieces, } from "../decode/convert.js";
4
4
  import { DEFAULT_LOCALE } from "../script/script.js";
5
5
  import { writeSyllable } from "../syllable/syllable.js";
6
6
  /**
@@ -62,7 +62,7 @@ const ESCAPES = new Map([
62
62
  * every attribute here is double-quoted, and the 隔音符号 of `Xī'ān` is a
63
63
  * letter of the orthography that a reader should see as one.
64
64
  */
65
- function escape(text) {
65
+ export function escape(text) {
66
66
  return text.replaceAll(/[&<>"]/gu, (character) => {
67
67
  /* c8 ignore next -- the pattern only matches what the map holds */
68
68
  return ESCAPES.get(character) ?? character;
@@ -87,7 +87,7 @@ function alternativesOf(confidence, options) {
87
87
  /**
88
88
  * Mark up one piece of a conversion.
89
89
  */
90
- function writePiece(piece, options) {
90
+ export function writePiece(piece, options) {
91
91
  const { toneClasses = true, markUncertain = true, lang = true } = options;
92
92
  if (piece.syllable === undefined) {
93
93
  return escape(piece.text);
@@ -122,163 +122,4 @@ function writePiece(piece, options) {
122
122
  export function toHtml(pieces, options = {}) {
123
123
  return pieces.map((piece) => writePiece(piece, options)).join("");
124
124
  }
125
- /**
126
- * What the characters being annotated declare themselves to be.
127
- *
128
- * The mirror of {@link languageTag}: inside an annotation the base is hanzi and
129
- * only the reading is pinyin, so on an English page the two need different tags
130
- * and neither can be left to inherit.
131
- *
132
- * **`zh`, with no script subtag, and that is deliberate.** `Hans` or `Hant`
133
- * would be better for font selection, and neither can be known here. The
134
- * conversion's locale does not settle it — script and locale are separate axes,
135
- * and a mainland edition of a classical text is 繁體 read as `zh-CN` — and
136
- * detecting it from the characters needs the script tables, which load
137
- * separately from the dictionary precisely so that converting does not pay for
138
- * them. A tag that is merely unspecific is worth more than one that is wrong,
139
- * so a caller who knows the script should wrap the output and say so there.
140
- */
141
- const BASE_TAG = "zh";
142
- /**
143
- * Gather pieces into the bases they are readings of.
144
- *
145
- * A piece naming characters opens a group and every piece after it that names
146
- * none reads on into the same one, which is how 玩儿 keeps `wánr` over both
147
- * characters and 95% keeps `bǎifēnzhījiǔshíwǔ` over all three. Pieces writing
148
- * no reading at all — the spaces between words, and runs that were never Han —
149
- * are their own groups, with nothing to annotate.
150
- */
151
- function annotationsOf(pieces) {
152
- const groups = [];
153
- for (const [at, piece] of pieces.entries()) {
154
- const open = groups.at(-1);
155
- if (open?.source !== undefined && continues(piece, pieces[at + 1])) {
156
- groups[groups.length - 1] = {
157
- source: open.source,
158
- pieces: [...open.pieces, piece],
159
- };
160
- continue;
161
- }
162
- groups.push({ source: piece.source, pieces: [piece] });
163
- }
164
- return groups;
165
- }
166
- /**
167
- * Whether a piece belongs to the annotation the group before it opened.
168
- *
169
- * Three kinds do:
170
- *
171
- * - A **syllable naming no characters** is reading on into the ones already
172
- * named, which is 儿化 and every syllable of a read number after the first.
173
- * - A **separator that is not a space** is a mark *inside* one orthographic
174
- * word rather than a gap between two — the hyphen of `gāngān-jìngjìng`, the
175
- * only one GB/T 16159 writes — so it belongs beside the syllables it divides.
176
- * - A **space with more of the same reading after it**. 1988 is read
177
- * `yī jiǔ bā bā`, four syllables over one base, and the spaces between them
178
- * are inside that reading rather than between two of them.
179
- *
180
- * That last one is why this needs the piece after it. A space is written the
181
- * same way whether it separates two words or two syllables of one number, and
182
- * what tells them apart is whether what follows is still reading the same
183
- * characters. Told apart wrongly, the reading escapes its own annotation:
184
- * 1988年 came out as `1988` over `yī` with `jiǔ bā bā` loose beside it.
185
- *
186
- * A space between two words is the case that does not continue, and dropping it
187
- * is the point: the hanzi it annotates has no space in it, and each base is
188
- * already its own group on the page.
189
- */
190
- function continues(piece, next) {
191
- if (piece.syllable !== undefined) {
192
- return piece.source === undefined;
193
- }
194
- if (piece.source !== undefined) {
195
- return false;
196
- }
197
- return (piece.text.trim() !== "" ||
198
- (next?.syllable !== undefined && next.source === undefined));
199
- }
200
- /**
201
- * Mark up one base and its reading.
202
- */
203
- function writeAnnotation(annotation, options) {
204
- const { lang = true } = options;
205
- const { source, pieces } = annotation;
206
- if (pieces.every((piece) => piece.syllable === undefined)) {
207
- // Nothing is read here. Either it is source text that simply has no
208
- // reading — punctuation, a Latin word — and is written as the author wrote
209
- // it, or it is pinyin orthography with no source behind it at all: the
210
- // space between two words, and the hyphen in `gāngān-jìngjìng`. Writing
211
- // those into the hanzi would annotate 干干净净 as 干干-净净.
212
- return source === undefined ? "" : escape(source);
213
- }
214
- if (source === undefined) {
215
- // A reading whose piece never named what it reads. Nothing a conversion
216
- // builds looks like this — every group is opened by a piece carrying its
217
- // characters — but {@link toAnnotatedHtml} takes pieces from the caller,
218
- // and there is no base to hang an annotation on, so it is written as the
219
- // plain markup it would have got from {@link toHtml}.
220
- return pieces.map((piece) => writePiece(piece, options)).join("");
221
- }
222
- const reading = pieces.map((piece) => writePiece(piece, options)).join("");
223
- // The tag goes on the <ruby> rather than around the base, and the syllables
224
- // inside the <rt> override it with their own. `<rb>` would be the obvious
225
- // place for it and is not an element any more: the WHATWG parser drops it,
226
- // leaving the base as bare text, so writing one would mean emitting markup
227
- // that no browser keeps.
228
- const opening = lang ? `<ruby lang="${BASE_TAG}">` : "<ruby>";
229
- return `${opening}${escape(source)}<rp>(</rp><rt>${reading}</rt><rp>)</rp></ruby>`;
230
- }
231
- /**
232
- * Mark up a converted text as hanzi with its reading above, syllable by
233
- * syllable.
234
- *
235
- * The output every other mode cannot give: `convert` and {@link toHtml} write
236
- * the pinyin *instead of* the hanzi, and a learner's text, a subtitle and a
237
- * dictionary entry all want both at once. The markup is `<ruby>`, which every
238
- * current browser lays out natively and which degrades to parentheses through
239
- * `<rp>` where it is not supported.
240
- *
241
- * ```html
242
- * <ruby lang="zh">银<rp>(</rp><rt><span …>yín</span></rt><rp>)</rp></ruby>
243
- * ```
244
- *
245
- * Each `<rt>` holds whatever {@link toHtml} would have written for those
246
- * syllables, so tone classes and uncertainty marking work inside an annotation
247
- * exactly as they do outside one.
248
- *
249
- * **A base is not always one character.** 玩儿 is two characters and the one
250
- * syllable `wánr`, and a read number reverses on the way — 95% is
251
- * `bǎifēnzhījiǔshíwǔ` — so both are annotated whole. Splitting them per
252
- * character is what everything that emits ruby from a pinyin library gets
253
- * wrong, and it is why {@link ConvertedPiece.source} exists.
254
- */
255
- export function toAnnotatedHtml(pieces, options = {}) {
256
- return annotationsOf(pieces)
257
- .map((annotation) => writeAnnotation(annotation, options))
258
- .join("");
259
- }
260
- /**
261
- * Convert hanzi to pinyin as HTML, hanzi and reading together.
262
- *
263
- * {@link toAnnotatedHtml} applied to a fresh conversion; see it for what the
264
- * markup is and why a base is not always one character.
265
- */
266
- export function convertToAnnotatedHtml(dictionary, text, options = {}) {
267
- return toAnnotatedHtml(convertPieces(dictionary, text, options), options);
268
- }
269
- /**
270
- * Convert hanzi to pinyin as HTML, one element per syllable.
271
- *
272
- * What per-syllable confidence is for, and the reason ALGORITHM.md asks for it:
273
- * a reading the decode was guessing at can be *shown* to be a guess, which for
274
- * a learner is a feature rather than a diagnostic. No styling is imposed — the
275
- * classes are hooks, and the page decides whether a fourth tone is red and an
276
- * uncertain reading is dotted underneath.
277
- *
278
- * Nothing is wrapped around the whole conversion, and anything that is not Han
279
- * passes through escaped rather than marked up.
280
- */
281
- export function convertToHtml(dictionary, text, options = {}) {
282
- return toHtml(convertPieces(dictionary, text, options), options);
283
- }
284
125
  //# sourceMappingURL=html.js.map
@@ -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AAW,CAAC,KAAK,CAAC,UAAU,CAAC;QAC3B,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC;QAC3C,CAAC,CAAC,EAAE,CAAC;IACT,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,UAAU,GAAG,CAAC,UAAU,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpD,IAAI,IAAI,EAAE,CAAC;QACT,UAAU,CAAC,IAAI,CAAC,SAAS,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,UAAU,CAAC,IAAI,CAAC,sBAAsB,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3E,CAAC;IACD,OAAO,SAAS,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC;AACtE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,MAAM,CACpB,MAAiC,EACjC,OAAO,GAAgB,EAAE;IAEzB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACpE,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The short hash a slug may carry on its end.
3
+ *
4
+ * Apart from the rest of slugging because it never sees a syllable: what is
5
+ * hashed is the source text, for the reason set out at {@link hashOf}, so this
6
+ * runs beside the conversion rather than after it.
7
+ */
8
+ /**
9
+ * How many characters {@link SlugOptions.hash} writes when simply asked for.
10
+ *
11
+ * Four base-36 characters is 1.7 million values, which is far more than it
12
+ * looks: two texts only collide when their slugs *and* their hashes match, so
13
+ * the suffix is only ever telling apart the handful of texts sharing one slug,
14
+ * not the whole corpus.
15
+ */
16
+ export declare const DEFAULT_HASH_LENGTH = 4;
17
+ /**
18
+ * The longest hash there is anything to fill.
19
+ *
20
+ * {@link hashOf} is 32 bits wide, and 36⁷ is the last power of 36 under 2³²:
21
+ * asking for an eighth character would add a place that some values can never
22
+ * reach, which looks like more uniqueness while being none.
23
+ */
24
+ export declare const LONGEST_HASH = 7;
25
+ /**
26
+ * A 32-bit hash of a text, written in the letters and digits a slug allows.
27
+ *
28
+ * **The source text is what is hashed, not the pinyin.** Two texts needing a
29
+ * hash to tell them apart are, by definition, ones the pinyin already ran
30
+ * together: 权利 and 权力 are both `quan2li4`, and hashing that would give them
31
+ * the same suffix and settle nothing. Hashing the hanzi also means the suffix
32
+ * does not move when a later release reads a word differently, so a slug's tail
33
+ * is the stable half of it.
34
+ *
35
+ * FNV-1a with murmur3's finalizer, which is neither cryptographic nor trying to
36
+ * be: nothing here resists an attacker, and all that is being asked of it is
37
+ * that two texts a reader would call different land on different suffixes.
38
+ * Written out rather than reached for because the package has no runtime
39
+ * dependencies and the core imports no Node built-ins, and `crypto.subtle` —
40
+ * the one hash a browser ships — is asynchronous, which this is not.
41
+ *
42
+ * Normalised first, so that text typed as a decomposed sequence hashes as the
43
+ * same text once composed. 简体 and 繁體 are deliberately *not* folded together:
44
+ * a caller who wrote 头发 and 頭髮 separately meant them separately.
45
+ */
46
+ export declare function hashOf(text: string, length: number): string;
47
+ /**
48
+ * How long a hash the options asked for, or zero for none.
49
+ */
50
+ export declare function hashLength(asked: number | boolean | undefined): number;
51
+ //# sourceMappingURL=slug-hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug-hash.d.ts","sourceRoot":"","sources":["../../src/format/slug-hash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,IAAI,CAAC;AAErC;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,IAAI,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAgB3D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAQtE"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * The short hash a slug may carry on its end.
3
+ *
4
+ * Apart from the rest of slugging because it never sees a syllable: what is
5
+ * hashed is the source text, for the reason set out at {@link hashOf}, so this
6
+ * runs beside the conversion rather than after it.
7
+ */
8
+ /**
9
+ * How many characters {@link SlugOptions.hash} writes when simply asked for.
10
+ *
11
+ * Four base-36 characters is 1.7 million values, which is far more than it
12
+ * looks: two texts only collide when their slugs *and* their hashes match, so
13
+ * the suffix is only ever telling apart the handful of texts sharing one slug,
14
+ * not the whole corpus.
15
+ */
16
+ export const DEFAULT_HASH_LENGTH = 4;
17
+ /**
18
+ * The longest hash there is anything to fill.
19
+ *
20
+ * {@link hashOf} is 32 bits wide, and 36⁷ is the last power of 36 under 2³²:
21
+ * asking for an eighth character would add a place that some values can never
22
+ * reach, which looks like more uniqueness while being none.
23
+ */
24
+ export const LONGEST_HASH = 7;
25
+ /**
26
+ * A 32-bit hash of a text, written in the letters and digits a slug allows.
27
+ *
28
+ * **The source text is what is hashed, not the pinyin.** Two texts needing a
29
+ * hash to tell them apart are, by definition, ones the pinyin already ran
30
+ * together: 权利 and 权力 are both `quan2li4`, and hashing that would give them
31
+ * the same suffix and settle nothing. Hashing the hanzi also means the suffix
32
+ * does not move when a later release reads a word differently, so a slug's tail
33
+ * is the stable half of it.
34
+ *
35
+ * FNV-1a with murmur3's finalizer, which is neither cryptographic nor trying to
36
+ * be: nothing here resists an attacker, and all that is being asked of it is
37
+ * that two texts a reader would call different land on different suffixes.
38
+ * Written out rather than reached for because the package has no runtime
39
+ * dependencies and the core imports no Node built-ins, and `crypto.subtle` —
40
+ * the one hash a browser ships — is asynchronous, which this is not.
41
+ *
42
+ * Normalised first, so that text typed as a decomposed sequence hashes as the
43
+ * same text once composed. 简体 and 繁體 are deliberately *not* folded together:
44
+ * a caller who wrote 头发 and 頭髮 separately meant them separately.
45
+ */
46
+ export function hashOf(text, length) {
47
+ const bytes = new TextEncoder().encode(text.normalize("NFC"));
48
+ let hash = 0x81_1c_9d_c5;
49
+ for (const byte of bytes) {
50
+ hash = Math.imul(hash ^ byte, 0x01_00_01_93);
51
+ }
52
+ // FNV-1a leaves its lowest bits the least mixed, and the last characters of
53
+ // the base-36 spelling are exactly those bits, so this spreads them first.
54
+ hash ^= hash >>> 16;
55
+ hash = Math.imul(hash, 0x85_eb_ca_6b);
56
+ hash ^= hash >>> 13;
57
+ hash = Math.imul(hash, 0xc2_b2_ae_35);
58
+ hash ^= hash >>> 16;
59
+ const wanted = Math.min(Math.max(Math.trunc(length), 1), LONGEST_HASH);
60
+ return (hash >>> 0).toString(36).padStart(LONGEST_HASH, "0").slice(-wanted);
61
+ }
62
+ /**
63
+ * How long a hash the options asked for, or zero for none.
64
+ */
65
+ export function hashLength(asked) {
66
+ if (asked === undefined || asked === false) {
67
+ return 0;
68
+ }
69
+ if (asked === true) {
70
+ return DEFAULT_HASH_LENGTH;
71
+ }
72
+ return Math.min(Math.max(Math.trunc(asked), 0), LONGEST_HASH);
73
+ }
74
+ //# sourceMappingURL=slug-hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug-hash.js","sourceRoot":"","sources":["../../src/format/slug-hash.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;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CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AAChE,CAAC"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * How a slug is built.
3
+ *
4
+ * Their own module because every part of slugging reads them and none of them
5
+ * reads the others: the words, the hash and the fitting all take the same
6
+ * options object, and none of the three should have to import the other two to
7
+ * name it.
8
+ */
9
+ import type { NumberStyle } from "../decode/convert.js";
10
+ import type { SandhiOptions } from "../decode/sandhi.js";
11
+ import type { Locale } from "../script/script.js";
12
+ /**
13
+ * Whether a slug carries its tones.
14
+ *
15
+ * `numbers` writes them as digits — 中文 is `zhong1wen2` — and `none` leaves
16
+ * them off. Tones are on by default because dropping them collides: there are
17
+ * roughly 400 toneless syllables against 1300 toned ones, so a toneless slug
18
+ * runs 树, 书 and 输 together as `shu`. They are not a guarantee, though —
19
+ * 权利 and 权力 are both `quan2li4`, and only {@link SlugOptions.hash} tells
20
+ * those apart.
21
+ */
22
+ export type SlugTones = "numbers" | "none";
23
+ /**
24
+ * Whether the syllables inside one word are separated.
25
+ *
26
+ * `join` writes a word as a word — 中文 is `zhong1wen2` — which is what 正词法
27
+ * asks for and what a reader expects in a URL. `separate` cuts every syllable
28
+ * apart, `zhong1-wen2`, for a caller matching a slug syllable by syllable.
29
+ */
30
+ export type SlugSyllables = "join" | "separate";
31
+ /**
32
+ * How ü is written where the alphabet has no room for it.
33
+ *
34
+ * `v` is the input-method convention and keeps 绿 `lv4` apart from 路 `lu4`;
35
+ * `u` is prettier and merges them.
36
+ */
37
+ export type SlugUmlaut = "v" | "u";
38
+ /**
39
+ * How a slug is built.
40
+ */
41
+ export interface SlugOptions {
42
+ /** Whether tones are written. Defaults to `numbers`. */
43
+ readonly tones?: SlugTones;
44
+ /**
45
+ * What goes between words. Defaults to `-`.
46
+ *
47
+ * Written as given rather than checked, because the separator is the one
48
+ * place a caller decides what kind of identifier this is: `-` for a URL, `_`
49
+ * for a name in code, and the empty string for a key to match against.
50
+ */
51
+ readonly separator?: string;
52
+ /** Whether the syllables within a word are separated. Defaults to `join`. */
53
+ readonly syllables?: SlugSyllables;
54
+ /** How ü is written. Defaults to `v`. */
55
+ readonly umlaut?: SlugUmlaut;
56
+ /**
57
+ * What to do with the digits in a text. Defaults to `keep`.
58
+ *
59
+ * The opposite of what a conversion defaults to, and deliberately: a slug for
60
+ * iPhone 15 评测 should be `iphone-15-ping2ce4` rather than
61
+ * `iphone-shi2wu3-ping2ce4`, because the digits are how anyone would look for
62
+ * it. `read` says them, for a caller that wants the text spoken.
63
+ */
64
+ readonly numbers?: NumberStyle;
65
+ /**
66
+ * A short hash of the source text on the end. Defaults to none.
67
+ *
68
+ * `true` for {@link DEFAULT_HASH_LENGTH} characters, or a length of your own,
69
+ * up to {@link LONGEST_HASH}. See {@link hashOf} for what is hashed and why
70
+ * it is the hanzi rather than the pinyin.
71
+ *
72
+ * Unconditional rather than only where two slugs collide: a function that
73
+ * cannot see the rest of your corpus cannot know that they did. It narrows
74
+ * collisions rather than closing them, and checking the slug you generated
75
+ * against the ones you have stored is still yours to do.
76
+ */
77
+ readonly hash?: number | boolean;
78
+ /**
79
+ * The longest the slug may be, counting any hash. Defaults to no limit.
80
+ *
81
+ * Cut at a word boundary, so a limit lands between words rather than through
82
+ * the middle of one. A single word longer than the limit is cut where the
83
+ * limit falls, since there is nowhere else to cut it, and the hash is never
84
+ * what gets dropped.
85
+ */
86
+ readonly maxLength?: number;
87
+ /**
88
+ * What to write where a text slugs to nothing. Defaults to the empty string.
89
+ *
90
+ * 《》! has no letters in it, and neither does an empty text.
91
+ */
92
+ readonly fallback?: string;
93
+ /** Which reading standard to use. Defaults to `zh-CN`. */
94
+ readonly locale?: Locale;
95
+ /** Which tone sandhi to apply. Defaults to what a conversion applies. */
96
+ readonly sandhi?: SandhiOptions;
97
+ }
98
+ //# sourceMappingURL=slug-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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appingURL=slug-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug-options.js","sourceRoot":"","sources":["../../src/format/slug-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Writing the words of a slug, before anything is decided about its length.
3
+ *
4
+ * Everything here works in boundaries rather than in the caller's separator,
5
+ * for the reason given at {@link BOUNDARY}; what comes out is a list of words,
6
+ * and `slug.ts` decides how many of them there is room for and what goes
7
+ * between them.
8
+ */
9
+ import type { ConvertedPiece } from "../decode/convert.js";
10
+ import type { SlugOptions } from "./slug-options.js";
11
+ /**
12
+ * Gather each run of consecutive syllables, which is one word.
13
+ *
14
+ * A conversion puts a piece carrying no syllable between two words — the space,
15
+ * or the hyphen 分词连写 writes inside 干干净净 — so the words are already
16
+ * marked out and need no second look at the text.
17
+ */
18
+ export declare function slugPieces(pieces: readonly ConvertedPiece[], options: SlugOptions): string;
19
+ /**
20
+ * The words a build produced, with its empty boundaries collapsed away.
21
+ *
22
+ * Everything after this works on the words rather than on the text they will
23
+ * become, so that a limit counts the separator the caller actually chose: a
24
+ * boundary is one character here and could be two, or none, once written.
25
+ */
26
+ export declare function partsOf(built: string): readonly string[];
27
+ //# sourceMappingURL=slug-words.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"slug-words.d.ts","sourceRoot":"","sources":["../../src/format/slug-words.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG3D,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,mBAAmB,CAAC;AAsFjE;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,SAAS,cAAc,EAAE,EACjC,OAAO,EAAE,WAAW,GACnB,MAAM,CAuBR;AAED;;;;;;GAMG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAExD"}
Binary file
@@ -0,0 +1 @@
1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
1
- import { type NumberStyle } from "../decode/convert.js";
2
- import type { SandhiOptions } from "../decode/sandhi.js";
3
1
  import type { Dictionary } from "../dictionary/dictionary.js";
4
- import type { Locale } from "../script/script.js";
5
- /**
6
- * Whether a slug carries its tones.
7
- *
8
- * `numbers` writes them as digits — 中文 is `zhong1wen2` — and `none` leaves
9
- * them off. Tones are on by default because dropping them collides: there are
10
- * roughly 400 toneless syllables against 1300 toned ones, so a toneless slug
11
- * runs 树, 书 and 输 together as `shu`. They are not a guarantee, though —
12
- * 权利 and 权力 are both `quan2li4`, and only {@link SlugOptions.hash} tells
13
- * those apart.
14
- */
15
- export type SlugTones = "numbers" | "none";
16
- /**
17
- * Whether the syllables inside one word are separated.
18
- *
19
- * `join` writes a word as a word — 中文 is `zhong1wen2` — which is what 正词法
20
- * asks for and what a reader expects in a URL. `separate` cuts every syllable
21
- * apart, `zhong1-wen2`, for a caller matching a slug syllable by syllable.
22
- */
23
- export type SlugSyllables = "join" | "separate";
24
- /**
25
- * How ü is written where the alphabet has no room for it.
26
- *
27
- * `v` is the input-method convention and keeps 绿 `lv4` apart from 路 `lu4`;
28
- * `u` is prettier and merges them.
29
- */
30
- export type SlugUmlaut = "v" | "u";
31
- /**
32
- * How a slug is built.
33
- */
34
- export interface SlugOptions {
35
- /** Whether tones are written. Defaults to `numbers`. */
36
- readonly tones?: SlugTones;
37
- /**
38
- * What goes between words. Defaults to `-`.
39
- *
40
- * Written as given rather than checked, because the separator is the one
41
- * place a caller decides what kind of identifier this is: `-` for a URL, `_`
42
- * for a name in code, and the empty string for a key to match against.
43
- */
44
- readonly separator?: string;
45
- /** Whether the syllables within a word are separated. Defaults to `join`. */
46
- readonly syllables?: SlugSyllables;
47
- /** How ü is written. Defaults to `v`. */
48
- readonly umlaut?: SlugUmlaut;
49
- /**
50
- * What to do with the digits in a text. Defaults to `keep`.
51
- *
52
- * The opposite of what a conversion defaults to, and deliberately: a slug for
53
- * iPhone 15 评测 should be `iphone-15-ping2ce4` rather than
54
- * `iphone-shi2wu3-ping2ce4`, because the digits are how anyone would look for
55
- * it. `read` says them, for a caller that wants the text spoken.
56
- */
57
- readonly numbers?: NumberStyle;
58
- /**
59
- * A short hash of the source text on the end. Defaults to none.
60
- *
61
- * `true` for {@link DEFAULT_HASH_LENGTH} characters, or a length of your own,
62
- * up to {@link LONGEST_HASH}. See {@link hashOf} for what is hashed and why
63
- * it is the hanzi rather than the pinyin.
64
- *
65
- * Unconditional rather than only where two slugs collide: a function that
66
- * cannot see the rest of your corpus cannot know that they did. It narrows
67
- * collisions rather than closing them, and checking the slug you generated
68
- * against the ones you have stored is still yours to do.
69
- */
70
- readonly hash?: number | boolean;
71
- /**
72
- * The longest the slug may be, counting any hash. Defaults to no limit.
73
- *
74
- * Cut at a word boundary, so a limit lands between words rather than through
75
- * the middle of one. A single word longer than the limit is cut where the
76
- * limit falls, since there is nowhere else to cut it, and the hash is never
77
- * what gets dropped.
78
- */
79
- readonly maxLength?: number;
80
- /**
81
- * What to write where a text slugs to nothing. Defaults to the empty string.
82
- *
83
- * 《》! has no letters in it, and neither does an empty text.
84
- */
85
- readonly fallback?: string;
86
- /** Which reading standard to use. Defaults to `zh-CN`. */
87
- readonly locale?: Locale;
88
- /** Which tone sandhi to apply. Defaults to what a conversion applies. */
89
- readonly sandhi?: SandhiOptions;
90
- }
91
- /**
92
- * How many characters {@link SlugOptions.hash} writes when simply asked for.
93
- *
94
- * Four base-36 characters is 1.7 million values, which is far more than it
95
- * looks: two texts only collide when their slugs *and* their hashes match, so
96
- * the suffix is only ever telling apart the handful of texts sharing one slug,
97
- * not the whole corpus.
98
- */
99
- export declare const DEFAULT_HASH_LENGTH = 4;
100
- /**
101
- * The longest hash there is anything to fill.
102
- *
103
- * {@link hashOf} is 32 bits wide, and 36⁷ is the last power of 36 under 2³²:
104
- * asking for an eighth character would add a place that some values can never
105
- * reach, which looks like more uniqueness while being none.
106
- */
107
- export declare const LONGEST_HASH = 7;
108
- /**
109
- * A 32-bit hash of a text, written in the letters and digits a slug allows.
110
- *
111
- * **The source text is what is hashed, not the pinyin.** Two texts needing a
112
- * hash to tell them apart are, by definition, ones the pinyin already ran
113
- * together: 权利 and 权力 are both `quan2li4`, and hashing that would give them
114
- * the same suffix and settle nothing. Hashing the hanzi also means the suffix
115
- * does not move when a later release reads a word differently, so a slug's tail
116
- * is the stable half of it.
117
- *
118
- * FNV-1a with murmur3's finalizer, which is neither cryptographic nor trying to
119
- * be: nothing here resists an attacker, and all that is being asked of it is
120
- * that two texts a reader would call different land on different suffixes.
121
- * Written out rather than reached for because the package has no runtime
122
- * dependencies and the core imports no Node built-ins, and `crypto.subtle` —
123
- * the one hash a browser ships — is asynchronous, which this is not.
124
- *
125
- * Normalised first, so that text typed as a decomposed sequence hashes as the
126
- * same text once composed. 简体 and 繁體 are deliberately *not* folded together:
127
- * a caller who wrote 头发 and 頭髮 separately meant them separately.
128
- */
129
- export declare function hashOf(text: string, length: number): string;
2
+ import type { SlugOptions } from "./slug-options.js";
3
+ export { DEFAULT_HASH_LENGTH, hashOf, LONGEST_HASH } from "./slug-hash.js";
4
+ export type { SlugOptions, SlugSyllables, SlugTones, SlugUmlaut, } from "./slug-options.js";
130
5
  /**
131
6
  * Convert hanzi to a URL-safe slug.
132
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":"slug.d.ts","sourceRoot":"","sources":["../../src/format/slug.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAE9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD;;;;;;;;;GASG;AACH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,C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