@mailwoman/registry 11.0.0 → 11.2.0

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 (258) hide show
  1. package/README.md +21 -6
  2. package/data/manifests/artifacts.json +35 -0
  3. package/data/manifests/coverage.json +63 -0
  4. package/data/manifests/sources.lock.json +12 -0
  5. package/data/normalized/language-subtags.json +18518 -0
  6. package/docs/data-policy.md +5 -5
  7. package/docs/performance.md +1 -1
  8. package/docs/rgy1.md +5 -5
  9. package/lib/artifacts/bcp47/extlang.fixture.json +260 -0
  10. package/lib/artifacts/bcp47/extlang.ts +32 -0
  11. package/lib/artifacts/bcp47/grandfathered.fixture.json +28 -0
  12. package/lib/artifacts/bcp47/grandfathered.ts +32 -0
  13. package/lib/artifacts/bcp47/language.fixture.json +8278 -0
  14. package/lib/artifacts/bcp47/language.ts +32 -0
  15. package/lib/artifacts/bcp47/redundant.fixture.json +69 -0
  16. package/lib/artifacts/bcp47/redundant.ts +32 -0
  17. package/lib/artifacts/bcp47/region.fixture.json +307 -0
  18. package/lib/artifacts/bcp47/region.ts +32 -0
  19. package/lib/artifacts/bcp47/script.fixture.json +227 -0
  20. package/lib/artifacts/bcp47/script.ts +32 -0
  21. package/lib/artifacts/bcp47/variant.fixture.json +141 -0
  22. package/lib/artifacts/bcp47/variant.ts +32 -0
  23. package/lib/artifacts/country-airport-collision.ts +7 -5
  24. package/lib/artifacts/iata-airport/membership.ts +7 -5
  25. package/lib/artifacts/iata-airport/records.ts +7 -5
  26. package/lib/artifacts/iso3166-1/alpha2-membership.ts +7 -5
  27. package/lib/artifacts/iso3166-1/alpha3-membership.ts +7 -5
  28. package/lib/artifacts/iso3166-1/records.ts +7 -5
  29. package/lib/bcp47/subtag-index.ts +65 -0
  30. package/lib/bcp47/tag.ts +301 -0
  31. package/lib/errors.ts +22 -9
  32. package/lib/iata/airports/records.ts +3 -4
  33. package/lib/iata/airports/validate.ts +6 -5
  34. package/lib/index.ts +18 -8
  35. package/lib/inspect.ts +5 -5
  36. package/lib/iso15924/codes.ts +169 -0
  37. package/lib/iso15924/unicode-script.ts +124 -0
  38. package/lib/iso3166/alpha2.ts +5 -5
  39. package/lib/iso3166/alpha3.ts +6 -6
  40. package/lib/iso3166/records.ts +9 -8
  41. package/lib/iso3166/relations.ts +5 -5
  42. package/lib/iso639/languages.ts +88 -0
  43. package/lib/key.ts +9 -7
  44. package/lib/normalize.ts +12 -8
  45. package/lib/overlap/country-airport.ts +14 -12
  46. package/lib/rgy1/base64.ts +3 -4
  47. package/lib/rgy1/reader.ts +8 -7
  48. package/lib/rgy1/sections.generated.ts +6 -5
  49. package/lib/rgy1/views.ts +5 -6
  50. package/lib/types.ts +66 -7
  51. package/lib/wasm.ts +11 -9
  52. package/out/artifacts/bcp47/extlang.d.ts +21 -0
  53. package/out/artifacts/bcp47/extlang.d.ts.map +1 -0
  54. package/out/artifacts/bcp47/extlang.fixture.json +260 -0
  55. package/out/artifacts/bcp47/extlang.js +17 -0
  56. package/out/artifacts/bcp47/extlang.js.map +1 -0
  57. package/out/artifacts/bcp47/grandfathered.d.ts +21 -0
  58. package/out/artifacts/bcp47/grandfathered.d.ts.map +1 -0
  59. package/out/artifacts/bcp47/grandfathered.fixture.json +28 -0
  60. package/out/artifacts/bcp47/grandfathered.js +17 -0
  61. package/out/artifacts/bcp47/grandfathered.js.map +1 -0
  62. package/out/artifacts/bcp47/language.d.ts +21 -0
  63. package/out/artifacts/bcp47/language.d.ts.map +1 -0
  64. package/out/artifacts/bcp47/language.fixture.json +8278 -0
  65. package/out/artifacts/bcp47/language.js +17 -0
  66. package/out/artifacts/bcp47/language.js.map +1 -0
  67. package/out/artifacts/bcp47/redundant.d.ts +21 -0
  68. package/out/artifacts/bcp47/redundant.d.ts.map +1 -0
  69. package/out/artifacts/bcp47/redundant.fixture.json +69 -0
  70. package/out/artifacts/bcp47/redundant.js +17 -0
  71. package/out/artifacts/bcp47/redundant.js.map +1 -0
  72. package/out/artifacts/bcp47/region.d.ts +21 -0
  73. package/out/artifacts/bcp47/region.d.ts.map +1 -0
  74. package/out/artifacts/bcp47/region.fixture.json +307 -0
  75. package/out/artifacts/bcp47/region.js +17 -0
  76. package/out/artifacts/bcp47/region.js.map +1 -0
  77. package/out/artifacts/bcp47/script.d.ts +21 -0
  78. package/out/artifacts/bcp47/script.d.ts.map +1 -0
  79. package/out/artifacts/bcp47/script.fixture.json +227 -0
  80. package/out/artifacts/bcp47/script.js +17 -0
  81. package/out/artifacts/bcp47/script.js.map +1 -0
  82. package/out/artifacts/bcp47/variant.d.ts +21 -0
  83. package/out/artifacts/bcp47/variant.d.ts.map +1 -0
  84. package/out/artifacts/bcp47/variant.fixture.json +141 -0
  85. package/out/artifacts/bcp47/variant.js +17 -0
  86. package/out/artifacts/bcp47/variant.js.map +1 -0
  87. package/out/artifacts/country-airport-collision.d.ts +0 -8
  88. package/out/artifacts/country-airport-collision.d.ts.map +1 -1
  89. package/out/artifacts/country-airport-collision.js +6 -5
  90. package/out/artifacts/country-airport-collision.js.map +1 -1
  91. package/out/artifacts/iata-airport/membership.d.ts +0 -8
  92. package/out/artifacts/iata-airport/membership.d.ts.map +1 -1
  93. package/out/artifacts/iata-airport/membership.js +6 -5
  94. package/out/artifacts/iata-airport/membership.js.map +1 -1
  95. package/out/artifacts/iata-airport/records.d.ts +0 -8
  96. package/out/artifacts/iata-airport/records.d.ts.map +1 -1
  97. package/out/artifacts/iata-airport/records.js +6 -5
  98. package/out/artifacts/iata-airport/records.js.map +1 -1
  99. package/out/artifacts/iso3166-1/alpha2-membership.d.ts +0 -8
  100. package/out/artifacts/iso3166-1/alpha2-membership.d.ts.map +1 -1
  101. package/out/artifacts/iso3166-1/alpha2-membership.js +6 -5
  102. package/out/artifacts/iso3166-1/alpha2-membership.js.map +1 -1
  103. package/out/artifacts/iso3166-1/alpha3-membership.d.ts +0 -8
  104. package/out/artifacts/iso3166-1/alpha3-membership.d.ts.map +1 -1
  105. package/out/artifacts/iso3166-1/alpha3-membership.js +6 -5
  106. package/out/artifacts/iso3166-1/alpha3-membership.js.map +1 -1
  107. package/out/artifacts/iso3166-1/records.d.ts +0 -8
  108. package/out/artifacts/iso3166-1/records.d.ts.map +1 -1
  109. package/out/artifacts/iso3166-1/records.js +6 -5
  110. package/out/artifacts/iso3166-1/records.js.map +1 -1
  111. package/out/bcp47/subtag-index.d.ts +22 -0
  112. package/out/bcp47/subtag-index.d.ts.map +1 -0
  113. package/out/bcp47/subtag-index.js +43 -0
  114. package/out/bcp47/subtag-index.js.map +1 -0
  115. package/out/bcp47/tag.d.ts +47 -0
  116. package/out/bcp47/tag.d.ts.map +1 -0
  117. package/out/bcp47/tag.js +218 -0
  118. package/out/bcp47/tag.js.map +1 -0
  119. package/out/errors.d.ts +12 -8
  120. package/out/errors.d.ts.map +1 -1
  121. package/out/errors.js +10 -8
  122. package/out/errors.js.map +1 -1
  123. package/out/iata/airports/records.d.ts +0 -7
  124. package/out/iata/airports/records.d.ts.map +1 -1
  125. package/out/iata/airports/records.js +2 -4
  126. package/out/iata/airports/records.js.map +1 -1
  127. package/out/iata/airports/validate.d.ts +0 -8
  128. package/out/iata/airports/validate.d.ts.map +1 -1
  129. package/out/iata/airports/validate.js +5 -5
  130. package/out/iata/airports/validate.js.map +1 -1
  131. package/out/index.d.ts +13 -8
  132. package/out/index.d.ts.map +1 -1
  133. package/out/index.js +6 -12
  134. package/out/index.js.map +1 -1
  135. package/out/inspect.d.ts +2 -5
  136. package/out/inspect.d.ts.map +1 -1
  137. package/out/inspect.js +4 -5
  138. package/out/inspect.js.map +1 -1
  139. package/out/iso15924/codes.d.ts +57 -0
  140. package/out/iso15924/codes.d.ts.map +1 -0
  141. package/out/iso15924/codes.js +133 -0
  142. package/out/iso15924/codes.js.map +1 -0
  143. package/out/iso15924/unicode-script.d.ts +10 -0
  144. package/out/iso15924/unicode-script.d.ts.map +1 -0
  145. package/out/iso15924/unicode-script.js +103 -0
  146. package/out/iso15924/unicode-script.js.map +1 -0
  147. package/out/iso3166/alpha2.d.ts +0 -8
  148. package/out/iso3166/alpha2.d.ts.map +1 -1
  149. package/out/iso3166/alpha2.js +4 -5
  150. package/out/iso3166/alpha2.js.map +1 -1
  151. package/out/iso3166/alpha3.d.ts +1 -9
  152. package/out/iso3166/alpha3.d.ts.map +1 -1
  153. package/out/iso3166/alpha3.js +5 -6
  154. package/out/iso3166/alpha3.js.map +1 -1
  155. package/out/iso3166/records.d.ts +0 -11
  156. package/out/iso3166/records.d.ts.map +1 -1
  157. package/out/iso3166/records.js +8 -8
  158. package/out/iso3166/records.js.map +1 -1
  159. package/out/iso3166/relations.d.ts +0 -7
  160. package/out/iso3166/relations.d.ts.map +1 -1
  161. package/out/iso3166/relations.js +4 -5
  162. package/out/iso3166/relations.js.map +1 -1
  163. package/out/iso639/languages.d.ts +40 -0
  164. package/out/iso639/languages.d.ts.map +1 -0
  165. package/out/iso639/languages.js +54 -0
  166. package/out/iso639/languages.js.map +1 -0
  167. package/out/key.d.ts +6 -7
  168. package/out/key.d.ts.map +1 -1
  169. package/out/key.js +8 -7
  170. package/out/key.js.map +1 -1
  171. package/out/normalize.d.ts +9 -8
  172. package/out/normalize.d.ts.map +1 -1
  173. package/out/normalize.js +2 -12
  174. package/out/normalize.js.map +1 -1
  175. package/out/overlap/country-airport.d.ts +2 -16
  176. package/out/overlap/country-airport.d.ts.map +1 -1
  177. package/out/overlap/country-airport.js +13 -12
  178. package/out/overlap/country-airport.js.map +1 -1
  179. package/out/rgy1/base64.d.ts +0 -4
  180. package/out/rgy1/base64.d.ts.map +1 -1
  181. package/out/rgy1/base64.js +2 -4
  182. package/out/rgy1/base64.js.map +1 -1
  183. package/out/rgy1/reader.d.ts +0 -11
  184. package/out/rgy1/reader.d.ts.map +1 -1
  185. package/out/rgy1/reader.js +7 -7
  186. package/out/rgy1/reader.js.map +1 -1
  187. package/out/rgy1/sections.generated.d.ts +3 -5
  188. package/out/rgy1/sections.generated.d.ts.map +1 -1
  189. package/out/rgy1/sections.generated.js +5 -5
  190. package/out/rgy1/sections.generated.js.map +1 -1
  191. package/out/rgy1/views.d.ts +2 -9
  192. package/out/rgy1/views.d.ts.map +1 -1
  193. package/out/rgy1/views.js +4 -6
  194. package/out/rgy1/views.js.map +1 -1
  195. package/out/sdk/fetch.d.ts +6 -6
  196. package/out/sdk/fetch.d.ts.map +1 -1
  197. package/out/sdk/fetch.js +23 -11
  198. package/out/sdk/fetch.js.map +1 -1
  199. package/out/sdk/fetch.run.d.ts +0 -12
  200. package/out/sdk/fetch.run.d.ts.map +1 -1
  201. package/out/sdk/fetch.run.js +22 -9
  202. package/out/sdk/fetch.run.js.map +1 -1
  203. package/out/sdk/sources.d.ts +7 -16
  204. package/out/sdk/sources.d.ts.map +1 -1
  205. package/out/sdk/sources.js +34 -14
  206. package/out/sdk/sources.js.map +1 -1
  207. package/out/tools/artifact-path.d.ts +0 -5
  208. package/out/tools/artifact-path.d.ts.map +1 -1
  209. package/out/tools/artifact-path.js +2 -5
  210. package/out/tools/artifact-path.js.map +1 -1
  211. package/out/tools/bench.run.d.ts +0 -17
  212. package/out/tools/bench.run.d.ts.map +1 -1
  213. package/out/tools/bench.run.js +13 -10
  214. package/out/tools/bench.run.js.map +1 -1
  215. package/out/tools/build-wasm.run.d.ts +0 -16
  216. package/out/tools/build-wasm.run.d.ts.map +1 -1
  217. package/out/tools/build-wasm.run.js +8 -10
  218. package/out/tools/build-wasm.run.js.map +1 -1
  219. package/out/tools/generate-sections.run.d.ts +0 -11
  220. package/out/tools/generate-sections.run.d.ts.map +1 -1
  221. package/out/tools/generate-sections.run.js +5 -14
  222. package/out/tools/generate-sections.run.js.map +1 -1
  223. package/out/tools/generate.run.d.ts +0 -16
  224. package/out/tools/generate.run.d.ts.map +1 -1
  225. package/out/tools/generate.run.js +61 -17
  226. package/out/tools/generate.run.js.map +1 -1
  227. package/out/tools/language-subtags.d.ts +59 -0
  228. package/out/tools/language-subtags.d.ts.map +1 -0
  229. package/out/tools/language-subtags.js +145 -0
  230. package/out/tools/language-subtags.js.map +1 -0
  231. package/out/tools/normalize.d.ts +4 -14
  232. package/out/tools/normalize.d.ts.map +1 -1
  233. package/out/tools/normalize.js +14 -14
  234. package/out/tools/normalize.js.map +1 -1
  235. package/out/tools/normalize.run.d.ts +0 -12
  236. package/out/tools/normalize.run.d.ts.map +1 -1
  237. package/out/tools/normalize.run.js +24 -7
  238. package/out/tools/normalize.run.js.map +1 -1
  239. package/out/types.d.ts +62 -7
  240. package/out/types.d.ts.map +1 -1
  241. package/out/types.js +12 -9
  242. package/out/types.js.map +1 -1
  243. package/out/wasm.d.ts +0 -13
  244. package/out/wasm.d.ts.map +1 -1
  245. package/out/wasm.js +10 -9
  246. package/out/wasm.js.map +1 -1
  247. package/package.json +12 -4
  248. package/sdk/fetch.run.ts +25 -9
  249. package/sdk/fetch.ts +32 -12
  250. package/sdk/sources.ts +36 -14
  251. package/tools/artifact-path.ts +2 -5
  252. package/tools/bench.run.ts +19 -10
  253. package/tools/build-wasm.run.ts +9 -10
  254. package/tools/generate-sections.run.ts +6 -14
  255. package/tools/generate.run.ts +68 -17
  256. package/tools/language-subtags.ts +195 -0
  257. package/tools/normalize.run.ts +28 -7
  258. package/tools/normalize.ts +16 -15
