@fgv/ts-bcp47 5.0.0-2 → 5.0.0-21

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 (314) hide show
  1. package/.vscode/settings.json +58 -0
  2. package/config/api-extractor.json +343 -0
  3. package/config/rig.json +16 -0
  4. package/dist/tsdoc-metadata.json +1 -1
  5. package/lib/packlets/iana/jar/language-subtags/tags/converters.js +1 -0
  6. package/lib/test/data/iana/language-subtag-registry.json +57435 -0
  7. package/lib/test/data/iana/language-tag-extension-registry.json +38 -0
  8. package/lib/test/unit/bcp47/bcp47Tags/validate.test.d.ts +2 -0
  9. package/lib/test/unit/bcp47/canonicalTag.test.d.ts +2 -0
  10. package/lib/test/unit/bcp47/common.test.d.ts +2 -0
  11. package/lib/test/unit/bcp47/commonTestCases.d.ts +5 -0
  12. package/lib/test/unit/bcp47/commonTestCases.js +478 -0
  13. package/lib/test/unit/bcp47/helpers.test.d.ts +2 -0
  14. package/lib/test/unit/bcp47/languageRegistryData.test.d.ts +2 -0
  15. package/lib/test/unit/bcp47/languageTag.test.d.ts +2 -0
  16. package/lib/test/unit/bcp47/languageTagHelpers.d.ts +70 -0
  17. package/lib/test/unit/bcp47/languageTagHelpers.js +184 -0
  18. package/lib/test/unit/bcp47/match/chooser.test.d.ts +2 -0
  19. package/lib/test/unit/bcp47/match/similarity.test.d.ts +2 -0
  20. package/lib/test/unit/bcp47/normalizeTag.test.d.ts +2 -0
  21. package/lib/test/unit/bcp47/overrides.test.d.ts +2 -0
  22. package/lib/test/unit/bcp47/validTag.test.d.ts +2 -0
  23. package/lib/test/unit/bcp47/validateTag.test.d.ts +2 -0
  24. package/lib/test/unit/bcp47/wellFormedTag.test.d.ts +2 -0
  25. package/lib/test/unit/examples.test.d.ts +2 -0
  26. package/lib/test/unit/iana/common/datedRegistry.test.d.ts +2 -0
  27. package/lib/test/unit/iana/common/validate.test.d.ts +2 -0
  28. package/lib/test/unit/iana/jar/jarConverters.test.d.ts +2 -0
  29. package/lib/test/unit/iana/jar/language-subtags/tags/converters.test.d.ts +2 -0
  30. package/lib/test/unit/iana/jar/language-subtags/tags/validate.test.d.ts +2 -0
  31. package/lib/test/unit/iana/language-subtags/data.test.d.ts +2 -0
  32. package/lib/test/unit/iana/language-subtags/jarConverters.test.d.ts +2 -0
  33. package/lib/test/unit/iana/language-subtags/registry.test.d.ts +2 -0
  34. package/lib/test/unit/iana/language-subtags/scope.test.d.ts +2 -0
  35. package/lib/test/unit/iana/language-tag-extensions/extensionsRegistry.test.d.ts +2 -0
  36. package/lib/test/unit/iana/language-tag-extensions/validate.test.d.ts +2 -0
  37. package/lib/test/unit/unsd/csv.test.d.ts +2 -0
  38. package/lib/test/unit/unsd/regionCodes.test.d.ts +2 -0
  39. package/package.json +20 -20
  40. package/src/data/bcp/overrides.json +20 -0
  41. package/src/data/iana/language-subtags.json +57439 -0
  42. package/src/data/iana/language-tag-extensions.json +38 -0
  43. package/src/data/unsd/m49.json +3723 -0
  44. package/src/index.ts +29 -0
  45. package/src/packlets/bcp47/bcp47Subtags/converters.ts +33 -0
  46. package/src/packlets/bcp47/bcp47Subtags/index.ts +27 -0
  47. package/src/packlets/bcp47/bcp47Subtags/model.ts +46 -0
  48. package/src/packlets/bcp47/bcp47Subtags/validate.ts +55 -0
  49. package/src/packlets/bcp47/common.ts +85 -0
  50. package/src/packlets/bcp47/helpers.ts +117 -0
  51. package/src/packlets/bcp47/index.ts +38 -0
  52. package/src/packlets/bcp47/languageRegistryData.ts +304 -0
  53. package/src/packlets/bcp47/languageTag.ts +467 -0
  54. package/src/packlets/bcp47/languageTagParser.ts +307 -0
  55. package/src/packlets/bcp47/match/chooser.ts +164 -0
  56. package/src/packlets/bcp47/match/common.ts +57 -0
  57. package/src/packlets/bcp47/match/index.ts +26 -0
  58. package/src/packlets/bcp47/match/similarity.ts +243 -0
  59. package/src/packlets/bcp47/normalization/baseNormalizer.ts +146 -0
  60. package/src/packlets/bcp47/normalization/canonicalNormalizer.ts +102 -0
  61. package/src/packlets/bcp47/normalization/common.ts +84 -0
  62. package/src/packlets/bcp47/normalization/index.ts +27 -0
  63. package/src/packlets/bcp47/normalization/normalizeTag.ts +116 -0
  64. package/src/packlets/bcp47/normalization/preferredTagNormalizer.ts +213 -0
  65. package/src/packlets/bcp47/overrides/converters.ts +58 -0
  66. package/src/packlets/bcp47/overrides/defaultRegistries.ts +40 -0
  67. package/src/packlets/bcp47/overrides/index.ts +25 -0
  68. package/src/packlets/bcp47/overrides/model.ts +33 -0
  69. package/src/packlets/bcp47/overrides/overridesRegistry.ts +104 -0
  70. package/src/packlets/bcp47/validation/baseValidator.ts +132 -0
  71. package/src/packlets/bcp47/validation/common.ts +86 -0
  72. package/src/packlets/bcp47/validation/index.ts +29 -0
  73. package/src/packlets/bcp47/validation/isCanonical.ts +103 -0
  74. package/src/packlets/bcp47/validation/isInPreferredForm.ts +53 -0
  75. package/src/packlets/bcp47/validation/isStrictlyValid.ts +117 -0
  76. package/src/packlets/bcp47/validation/isValid.ts +122 -0
  77. package/src/packlets/bcp47/validation/isWellFormed.ts +102 -0
  78. package/src/packlets/bcp47/validation/validateTag.ts +175 -0
  79. package/src/packlets/iana/common/converters.ts +67 -0
  80. package/src/packlets/iana/common/model.ts +56 -0
  81. package/src/packlets/iana/common/registeredItems.ts +145 -0
  82. package/src/packlets/iana/common/utils.ts +32 -0
  83. package/src/packlets/iana/common/validate.ts +64 -0
  84. package/src/packlets/iana/converters.ts +26 -0
  85. package/src/packlets/iana/defaultRegistries.ts +40 -0
  86. package/src/packlets/iana/index.ts +33 -0
  87. package/src/packlets/iana/jar/converters.ts +26 -0
  88. package/src/packlets/iana/jar/index.ts +27 -0
  89. package/src/packlets/iana/jar/jarConverters.ts +70 -0
  90. package/src/packlets/iana/jar/jarModel.ts +34 -0
  91. package/src/packlets/iana/jar/language-subtags/converters.ts +26 -0
  92. package/src/packlets/iana/jar/language-subtags/index.ts +27 -0
  93. package/src/packlets/iana/jar/language-subtags/model.ts +26 -0
  94. package/src/packlets/iana/jar/language-subtags/registry/converters.ts +40 -0
  95. package/src/packlets/iana/jar/language-subtags/registry/index.ts +26 -0
  96. package/src/packlets/iana/jar/language-subtags/registry/model.ts +171 -0
  97. package/src/packlets/iana/jar/language-subtags/tags/converters.ts +120 -0
  98. package/src/packlets/iana/jar/language-subtags/tags/index.ts +28 -0
  99. package/src/packlets/iana/jar/language-subtags/tags/model.ts +71 -0
  100. package/src/packlets/iana/jar/language-subtags/tags/tagValidation.ts +67 -0
  101. package/src/packlets/iana/jar/language-subtags/tags/validate.ts +106 -0
  102. package/src/packlets/iana/jar/model.ts +26 -0
  103. package/src/packlets/iana/language-subtags/common.ts +46 -0
  104. package/src/packlets/iana/language-subtags/converters.ts +226 -0
  105. package/src/packlets/iana/language-subtags/index.ts +30 -0
  106. package/src/packlets/iana/language-subtags/jarConverters.ts +269 -0
  107. package/src/packlets/iana/language-subtags/model.ts +213 -0
  108. package/src/packlets/iana/language-subtags/scope.ts +222 -0
  109. package/src/packlets/iana/language-subtags/subtagRegistry.ts +136 -0
  110. package/src/packlets/iana/language-subtags/validate.ts +23 -0
  111. package/src/packlets/iana/language-tag-extensions/converters.ts +71 -0
  112. package/src/packlets/iana/language-tag-extensions/extensionsRegistry.ts +92 -0
  113. package/src/packlets/iana/language-tag-extensions/extensionsScope.ts +60 -0
  114. package/src/packlets/iana/language-tag-extensions/index.ts +29 -0
  115. package/src/packlets/iana/language-tag-extensions/jarConverters.ts +91 -0
  116. package/src/packlets/iana/language-tag-extensions/model.ts +67 -0
  117. package/src/packlets/iana/language-tag-extensions/validate.ts +36 -0
  118. package/src/packlets/iana/languageRegistries.ts +57 -0
  119. package/src/packlets/iana/model.ts +26 -0
  120. package/src/packlets/iana/validate.ts +23 -0
  121. package/src/packlets/unsd/areas.ts +105 -0
  122. package/src/packlets/unsd/common.ts +79 -0
  123. package/src/packlets/unsd/csv/converters.ts +82 -0
  124. package/src/packlets/unsd/csv/index.ts +26 -0
  125. package/src/packlets/unsd/csv/model.ts +44 -0
  126. package/src/packlets/unsd/defaultRegistries.ts +40 -0
  127. package/src/packlets/unsd/index.ts +28 -0
  128. package/src/packlets/unsd/regionCodes.ts +144 -0
  129. package/src/packlets/unsd/regions.ts +95 -0
  130. package/src/packlets/utils/index.ts +24 -0
  131. package/src/packlets/utils/jsonHelpers.ts +25 -0
  132. package/src/packlets/utils/public.ts +28 -0
  133. package/src/packlets/utils/validationHelpers.ts +180 -0
  134. package/CHANGELOG.md +0 -109
  135. package/lib/index.d.ts.map +0 -1
  136. package/lib/index.js.map +0 -1
  137. package/lib/packlets/bcp47/bcp47Subtags/converters.d.ts.map +0 -1
  138. package/lib/packlets/bcp47/bcp47Subtags/converters.js.map +0 -1
  139. package/lib/packlets/bcp47/bcp47Subtags/index.d.ts.map +0 -1
  140. package/lib/packlets/bcp47/bcp47Subtags/index.js.map +0 -1
  141. package/lib/packlets/bcp47/bcp47Subtags/model.d.ts.map +0 -1
  142. package/lib/packlets/bcp47/bcp47Subtags/model.js.map +0 -1
  143. package/lib/packlets/bcp47/bcp47Subtags/validate.d.ts.map +0 -1
  144. package/lib/packlets/bcp47/bcp47Subtags/validate.js.map +0 -1
  145. package/lib/packlets/bcp47/common.d.ts.map +0 -1
  146. package/lib/packlets/bcp47/common.js.map +0 -1
  147. package/lib/packlets/bcp47/helpers.d.ts.map +0 -1
  148. package/lib/packlets/bcp47/helpers.js.map +0 -1
  149. package/lib/packlets/bcp47/index.d.ts.map +0 -1
  150. package/lib/packlets/bcp47/index.js.map +0 -1
  151. package/lib/packlets/bcp47/languageRegistryData.d.ts.map +0 -1
  152. package/lib/packlets/bcp47/languageRegistryData.js.map +0 -1
  153. package/lib/packlets/bcp47/languageTag.d.ts.map +0 -1
  154. package/lib/packlets/bcp47/languageTag.js.map +0 -1
  155. package/lib/packlets/bcp47/languageTagParser.d.ts.map +0 -1
  156. package/lib/packlets/bcp47/languageTagParser.js.map +0 -1
  157. package/lib/packlets/bcp47/match/chooser.d.ts.map +0 -1
  158. package/lib/packlets/bcp47/match/chooser.js.map +0 -1
  159. package/lib/packlets/bcp47/match/common.d.ts.map +0 -1
  160. package/lib/packlets/bcp47/match/common.js.map +0 -1
  161. package/lib/packlets/bcp47/match/index.d.ts.map +0 -1
  162. package/lib/packlets/bcp47/match/index.js.map +0 -1
  163. package/lib/packlets/bcp47/match/similarity.d.ts.map +0 -1
  164. package/lib/packlets/bcp47/match/similarity.js.map +0 -1
  165. package/lib/packlets/bcp47/normalization/baseNormalizer.d.ts.map +0 -1
  166. package/lib/packlets/bcp47/normalization/baseNormalizer.js.map +0 -1
  167. package/lib/packlets/bcp47/normalization/canonicalNormalizer.d.ts.map +0 -1
  168. package/lib/packlets/bcp47/normalization/canonicalNormalizer.js.map +0 -1
  169. package/lib/packlets/bcp47/normalization/common.d.ts.map +0 -1
  170. package/lib/packlets/bcp47/normalization/common.js.map +0 -1
  171. package/lib/packlets/bcp47/normalization/index.d.ts.map +0 -1
  172. package/lib/packlets/bcp47/normalization/index.js.map +0 -1
  173. package/lib/packlets/bcp47/normalization/normalizeTag.d.ts.map +0 -1
  174. package/lib/packlets/bcp47/normalization/normalizeTag.js.map +0 -1
  175. package/lib/packlets/bcp47/normalization/preferredTagNormalizer.d.ts.map +0 -1
  176. package/lib/packlets/bcp47/normalization/preferredTagNormalizer.js.map +0 -1
  177. package/lib/packlets/bcp47/overrides/converters.d.ts.map +0 -1
  178. package/lib/packlets/bcp47/overrides/converters.js.map +0 -1
  179. package/lib/packlets/bcp47/overrides/defaultRegistries.d.ts.map +0 -1
  180. package/lib/packlets/bcp47/overrides/defaultRegistries.js.map +0 -1
  181. package/lib/packlets/bcp47/overrides/index.d.ts.map +0 -1
  182. package/lib/packlets/bcp47/overrides/index.js.map +0 -1
  183. package/lib/packlets/bcp47/overrides/model.d.ts.map +0 -1
  184. package/lib/packlets/bcp47/overrides/model.js.map +0 -1
  185. package/lib/packlets/bcp47/overrides/overridesRegistry.d.ts.map +0 -1
  186. package/lib/packlets/bcp47/overrides/overridesRegistry.js.map +0 -1
  187. package/lib/packlets/bcp47/validation/baseValidator.d.ts.map +0 -1
  188. package/lib/packlets/bcp47/validation/baseValidator.js.map +0 -1
  189. package/lib/packlets/bcp47/validation/common.d.ts.map +0 -1
  190. package/lib/packlets/bcp47/validation/common.js.map +0 -1
  191. package/lib/packlets/bcp47/validation/index.d.ts.map +0 -1
  192. package/lib/packlets/bcp47/validation/index.js.map +0 -1
  193. package/lib/packlets/bcp47/validation/isCanonical.d.ts.map +0 -1
  194. package/lib/packlets/bcp47/validation/isCanonical.js.map +0 -1
  195. package/lib/packlets/bcp47/validation/isInPreferredForm.d.ts.map +0 -1
  196. package/lib/packlets/bcp47/validation/isInPreferredForm.js.map +0 -1
  197. package/lib/packlets/bcp47/validation/isStrictlyValid.d.ts.map +0 -1
  198. package/lib/packlets/bcp47/validation/isStrictlyValid.js.map +0 -1
  199. package/lib/packlets/bcp47/validation/isValid.d.ts.map +0 -1
  200. package/lib/packlets/bcp47/validation/isValid.js.map +0 -1
  201. package/lib/packlets/bcp47/validation/isWellFormed.d.ts.map +0 -1
  202. package/lib/packlets/bcp47/validation/isWellFormed.js.map +0 -1
  203. package/lib/packlets/bcp47/validation/validateTag.d.ts.map +0 -1
  204. package/lib/packlets/bcp47/validation/validateTag.js.map +0 -1
  205. package/lib/packlets/iana/common/converters.d.ts.map +0 -1
  206. package/lib/packlets/iana/common/converters.js.map +0 -1
  207. package/lib/packlets/iana/common/model.d.ts.map +0 -1
  208. package/lib/packlets/iana/common/model.js.map +0 -1
  209. package/lib/packlets/iana/common/registeredItems.d.ts.map +0 -1
  210. package/lib/packlets/iana/common/registeredItems.js.map +0 -1
  211. package/lib/packlets/iana/common/utils.d.ts.map +0 -1
  212. package/lib/packlets/iana/common/utils.js.map +0 -1
  213. package/lib/packlets/iana/common/validate.d.ts.map +0 -1
  214. package/lib/packlets/iana/common/validate.js.map +0 -1
  215. package/lib/packlets/iana/converters.d.ts.map +0 -1
  216. package/lib/packlets/iana/converters.js.map +0 -1
  217. package/lib/packlets/iana/defaultRegistries.d.ts.map +0 -1
  218. package/lib/packlets/iana/defaultRegistries.js.map +0 -1
  219. package/lib/packlets/iana/index.d.ts.map +0 -1
  220. package/lib/packlets/iana/index.js.map +0 -1
  221. package/lib/packlets/iana/jar/converters.d.ts.map +0 -1
  222. package/lib/packlets/iana/jar/converters.js.map +0 -1
  223. package/lib/packlets/iana/jar/index.d.ts.map +0 -1
  224. package/lib/packlets/iana/jar/index.js.map +0 -1
  225. package/lib/packlets/iana/jar/jarConverters.d.ts.map +0 -1
  226. package/lib/packlets/iana/jar/jarConverters.js.map +0 -1
  227. package/lib/packlets/iana/jar/jarModel.d.ts.map +0 -1
  228. package/lib/packlets/iana/jar/jarModel.js.map +0 -1
  229. package/lib/packlets/iana/jar/language-subtags/converters.d.ts.map +0 -1
  230. package/lib/packlets/iana/jar/language-subtags/converters.js.map +0 -1
  231. package/lib/packlets/iana/jar/language-subtags/index.d.ts.map +0 -1
  232. package/lib/packlets/iana/jar/language-subtags/index.js.map +0 -1
  233. package/lib/packlets/iana/jar/language-subtags/model.d.ts.map +0 -1
  234. package/lib/packlets/iana/jar/language-subtags/model.js.map +0 -1
  235. package/lib/packlets/iana/jar/language-subtags/registry/converters.d.ts.map +0 -1
  236. package/lib/packlets/iana/jar/language-subtags/registry/converters.js.map +0 -1
  237. package/lib/packlets/iana/jar/language-subtags/registry/index.d.ts.map +0 -1
  238. package/lib/packlets/iana/jar/language-subtags/registry/index.js.map +0 -1
  239. package/lib/packlets/iana/jar/language-subtags/registry/model.d.ts.map +0 -1
  240. package/lib/packlets/iana/jar/language-subtags/registry/model.js.map +0 -1
  241. package/lib/packlets/iana/jar/language-subtags/tags/converters.d.ts.map +0 -1
  242. package/lib/packlets/iana/jar/language-subtags/tags/converters.js.map +0 -1
  243. package/lib/packlets/iana/jar/language-subtags/tags/index.d.ts.map +0 -1
  244. package/lib/packlets/iana/jar/language-subtags/tags/index.js.map +0 -1
  245. package/lib/packlets/iana/jar/language-subtags/tags/model.d.ts.map +0 -1
  246. package/lib/packlets/iana/jar/language-subtags/tags/model.js.map +0 -1
  247. package/lib/packlets/iana/jar/language-subtags/tags/tagValidation.d.ts.map +0 -1
  248. package/lib/packlets/iana/jar/language-subtags/tags/tagValidation.js.map +0 -1
  249. package/lib/packlets/iana/jar/language-subtags/tags/validate.d.ts.map +0 -1
  250. package/lib/packlets/iana/jar/language-subtags/tags/validate.js.map +0 -1
  251. package/lib/packlets/iana/jar/model.d.ts.map +0 -1
  252. package/lib/packlets/iana/jar/model.js.map +0 -1
  253. package/lib/packlets/iana/language-subtags/common.d.ts.map +0 -1
  254. package/lib/packlets/iana/language-subtags/common.js.map +0 -1
  255. package/lib/packlets/iana/language-subtags/converters.d.ts.map +0 -1
  256. package/lib/packlets/iana/language-subtags/converters.js.map +0 -1
  257. package/lib/packlets/iana/language-subtags/index.d.ts.map +0 -1
  258. package/lib/packlets/iana/language-subtags/index.js.map +0 -1
  259. package/lib/packlets/iana/language-subtags/jarConverters.d.ts.map +0 -1
  260. package/lib/packlets/iana/language-subtags/jarConverters.js.map +0 -1
  261. package/lib/packlets/iana/language-subtags/model.d.ts.map +0 -1
  262. package/lib/packlets/iana/language-subtags/model.js.map +0 -1
  263. package/lib/packlets/iana/language-subtags/scope.d.ts.map +0 -1
  264. package/lib/packlets/iana/language-subtags/scope.js.map +0 -1
  265. package/lib/packlets/iana/language-subtags/subtagRegistry.d.ts.map +0 -1
  266. package/lib/packlets/iana/language-subtags/subtagRegistry.js.map +0 -1
  267. package/lib/packlets/iana/language-subtags/validate.d.ts.map +0 -1
  268. package/lib/packlets/iana/language-subtags/validate.js.map +0 -1
  269. package/lib/packlets/iana/language-tag-extensions/converters.d.ts.map +0 -1
  270. package/lib/packlets/iana/language-tag-extensions/converters.js.map +0 -1
  271. package/lib/packlets/iana/language-tag-extensions/extensionsRegistry.d.ts.map +0 -1
  272. package/lib/packlets/iana/language-tag-extensions/extensionsRegistry.js.map +0 -1
  273. package/lib/packlets/iana/language-tag-extensions/extensionsScope.d.ts.map +0 -1
  274. package/lib/packlets/iana/language-tag-extensions/extensionsScope.js.map +0 -1
  275. package/lib/packlets/iana/language-tag-extensions/index.d.ts.map +0 -1
  276. package/lib/packlets/iana/language-tag-extensions/index.js.map +0 -1
  277. package/lib/packlets/iana/language-tag-extensions/jarConverters.d.ts.map +0 -1
  278. package/lib/packlets/iana/language-tag-extensions/jarConverters.js.map +0 -1
  279. package/lib/packlets/iana/language-tag-extensions/model.d.ts.map +0 -1
  280. package/lib/packlets/iana/language-tag-extensions/model.js.map +0 -1
  281. package/lib/packlets/iana/language-tag-extensions/validate.d.ts.map +0 -1
  282. package/lib/packlets/iana/language-tag-extensions/validate.js.map +0 -1
  283. package/lib/packlets/iana/languageRegistries.d.ts.map +0 -1
  284. package/lib/packlets/iana/languageRegistries.js.map +0 -1
  285. package/lib/packlets/iana/model.d.ts.map +0 -1
  286. package/lib/packlets/iana/model.js.map +0 -1
  287. package/lib/packlets/iana/validate.d.ts.map +0 -1
  288. package/lib/packlets/iana/validate.js.map +0 -1
  289. package/lib/packlets/unsd/areas.d.ts.map +0 -1
  290. package/lib/packlets/unsd/areas.js.map +0 -1
  291. package/lib/packlets/unsd/common.d.ts.map +0 -1
  292. package/lib/packlets/unsd/common.js.map +0 -1
  293. package/lib/packlets/unsd/csv/converters.d.ts.map +0 -1
  294. package/lib/packlets/unsd/csv/converters.js.map +0 -1
  295. package/lib/packlets/unsd/csv/index.d.ts.map +0 -1
  296. package/lib/packlets/unsd/csv/index.js.map +0 -1
  297. package/lib/packlets/unsd/csv/model.d.ts.map +0 -1
  298. package/lib/packlets/unsd/csv/model.js.map +0 -1
  299. package/lib/packlets/unsd/defaultRegistries.d.ts.map +0 -1
  300. package/lib/packlets/unsd/defaultRegistries.js.map +0 -1
  301. package/lib/packlets/unsd/index.d.ts.map +0 -1
  302. package/lib/packlets/unsd/index.js.map +0 -1
  303. package/lib/packlets/unsd/regionCodes.d.ts.map +0 -1
  304. package/lib/packlets/unsd/regionCodes.js.map +0 -1
  305. package/lib/packlets/unsd/regions.d.ts.map +0 -1
  306. package/lib/packlets/unsd/regions.js.map +0 -1
  307. package/lib/packlets/utils/index.d.ts.map +0 -1
  308. package/lib/packlets/utils/index.js.map +0 -1
  309. package/lib/packlets/utils/jsonHelpers.d.ts.map +0 -1
  310. package/lib/packlets/utils/jsonHelpers.js.map +0 -1
  311. package/lib/packlets/utils/public.d.ts.map +0 -1
  312. package/lib/packlets/utils/public.js.map +0 -1
  313. package/lib/packlets/utils/validationHelpers.d.ts.map +0 -1
  314. package/lib/packlets/utils/validationHelpers.js.map +0 -1
@@ -0,0 +1,102 @@
1
+ /*
2
+ * Copyright (c) 2022 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+ import * as Iana from '../../iana';
24
+ import * as Bcp47Subtags from '../bcp47Subtags';
25
+
26
+ import { Result, allSucceed, succeed } from '@fgv/ts-utils';
27
+ import { ExtensionSingleton, ExtensionSubtag } from '../bcp47Subtags/model';
28
+
29
+ import { ISubtags } from '../common';
30
+ import { TagValidatorBase } from './baseValidator';
31
+ import { TagValidity } from './common';
32
+
33
+ /**
34
+ * @internal
35
+ */
36
+ export class IsWellFormedValidator extends TagValidatorBase {
37
+ public validity: TagValidity = 'well-formed';
38
+
39
+ protected _checkLanguage(subtags: ISubtags): Result<Iana.LanguageSubtags.LanguageSubtag | undefined> {
40
+ return subtags.primaryLanguage
41
+ ? this.iana.subtags.languages.verifyIsWellFormed(subtags.primaryLanguage)
42
+ : succeed(undefined);
43
+ }
44
+
45
+ protected _checkExtlangs(subtags: ISubtags): Result<Iana.LanguageSubtags.ExtLangSubtag[] | undefined> {
46
+ if (subtags.extlangs) {
47
+ return allSucceed(
48
+ subtags.extlangs.map((e) => this.iana.subtags.extlangs.verifyIsWellFormed(e)),
49
+ subtags.extlangs
50
+ );
51
+ }
52
+ return succeed(undefined);
53
+ }
54
+
55
+ protected _checkScript(subtags: ISubtags): Result<Iana.LanguageSubtags.ScriptSubtag | undefined> {
56
+ return subtags.script ? this.iana.subtags.scripts.verifyIsWellFormed(subtags.script) : succeed(undefined);
57
+ }
58
+
59
+ protected _checkRegion(subtags: ISubtags): Result<Iana.LanguageSubtags.RegionSubtag | undefined> {
60
+ return subtags.region ? this.iana.subtags.regions.verifyIsWellFormed(subtags.region) : succeed(undefined);
61
+ }
62
+
63
+ protected _checkVariants(subtags: ISubtags): Result<Iana.LanguageSubtags.VariantSubtag[] | undefined> {
64
+ if (subtags.variants) {
65
+ return allSucceed(
66
+ subtags.variants.map((v) => this.iana.subtags.variants.verifyIsWellFormed(v)),
67
+ subtags.variants
68
+ );
69
+ }
70
+ return succeed(undefined);
71
+ }
72
+
73
+ protected _checkExtensionSingleton(singleton: ExtensionSingleton): Result<ExtensionSingleton> {
74
+ return this.iana.extensions.extensions.verifyIsWellFormed(singleton);
75
+ }
76
+
77
+ protected _checkExtensionSubtagValue(value: ExtensionSubtag): Result<ExtensionSubtag> {
78
+ return Bcp47Subtags.Validate.extensionSubtag.verifyIsWellFormed(value);
79
+ }
80
+
81
+ protected _checkPrivateUseTags(
82
+ subtags: ISubtags
83
+ ): Result<Iana.LanguageSubtags.ExtendedLanguageRange[] | undefined> {
84
+ if (subtags.privateUse) {
85
+ return allSucceed(
86
+ subtags.privateUse.map((pu) =>
87
+ Iana.LanguageSubtags.Validate.extendedLanguageRange.verifyIsWellFormed(pu)
88
+ ),
89
+ subtags.privateUse
90
+ );
91
+ }
92
+ return succeed(subtags.privateUse);
93
+ }
94
+
95
+ protected _checkGrandfatheredTags(
96
+ subtags: ISubtags
97
+ ): Result<Iana.LanguageSubtags.GrandfatheredTag | undefined> {
98
+ return subtags.grandfathered
99
+ ? this.iana.subtags.grandfathered.verifyIsWellFormed(subtags.grandfathered)
100
+ : succeed(undefined);
101
+ }
102
+ }
@@ -0,0 +1,175 @@
1
+ /*
2
+ * Copyright (c) 2022 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+ import { Result, succeed } from '@fgv/ts-utils';
24
+ import { TagValidity, compareValidity } from './common';
25
+
26
+ import { ISubtags } from '../common';
27
+ import { ITagValidator } from './baseValidator';
28
+ import { IsCanonicalValidator } from './isCanonical';
29
+ import { IsInPreferredFromValidator } from './isInPreferredForm';
30
+ import { IsStrictlyValidValidator } from './isStrictlyValid';
31
+ import { IsValidValidator } from './isValid';
32
+ import { IsWellFormedValidator } from './isWellFormed';
33
+
34
+ /**
35
+ * Validation helpers for BCP-47 language tags.
36
+ * @public
37
+ */
38
+ export class ValidateTag {
39
+ private static _isCanonical?: ITagValidator;
40
+ private static _isInPreferredForm?: ITagValidator;
41
+ private static _validators: Record<TagValidity, ITagValidator> | undefined = undefined;
42
+
43
+ /**
44
+ * Determines if supplied {@link Bcp47.Subtags | subtags } are in canonical form,
45
+ * meaning that they are at least well-formed as specified by
46
+ * {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | RFC 5646}, and
47
+ * all subtags are also
48
+ * {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.1.1 | capitalized as recommended}.
49
+ * @param subtags - The {@link Bcp47.Subtags | subtags } to test.
50
+ * @returns `true` if the {@link Bcp47.Subtags | subtags } represent
51
+ * a language tag in canonical, false otherwise.
52
+ * @example `en-US` is in canonical form, `en-us` is not.
53
+ * @example `eng-US` is in canonical form, `eng-us` is not.
54
+ */
55
+ public static isCanonical(subtags: ISubtags): boolean {
56
+ if (!this._isCanonical) {
57
+ this._isCanonical = new IsCanonicalValidator();
58
+ }
59
+ return this._isCanonical.validateSubtags(subtags).isSuccess();
60
+ }
61
+
62
+ /**
63
+ * Determines if supplied {@link Bcp47.Subtags | subtags } are
64
+ * in preferred form. Preferred form is valid as specified by
65
+ * {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | RFC 5646} and
66
+ * also meets additional preferences specified in the
67
+ * {@link https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry | language subtag registry} -
68
+ * extraneous (suppressed) script tags, deprecated language, extlang, script or region tags or
69
+ * deprecated grandfathered or redundant tags (with a defined preferred-value) are not allowed.
70
+ * @param subtags - The {@link Bcp47.Subtags | subtags } to test.
71
+ * @returns `true` if the {@link Bcp47.Subtags | subtags } represent
72
+ * a valid language tag in preferred form, false otherwise.
73
+ * @example `en-US` is in preferred form, `en-Latn-US` is not.
74
+ * @example `cmn` is in preferred form, `zh-cmn-Hans` is not.
75
+ */
76
+ public static isInPreferredForm(subtags: ISubtags): boolean {
77
+ if (!this._isInPreferredForm) {
78
+ this._isInPreferredForm = new IsInPreferredFromValidator();
79
+ }
80
+ return this._isInPreferredForm.validateSubtags(subtags).isSuccess();
81
+ }
82
+
83
+ /**
84
+ * Determines if supplied {@link Bcp47.Subtags | subtags } are
85
+ * strictly valid. A strictly valid tag is both
86
+ * {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | valid as defined in the RFC}
87
+ * and meets any other requirements such as
88
+ * {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-3.1.8 | prefix validity}.
89
+ * @param subtags - The {@link Bcp47.Subtags | subtags } to test.
90
+ * @returns `true` if the {@link Bcp47.Subtags | subtags } represent
91
+ * a strictly valid language tag, false otherwise.
92
+ * @example `ca-valencia` is strictly valid, `es-valencia` is not.
93
+ */
94
+ public static isStrictlyValid(subtags: ISubtags): boolean {
95
+ return this.validateSubtags(subtags, 'strictly-valid').isSuccess();
96
+ }
97
+
98
+ /**
99
+ * Determines if supplied {@link Bcp47.Subtags | subtags } are
100
+ * valid as specified by {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | RFC 5646},
101
+ * meaning that all subtags, or the tag itself for grandfathered tags, are defined in the
102
+ * {@link https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry | IANA language subtag registry}.
103
+ * @param subtags - The {@link Bcp47.Subtags | subtags } to test.
104
+ * @returns `true` if the {@link Bcp47.Subtags | subtags } represent
105
+ * a valid language tag, false otherwise.
106
+ * @example `en-US` is valid, `eng-US` is not.
107
+ */
108
+ public static isValid(subtags: ISubtags): boolean {
109
+ return this.validateSubtags(subtags, 'valid').isSuccess();
110
+ }
111
+
112
+ /**
113
+ * Determines if supplied {@link Bcp47.Subtags | subtags } are
114
+ * well-formed as specified by {@link https://www.rfc-editor.org/rfc/rfc5646.html#section-2.2.9 | RFC 5646},
115
+ * meaning that all subtags meet the grammar defined in the specification.
116
+ * @param subtags - The {@link Bcp47.Subtags | subtags } to test.
117
+ * @returns `true` if the {@link Bcp47.Subtags | subtags } represent
118
+ * a well-formed language tag, false otherwise.
119
+ * @example `en-US` is valid, `english-US` is not.
120
+ * @public
121
+ */
122
+ public static isWellFormed(subtags: ISubtags): boolean {
123
+ return this.validateSubtags(subtags, 'well-formed').isSuccess();
124
+ }
125
+
126
+ /**
127
+ * Chooses an appropriate default tag validator given desired and optional current
128
+ * {@link Bcp47.TagValidity | validation level}.
129
+ * @param wantValidity - The desired {@link Bcp47.TagValidity | validity level}.
130
+ * @param haveValidity - (optional) The current {@link Bcp47.TagValidity | validity level}.
131
+ * @returns An appropriate {@link Bcp47.TagValidator | tag validator} or `undefined` if no
132
+ * additional validation is necessary.
133
+ * @internal
134
+ */
135
+ public static chooseValidator(
136
+ wantValidity: TagValidity,
137
+ haveValidity?: TagValidity
138
+ ): ITagValidator | undefined {
139
+ if (haveValidity && compareValidity(haveValidity, wantValidity) >= 0) {
140
+ return undefined;
141
+ }
142
+
143
+ if (!this._validators) {
144
+ this._validators = {
145
+ /* eslint-disable @typescript-eslint/naming-convention */
146
+ unknown: new IsWellFormedValidator(),
147
+ 'well-formed': new IsWellFormedValidator(),
148
+ valid: new IsValidValidator(),
149
+ 'strictly-valid': new IsStrictlyValidValidator()
150
+ /* eslint-enable @typescript-eslint/naming-convention */
151
+ };
152
+ }
153
+ return this._validators![wantValidity];
154
+ }
155
+
156
+ /**
157
+ * Validates supplied {@link Bcp47.Subtags | subtags } to a requested
158
+ * {@link Bcp47.TagValidity | validity level}, if necessary.
159
+ * @param subtags - The {@link Bcp47.Subtags | subtags } to be validated.
160
+ * @param wantValidity - The desired {@link Bcp47.TagValidity | validity level}.
161
+ * @param haveValidity - (optional) The current {@link Bcp47.TagValidity | validity level}.
162
+ * @returns `Success` with the validated {@link Bcp47.Subtags | subtags }, or
163
+ * `Failure` with details if an error occurs.
164
+ * @public
165
+ */
166
+ public static validateSubtags(
167
+ subtags: ISubtags,
168
+ wantValidity: TagValidity,
169
+ haveValidity?: TagValidity
170
+ ): Result<boolean> {
171
+ const validator = this.chooseValidator(wantValidity, haveValidity);
172
+ // istanbul ignore next - a pain to test
173
+ return validator?.validateSubtags(subtags) ?? succeed(true);
174
+ }
175
+ }
@@ -0,0 +1,67 @@
1
+ /*
2
+ * Copyright (c) 2022 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ /* eslint-disable @rushstack/typedef-var */
23
+
24
+ import * as Validate from './validate';
25
+
26
+ import { Converter, Converters } from '@fgv/ts-utils';
27
+ import { IDatedRegistry } from './model';
28
+
29
+ /**
30
+ * Validating converter from string {@link Iana.Model.YearMonthDaySpec}.
31
+ * @public
32
+ */
33
+ export const yearMonthDaySpec = Validate.yearMonthDateSpec.converter;
34
+
35
+ /**
36
+ * Validating converter from string {@link Iana.Model.IsoAlpha2RegionCode}.
37
+ * @public
38
+ */
39
+ export const isoAlpha2RegionCode = Validate.isoAlpha2RegionCode.converter;
40
+
41
+ /**
42
+ * Validating converter from string {@link Iana.Model.IsoAlpha3RegionCode}.
43
+ * @public
44
+ */
45
+ export const isoAlpha3RegionCode = Validate.isoAlpha3RegionCode.converter;
46
+
47
+ /**
48
+ * Validating converter from string {@link Iana.Model.UnM49RegionCode}.
49
+ * @public
50
+ */
51
+ export const unM49RegionCode = Validate.unM49RegionCode.converter;
52
+
53
+ /**
54
+ * Helper function which creates a converter that returns a validated {@Link Iana.Model.IDatedRegistry | DatedRegistry}
55
+ * containing entries of supplied template type `T`.
56
+ * @param entryConverter - A `Converter<T>` to validate each entry
57
+ * @returns A new validating `Converter` which yields {@Link Iana.Model.IDatedRegistry | DatedRegistry<T>}
58
+ * @public
59
+ */
60
+ export function datedRegistry<T, TC = unknown>(
61
+ entryConverter: Converter<T, TC>
62
+ ): Converter<IDatedRegistry<T>, unknown> {
63
+ return Converters.strictObject<IDatedRegistry<T>, unknown>({
64
+ fileDate: yearMonthDaySpec,
65
+ entries: Converters.arrayOf(entryConverter)
66
+ });
67
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ * Copyright (c) 2022 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+ import { Brand } from '@fgv/ts-utils';
24
+
25
+ /**
26
+ * Represents an ISO 3166 Alpha-2 region code.
27
+ * @public
28
+ */
29
+ export type IsoAlpha2RegionCode = Brand<string, 'IsoAlpha2RegionCode'>;
30
+
31
+ /**
32
+ * Represents an ISO 3166 Alpha-3 region code.
33
+ * @public
34
+ */
35
+ export type IsoAlpha3RegionCode = Brand<string, 'IsoAlpha3RegionCode'>;
36
+
37
+ /**
38
+ * Represents a UN M.49 numeric region code.
39
+ * @public
40
+ */
41
+ export type UnM49RegionCode = Brand<string, 'UnM49RegionCode'>;
42
+
43
+ /**
44
+ * Represents a date string in the format YYYY-MM-DD.
45
+ * @public
46
+ */
47
+ export type YearMonthDaySpec = Brand<string, 'YearMonthDaySpec'>;
48
+
49
+ /**
50
+ * A dated collection of registry entries of a specified templated type.
51
+ * @public
52
+ */
53
+ export interface IDatedRegistry<T> {
54
+ fileDate: YearMonthDaySpec;
55
+ entries: T[];
56
+ }
@@ -0,0 +1,145 @@
1
+ /*
2
+ * Copyright (c) 2022 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+ import { Result, fail, succeed } from '@fgv/ts-utils';
24
+ import { ValidationHelpers } from '../../utils';
25
+
26
+ /**
27
+ * @internal
28
+ */
29
+ export abstract class RegisteredItemScope<TTYPE extends string, TKEY extends string, TITEM> {
30
+ protected readonly _items: Map<TKEY, TITEM>;
31
+ protected readonly _type: TTYPE;
32
+ protected readonly _validate: ValidationHelpers<TKEY>;
33
+
34
+ protected constructor(type: TTYPE, validate: ValidationHelpers<TKEY>) {
35
+ this._items = new Map();
36
+ this._type = type;
37
+ this._validate = validate;
38
+ }
39
+
40
+ public getAllKeys(): TKEY[] {
41
+ return Array.from(this._items.keys());
42
+ }
43
+
44
+ public getAll(): TITEM[] {
45
+ return Array.from(this._items.values());
46
+ }
47
+
48
+ public tryGet(want: string | undefined): TITEM | undefined {
49
+ if (want) {
50
+ const got = this._items.get(want as TKEY);
51
+ if (!got) {
52
+ const result = this.toCanonical(want);
53
+ if (result.isSuccess()) {
54
+ return this._items.get(result.value as TKEY);
55
+ }
56
+ }
57
+ return got;
58
+ }
59
+ return undefined;
60
+ }
61
+
62
+ public tryGetCanonical(want: string | undefined): TITEM | undefined {
63
+ return want ? this._items.get(want as TKEY) : undefined;
64
+ }
65
+
66
+ public get(want: string | undefined): Result<TITEM> {
67
+ const got = this.tryGet(want);
68
+ return got ? succeed(got) : fail(`invalid ${this._type}`);
69
+ }
70
+
71
+ public getCanonical(want: string | undefined): Result<TITEM | undefined> {
72
+ const got = this.tryGetCanonical(want);
73
+ return got ? succeed(got) : fail(`invalid ${this._type}`);
74
+ }
75
+
76
+ public isWellFormed(val: unknown): val is TKEY {
77
+ return this._validate.isWellFormed(val);
78
+ }
79
+
80
+ public isCanonical(val: unknown): val is TKEY {
81
+ return this._validate.isCanonical(val);
82
+ }
83
+
84
+ public toCanonical(val: unknown): Result<TKEY> {
85
+ return this._validate.toCanonical(val);
86
+ }
87
+
88
+ public toValidCanonical(val: unknown): Result<TKEY> {
89
+ return this._validate.toCanonical(val).onSuccess((canonical) => {
90
+ if (this._items.has(canonical)) {
91
+ return succeed(canonical);
92
+ }
93
+ return fail(`${val}: invalid ${this._type}`);
94
+ });
95
+ }
96
+
97
+ public isValid(val: unknown): val is TKEY {
98
+ const result = this.toCanonical(val);
99
+ if (result.isSuccess()) {
100
+ return this._items.has(result.value);
101
+ }
102
+ return false;
103
+ }
104
+
105
+ public isValidCanonical(val: unknown): val is TKEY {
106
+ if (this.isCanonical(val)) {
107
+ return this._items.has(val);
108
+ }
109
+ return false;
110
+ }
111
+
112
+ public verifyIsWellFormed(val: unknown): Result<TKEY> {
113
+ return this._validate.verifyIsWellFormed(val);
114
+ }
115
+
116
+ public verifyIsValid(val: unknown): Result<TKEY> {
117
+ if (this.isValid(val)) {
118
+ return succeed(val);
119
+ }
120
+ if (!this.isWellFormed(val)) {
121
+ return fail(`${val}: malformed ${this._type}.`);
122
+ }
123
+ return fail(`${val}: invalid ${this._type}.`);
124
+ }
125
+
126
+ public verifyIsCanonical(val: unknown): Result<TKEY> {
127
+ if (this.isCanonical(val)) {
128
+ return succeed(val);
129
+ }
130
+ if (!this.isWellFormed(val)) {
131
+ return fail(`${val}: malformed ${this._type}`);
132
+ }
133
+ return fail(`${val}: non-canonical ${this._type}`);
134
+ }
135
+
136
+ protected _validateKey(key: TKEY): Result<true> {
137
+ if (!this.isCanonical(key)) {
138
+ return fail(`${key}: ${this._type} is not in canonical form`);
139
+ }
140
+ return succeed(true);
141
+ }
142
+
143
+ public abstract add(entry: TITEM): Result<true>;
144
+ protected abstract _validateEntry(entry: TITEM): Result<true>;
145
+ }
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Copyright (c) 2021 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+ import { DateTime } from 'luxon';
24
+ import { YearMonthDaySpec } from './model';
25
+
26
+ /**
27
+ * Gets the current date as an {@link Iana.Model.YearMonthDaySpec | YearMonthDaySpec }.
28
+ * @public
29
+ */
30
+ export function nowAsYearMonthDay(): YearMonthDaySpec {
31
+ return DateTime.now().toFormat('yyyy-LL-dd') as YearMonthDaySpec;
32
+ }
@@ -0,0 +1,64 @@
1
+ /*
2
+ * Copyright (c) 2021 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+ /* eslint-disable @rushstack/typedef-var */
23
+
24
+ import { succeed } from '@fgv/ts-utils';
25
+ import { RegExpValidationHelpers } from '../../utils';
26
+ import * as Model from './model';
27
+
28
+ /**
29
+ * @public
30
+ */
31
+ export const yearMonthDateSpec = new RegExpValidationHelpers<Model.YearMonthDaySpec>({
32
+ description: 'Year-Month-Date value',
33
+ wellFormed: /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/,
34
+ canonical: /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/
35
+ });
36
+
37
+ /**
38
+ * @public
39
+ */
40
+ export const isoAlpha2RegionCode = new RegExpValidationHelpers<Model.IsoAlpha2RegionCode>({
41
+ description: 'ISO 3166-2 Alpha-2 region code',
42
+ wellFormed: /^[A-Za-z]{2}$/,
43
+ canonical: /^[A-Z]{2}$/,
44
+ toCanonical: (from: Model.IsoAlpha2RegionCode) => succeed(from.toUpperCase() as Model.IsoAlpha2RegionCode)
45
+ });
46
+
47
+ /**
48
+ * @public
49
+ */
50
+ export const isoAlpha3RegionCode = new RegExpValidationHelpers<Model.IsoAlpha3RegionCode>({
51
+ description: 'ISO 3166-2 Alpha-3 region code',
52
+ wellFormed: /^[A-Za-z]{3}$/,
53
+ canonical: /^[A-Z]{3}$/,
54
+ toCanonical: (from: Model.IsoAlpha3RegionCode) => succeed(from.toUpperCase() as Model.IsoAlpha3RegionCode)
55
+ });
56
+
57
+ /**
58
+ * @public
59
+ */
60
+ export const unM49RegionCode = new RegExpValidationHelpers<Model.UnM49RegionCode>({
61
+ description: 'UN M.49 3-digit region code',
62
+ wellFormed: /^[0-9]{3}$/,
63
+ canonical: /^[0-9]{3}$/
64
+ });
@@ -0,0 +1,26 @@
1
+ /*
2
+ * Copyright (c) 2022 Erik Fortune
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in all
12
+ * copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+ import * as Jar from './jar/jarConverters';
24
+
25
+ export * from './common/converters';
26
+ export { Jar };