@@ -0,0 +1,124 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * The ISO 15924 script of a code point, from the Unicode Script property of the runtime.
6
+ *
7
+ * The answer is the registry's own code: `Latn`, `Grek`, `Hani`, `Deva`.
8
+ * `Zyyy` marks a Common code point (digits and punctuation), `Zinh` an Inherited one
9
+ * (a combining mark), and `Zzzz` a code point that has no script in the runtime's Unicode version.
10
+ *
11
+ * # The Unicode version is the runtime's
12
+ *
13
+ * The tables are the regular-expression engine's `\p{Script=…}` classes, so they add no byte to a bundle.
14
+ * The answer for a code point that a later Unicode version assigned depends on
15
+ * the runtime that runs the call: a Worker, a browser and Node can report `Zzzz`
16
+ * for a script that a newer one reports by name.
17
+ *
18
+ * The test of this module pins the answers for a fixed list of code points.
19
+ *
20
+ * The candidates are the registry's script codes that the runtime's regular-expression
21
+ * engine also names as a Script value, so the set follows both tables.
22
+ * A code point of a Unicode script that the registry omits reports `Zzzz`.
23
+ *
24
+ * The lookup costs one array read for ASCII, and one cached read for a code point seen before.
25
+ */
26
+
27
+ import { scriptSubtagRows } from "#artifacts/bcp47/script"
28
+ import type { BCP47 } from "#types"
29
+
30
+ /**
31
+ * The scripts tried first, because most addresses are written in them.
32
+ * The rest follow in the registry's order.
33
+ */
34
+ const COMMON_FIRST = [
35
+ "Zyyy",
36
+ "Zinh",
37
+ "Latn",
38
+ "Hani",
39
+ "Cyrl",
40
+ "Arab",
41
+ "Hang",
42
+ "Hira",
43
+ "Kana",
44
+ "Grek",
45
+ "Deva",
46
+ "Thai",
47
+ "Hebr",
48
+ ]
49
+
50
+ /**
51
+ * The most code points the cache holds before it starts again.
52
+ */
53
+ const CACHE_LIMIT = 65_536
54
+
55
+ let matcher: { readonly pattern: RegExp; readonly codes: readonly BCP47.ScriptCode[] } | null = null
56
+
57
+ const cache = new Map<number, BCP47.ScriptCode>()
58
+
59
+ function isScriptValue(code: string): boolean {
60
+ try {
61
+ new RegExp(`\\p{Script=${code}}`, "u")
62
+
63
+ return true
64
+ } catch {
65
+ return false
66
+ }
67
+ }
68
+
69
+ function build(): NonNullable<typeof matcher> {
70
+ const known = scriptSubtagRows()
71
+ .map((row) => row.subtag)
72
+ .filter((code) => /^[A-Z][a-z]{3}$/.test(code) && isScriptValue(code))
73
+
74
+ const present = new Set(known)
75
+ const first = COMMON_FIRST.filter((code) => present.has(code))
76
+ const codes = [...first, ...known.filter((code) => !first.includes(code))] as BCP47.ScriptCode[]
77
+
78
+ // Each script is one capture group, so one `exec` reports which group matched.
79
+ const pattern = new RegExp(codes.map((code) => `(\\p{Script=${code}})`).join("|"), "u")
80
+
81
+ return { pattern, codes }
82
+ }
83
+
84
+ /**
85
+ * The ISO 15924 script of a code point.
86
+ *
87
+ * @param codePoint A Unicode scalar value, from 0 to 0x10FFFF.
88
+ * @returns `Zyyy` for Common, `Zinh` for Inherited, and `Zzzz` when the runtime
89
+ * assigns the code point no registry script.
90
+ */
91
+ export function codePointScript(codePoint: number): BCP47.ScriptCode {
92
+ if (codePoint < 0x80) {
93
+ const lower = codePoint | 0x20
94
+
95
+ return (lower >= 0x61 && lower <= 0x7a ? "Latn" : "Zyyy") as BCP47.ScriptCode
96
+ }
97
+
98
+ const cached = cache.get(codePoint)
99
+
100
+ if (cached) return cached
101
+
102
+ matcher ??= build()
103
+
104
+ const found = matcher.pattern.exec(String.fromCodePoint(codePoint))
105
+ let script: BCP47.ScriptCode = "Zzzz" as BCP47.ScriptCode
106
+
107
+ if (found) {
108
+ for (let group = 1; group < found.length; group++) {
109
+ if (found[group] !== undefined) {
110
+ script = matcher.codes[group - 1]!
111
+
112
+ break
113
+ }
114
+ }
115
+ }
116
+
117
+ if (cache.size >= CACHE_LIMIT) {
118
+ cache.clear()
119
+ }
120
+
121
+ cache.set(codePoint, script)
122
+
123
+ return script
124
+ }
@@ -1,10 +1,10 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * The strict alpha-2 country-code predicate over the `iso3166-1-alpha2-membership` bitset.
5
6
  *
6
- * The strict alpha-2 country-code predicate over the `iso3166-1-alpha2-membership` bitset. An import of it retains
7
- * that 85-byte bitset and the reader, and no name, airport or record.
7
+ * An import of it retains that 85-byte bitset and the reader, and no name, airport or record.
8
8
  */
9
9
 
10
10
  import { iso31661Alpha2MembershipArtifact } from "#artifacts/iso3166-1/alpha2-membership"
@@ -1,10 +1,10 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * The strict alpha-3 country-code predicate over the `iso3166-1-alpha3-membership` bitset.
5
6
  *
6
- * The strict alpha-3 country-code predicate over the `iso3166-1-alpha3-membership` bitset. An import of it retains
7
- * that 2,197-byte bitset and the reader, and no name, airport or record.
7
+ * An import of it retains that 2,197-byte bitset and the reader, and no name, airport or record.
8
8
  */
9
9
 
10
10
  import { iso31661Alpha3MembershipArtifact } from "#artifacts/iso3166-1/alpha3-membership"
@@ -31,7 +31,7 @@ export function alpha3Membership(): BitsetView {
31
31
  * `AUS` is one.
32
32
  * `aus` and `AU` are not.
33
33
  *
34
- * A former code such as `DDR` is not: the records artifact still describes it.
34
+ * A former code such as `DDR` isn't: the records artifact still describes it.
35
35
  */
36
36
  export function isCountryCodeAlpha3(input: string): input is ISO.CountryCode_3166_1_Alpha3 {
37
37
  return alpha3Membership().test(encode3(input))
@@ -1,13 +1,14 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * Country record retrieval over the `iso3166-1-records` artifact: three id tables, six columns and a string pool.
5
+ * Country record retrieval over the `iso3166-1-records` artifact: three id tables,
6
+ * six columns and a string pool.
7
7
  *
8
- * A record is materialized on request and cached by row, so a repeated read of one country returns one object. The
9
- * artifact holds every status; `getCountry*` answers a record of any status and reports it, while the brands and the
10
- * membership predicates cover officially assigned codes only.
8
+ * A record is materialized on request and cached by row, so a repeated read
9
+ * of one country returns one object.
10
+ * The artifact holds every status; `getCountry*` answers a record of any status and reports it,
11
+ * while the brands and the membership predicates cover officially assigned codes only.
11
12
  */
12
13
 
13
14
  import { iso31661RecordsArtifact } from "#artifacts/iso3166-1/records"
@@ -1,9 +1,9 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
- * The code-equivalence relations of one country entity: alpha-2, alpha-3 and numeric codes of the same record.
5
+ * The code-equivalence relations of one country entity: alpha-2, alpha-3
6
+ * and numeric codes of the same record.
7
7
  */
8
8
 
9
9
  import { getCountryByAlpha2, getCountryByAlpha3, getCountryByNumeric } from "#iso3166/records"
@@ -0,0 +1,88 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
4
+ /**
5
+ * ISO 639 language subtags, read from the language subtags of the IANA Language Subtag Registry.
6
+ *
7
+ * The registry holds one subtag per language: the ISO 639-1 two-letter code
8
+ * where one exists, and otherwise the ISO 639-2, 639-3 or 639-5 three-letter code.
9
+ * Japanese is `ja` and never `jpn`; Cantonese is `yue`.
10
+ */
11
+
12
+ import { languageSubtagRows } from "#artifacts/bcp47/language"
13
+ import { lazySubtagIndex } from "#bcp47/subtag-index"
14
+ import { type Parsed, ParseFailure } from "#errors"
15
+ import type { BCP47 } from "#types"
16
+
17
+ const index = lazySubtagIndex(languageSubtagRows)
18
+
19
+ const CANONICAL = /^[a-z]{2,3}$/
20
+ const LETTERS = /^[A-Za-z]{2,3}$/
21
+
22
+ /**
23
+ * One language as the registry describes it.
24
+ */
25
+ export interface LanguageRecord {
26
+ subtag: BCP47.LanguageSubtag
27
+ /**
28
+ * The registry's first description, such as `Japanese`.
29
+ */
30
+ name: string
31
+ descriptions: readonly string[]
32
+ /**
33
+ * The script a tag for this language leaves implied, such as `Jpan` for `ja`, or `null`.
34
+ */
35
+ suppressScript: string | null
36
+ /**
37
+ * The macrolanguage this language is a member of, such as `zh` for `yue`, or `null`.
38
+ */
39
+ macrolanguage: string | null
40
+ /**
41
+ * `macrolanguage`, `collection`, `special` or `private-use`, or `null` for an individual language.
42
+ */
43
+ scope: string | null
44
+ deprecated: string | null
45
+ preferredValue: string | null
46
+ }
47
+
48
+ /**
49
+ * Whether `input` is a language subtag the registry holds, in lowercase.
50
+ */
51
+ export function isLanguageSubtag(input: string): input is BCP47.LanguageSubtag {
52
+ return CANONICAL.test(input) && index().get(input) !== null
53
+ }
54
+
55
+ /**
56
+ * The branded language subtag, or the reason the input was refused.
57
+ */
58
+ export function parseLanguageSubtag(input: string): Parsed<BCP47.LanguageSubtag> {
59
+ if (!LETTERS.test(input)) return { ok: false, reason: ParseFailure.Shape, input }
60
+
61
+ if (!CANONICAL.test(input)) return { ok: false, reason: ParseFailure.Case, input }
62
+
63
+ if (!isLanguageSubtag(input)) return { ok: false, reason: ParseFailure.NotFound, input }
64
+
65
+ return { ok: true, value: input }
66
+ }
67
+
68
+ /**
69
+ * The record of a lowercase language subtag, or `null`.
70
+ */
71
+ export function getLanguage(subtag: string): LanguageRecord | null {
72
+ if (!CANONICAL.test(subtag)) return null
73
+
74
+ const row = index().get(subtag)
75
+
76
+ if (!row) return null
77
+
78
+ return {
79
+ subtag: subtag as BCP47.LanguageSubtag,
80
+ name: row.descriptions[0] ?? subtag,
81
+ descriptions: row.descriptions,
82
+ suppressScript: row.suppressScript ?? null,
83
+ macrolanguage: row.macrolanguage ?? null,
84
+ scope: row.scope ?? null,
85
+ deprecated: row.deprecated ?? null,
86
+ preferredValue: row.preferredValue ?? null,
87
+ }
88
+ }
package/lib/key.ts CHANGED
@@ -1,13 +1,15 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * Key encodings: the position of a code in its direct-address key space,
6
+ * mirroring `crates/registry-core/src/key.rs`.
5
7
  *
6
- * Key encodings: the position of a code in its direct-address key space, mirroring `crates/registry-core/src/key.rs`.
8
+ * Two or three upper-case ASCII letters encode base-26 with the first letter in the highest place.
9
+ * A three-digit numeric code encodes as its decimal value.
7
10
  *
8
- * Two or three upper-case ASCII letters encode base-26 with the first letter in the highest place. A three-digit
9
- * numeric code encodes as its decimal value. Every encoder checks length and alphabet first and answers `-1` for
10
- * anything else. A caller normalizes case or whitespace before calling, never here.
11
+ * Every encoder checks length and alphabet first and answers `-1` for anything else.
12
+ * A caller normalizes case or whitespace before calling, never here.
11
13
  */
12
14
 
13
15
  /**
package/lib/normalize.ts CHANGED
@@ -1,14 +1,18 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
5
  * Explicit input normalization, separate from the strict predicates.
7
6
  *
8
- * `canonicalSpelling` trims ASCII whitespace and upper-cases ASCII letters. It reports each change. A caller who
9
- * wants `" aus "` to reach `AUS` asks for that step. Every other character stays as written. A dot, a dash or a
10
- * non-ASCII letter reaches the strict predicate unchanged and is refused there with `shape`. Free-text tokenization
11
- * belongs to Mailwoman, outside this package.
7
+ * `canonicalSpelling` trims ASCII whitespace and upper-cases ASCII letters.
8
+ * It reports each change.
9
+ *
10
+ * A caller who wants `" aus "` to reach `AUS` asks for that step.
11
+ * Every other character stays as written.
12
+ *
13
+ * A dot, a dash or a non-ASCII letter reaches the strict predicate unchanged
14
+ * and is refused there with `shape`.
15
+ * Free-text tokenization belongs to Mailwoman, outside this package.
12
16
  */
13
17
 
14
18
  /**
@@ -1,16 +1,18 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * The country/airport collision index: codes that are both an officially assigned
6
+ * ISO 3166-1 alpha-3 code and an IATA airport code in the profile.
5
7
  *
6
- * The country/airport collision index: codes that are both an officially assigned ISO 3166-1 alpha-3 code and an
7
- * IATA airport code in the profile.
8
+ * `isCountryAirportCollision` reads only the 2,197-byte collision bitset.
9
+ * `interpretCountryOrAirportCode` reads the records artifacts and answers every
10
+ * interpretation as a discriminated union, each branch with its own brand and entity,
11
+ * so `AUS` is Australia under one namespace and an airport in the United States under another.
8
12
  *
9
- * `isCountryAirportCollision` reads only the 2,197-byte collision bitset. `interpretCountryOrAirportCode` reads the
10
- * records artifacts and answers every interpretation as a discriminated union, each branch with its own brand and
11
- * entity, so `AUS` is Australia under one namespace and an airport in the United States under another. The two
12
- * relations are separate: `same-spelling-as` is the collision, `located-in` is each branch's `country`. The caller
13
- * ranks the interpretations, and the resolver in Mailwoman does it.
13
+ * The two relations are separate: `same-spelling-as` is the collision,
14
+ * `located-in` is each branch's `country`.
15
+ * The caller ranks the interpretations, and the resolver in Mailwoman does it.
14
16
  */
15
17
 
16
18
  import { countryAirportCollisionArtifact } from "#artifacts/country-airport-collision"
@@ -69,9 +71,9 @@ export type CodeMatch =
69
71
  /**
70
72
  * Every namespace that holds the spelling, in namespace order: country first, then airport.
71
73
  *
72
- * The order is the namespace list's and is not a ranking.
74
+ * The order is the namespace list's and isn't a ranking.
73
75
  * An empty array is `not-found-in-snapshot` in every namespace, and a former country code
74
- * is not an interpretation here because the current-assignment brand leaves it out.
76
+ * isn't an interpretation here because the current-assignment brand leaves it out.
75
77
  */
76
78
  export function interpretCountryOrAirportCode(input: string): CodeMatch[] {
77
79
  const matches: CodeMatch[] = []
@@ -1,8 +1,7 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
5
  * Decodes a generated artifact module's base64 text into bytes, on the platforms the readers run on.
7
6
  */
8
7
 
@@ -1,13 +1,14 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
5
  * The synchronous RGY1 reader: validate an artifact once, then probe its tables in place.
7
6
  *
8
- * The reader mirrors `crates/registry-core/src/artifact.rs` and follows `docs/rgy1.md`. It reads through a
9
- * `DataView` over the caller's bytes, honoring `byteOffset`, so an artifact handed over as a subarray behaves as the
10
- * same bytes would in their own buffer. No `Map` is rebuilt: a probe is an arithmetic index into the section's payload.
7
+ * The reader mirrors `crates/registry-core/src/artifact.rs` and follows `docs/rgy1.md`.
8
+ * It reads through a `DataView` over the caller's bytes, honoring `byteOffset`, so an
9
+ * artifact handed over as a subarray behaves as the same bytes would in their own buffer.
10
+ *
11
+ * No `Map` is rebuilt: a probe is an arithmetic index into the section's payload.
11
12
  */
12
13
 
13
14
  import {
@@ -1,10 +1,11 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * The RGY1 section kinds.
5
6
  *
6
- * The RGY1 section kinds. Generated from definitions/sections.json by tools/generate-sections.run.ts. Edit the
7
- * definition rather than this file.
7
+ * Generated from definitions/sections.json by tools/generate-sections.run.ts.
8
+ * Edit the definition rather than this file.
8
9
  */
9
10
 
10
11
  /**
package/lib/rgy1/views.ts CHANGED
@@ -1,8 +1,7 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
5
  * Typed views over an artifact's sections: bitset, id table, column, string pool and relation.
7
6
  */
8
7
 
@@ -33,7 +32,7 @@ export class BitsetView {
33
32
 
34
33
  /**
35
34
  * Whether `key` is a member.
36
- * A key outside the space is not.
35
+ * A key outside the space isn't.
37
36
  */
38
37
  test(key: number): boolean {
39
38
  if (key < 0) return false
@@ -45,7 +44,7 @@ export class BitsetView {
45
44
 
46
45
  /**
47
46
  * Whether a code in its canonical spelling is a member.
48
- * A code outside the grammar is not.
47
+ * A code outside the grammar isn't.
49
48
  */
50
49
  contains(code: string): boolean {
51
50
  return this.test(encodeForArity(this.arity, code))
package/lib/types.ts CHANGED
@@ -1,13 +1,14 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
+ * Branded identifier types.
5
6
  *
6
- * Branded identifier types. A brand is a declaration-only unique symbol, so a branded value is a plain string at
7
- * runtime and the compiler refuses to pass one namespace's code where another's is expected.
7
+ * A brand is a declaration-only unique symbol, so a branded value is a plain string at runtime
8
+ * and the compiler refuses to pass one namespace's code where another's is expected.
8
9
  *
9
- * A branded value records that a validator accepted it under a documented profile at the time of the call. The
10
- * issuing authority's later assignments are outside what the brand records.
10
+ * A branded value records that a validator accepted it under a documented profile at the time of the call.
11
+ * The issuing authority's later assignments are outside what the brand records.
11
12
  */
12
13
 
13
14
  /**
@@ -69,6 +70,64 @@ export declare namespace ICAO {
69
70
  type LocationIndicator = string & { readonly [$LocationIndicator]: true }
70
71
  }
71
72
 
73
+ /**
74
+ * BCP 47 namespaces, read from the IANA Language Subtag Registry.
75
+ */
76
+ export declare namespace BCP47 {
77
+ const $LanguageTag: unique symbol
78
+ const $ScriptCode: unique symbol
79
+ const $LanguageSubtag: unique symbol
80
+
81
+ /**
82
+ * A well-formed, valid BCP 47 tag in canonical form, such as `ja-Jpan-JP` or `en-GB`.
83
+ */
84
+ type LanguageTag = string & { readonly [$LanguageTag]: true }
85
+
86
+ /**
87
+ * An ISO 15924 script code the registry holds, in its canonical title case, such as `Latn` or `Jpan`.
88
+ */
89
+ type ScriptCode = string & { readonly [$ScriptCode]: true }
90
+
91
+ /**
92
+ * An ISO 639 language subtag the registry holds, in lowercase, such as `ja` or `yue`.
93
+ */
94
+ type LanguageSubtag = string & { readonly [$LanguageSubtag]: true }
95
+ }
96
+
97
+ /**
98
+ * The subtag types the IANA Language Subtag Registry defines.
99
+ */
100
+ export const SubtagType = {
101
+ Language: "language",
102
+ Extlang: "extlang",
103
+ Script: "script",
104
+ Region: "region",
105
+ Variant: "variant",
106
+ Grandfathered: "grandfathered",
107
+ Redundant: "redundant",
108
+ } as const
109
+
110
+ export type SubtagType = (typeof SubtagType)[keyof typeof SubtagType]
111
+
112
+ /**
113
+ * One registry record as a table module holds it.
114
+ *
115
+ * `subtag` holds the subtag for the five subtag types and the whole tag for `grandfathered` and `redundant`.
116
+ * A private-use range keeps its range spelling, such as `qaa..qtz`.
117
+ *
118
+ * Each table holds one subtag type, so a row leaves its type out.
119
+ */
120
+ export interface SubtagRow {
121
+ subtag: string
122
+ descriptions: string[]
123
+ deprecated?: string
124
+ preferredValue?: string
125
+ suppressScript?: string
126
+ macrolanguage?: string
127
+ scope?: string
128
+ prefixes?: string[]
129
+ }
130
+
72
131
  /**
73
132
  * The status a country record holds.
74
133
  */
package/lib/wasm.ts CHANGED
@@ -1,15 +1,17 @@
1
+ // SPDX-FileCopyrightText: Teffen Ellis and Mailwoman contributors
2
+ // SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial
3
+
1
4
  /**
2
- * @copyright Sister Software
3
- * @license AGPL-3.0
4
- * @author Teffen Ellis, et al.
5
- *
6
5
  * The WebAssembly batch adapter over `crates/registry-wasm`.
7
6
  *
8
- * Initialization is explicit: the caller passes the module's bytes or a compiled `WebAssembly.Module`, and this
9
- * module compiles the module inside `createRegistry` and at no other time. `registryWasmURL` locates the committed
10
- * binaries for a caller that loads them itself, and `preferredWasmVariant` reports whether the host runs `simd128`.
11
- * A batch call stages the packed codes in linear memory, crosses the boundary once, and copies the masks into the
12
- * caller's buffer. The staging buffers are kept and reused while they are large enough.
7
+ * Initialization is explicit: the caller passes the module's bytes or a compiled `WebAssembly.Module`,
8
+ * and this module compiles the module inside `createRegistry` and at no other time.
9
+ * `registryWasmURL` locates the committed binaries for a caller that loads them itself,
10
+ * and `preferredWasmVariant` reports whether the host runs `simd128`.
11
+ *
12
+ * A batch call stages the packed codes in linear memory, crosses the boundary once,
13
+ * and copies the masks into the caller's buffer.
14
+ * The staging buffers are kept and reused while they're large enough.
13
15
  */
14
16
 
15
17
  import { countryAirportCollisionArtifact } from "#artifacts/country-airport-collision"
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The `bcp47-extlang-subtags` table of the `open-2026-11` profile, 258 rows,
3
+ * read from the IANA Language Subtag Registry of File-Date 2026-09-17.
4
+ *
5
+ * The rows live in `./extlang.fixture.json`,
6
+ * SHA-256 afd04073183f12bd2d441296a9a096b536089bc69d678796f4fca91dab8b0cf8.
7
+ * Generated by tools/generate.run.ts from data/normalized.
8
+ * Edit the data or the generator rather than this file.
9
+ */
10
+ import type { SubtagRow } from "#types";
11
+ /**
12
+ * Returns the table's rows.
13
+ *
14
+ * Callers read the rows and never write them.
15
+ */
16
+ export declare function extlangSubtagRows(): readonly SubtagRow[];
17
+ /**
18
+ * The registry edition the table was read from.
19
+ */
20
+ export declare const EXTLANG_SUBTAGS_FILE_DATE = "2026-09-17";
21
+ //# sourceMappingURL=extlang.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extlang.d.ts","sourceRoot":"","sources":["../../../lib/artifacts/bcp47/extlang.ts"],"names":[],"mappings":"AAGA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAMvC;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,SAAS,SAAS,EAAE,CAExD;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,eAAe,CAAA"}