@mailwoman/registry 10.7.0 → 11.0.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.
- package/README.md +93 -98
- package/data/manifests/artifacts.json +32 -0
- package/data/manifests/coverage.json +56 -0
- package/data/manifests/sources.lock.json +48 -0
- package/data/normalized/iata-airports.json +126749 -0
- package/data/normalized/iso3166-1.json +2035 -0
- package/definitions/namespaces.json +63 -0
- package/definitions/sections.json +73 -0
- package/docs/data-policy.md +81 -0
- package/docs/performance.md +146 -0
- package/docs/rgy1.md +144 -0
- package/lib/artifacts/country-airport-collision.ts +26 -0
- package/lib/artifacts/iata-airport/membership.ts +26 -0
- package/lib/artifacts/iata-airport/records.ts +26 -0
- package/lib/artifacts/iso3166-1/alpha2-membership.ts +26 -0
- package/lib/artifacts/iso3166-1/alpha3-membership.ts +26 -0
- package/lib/artifacts/iso3166-1/records.ts +26 -0
- package/lib/errors.ts +44 -0
- package/lib/iata/airports/records.ts +174 -0
- package/lib/iata/airports/validate.ts +49 -0
- package/lib/index.ts +25 -15
- package/lib/inspect.ts +56 -0
- package/lib/iso3166/alpha2.ts +48 -0
- package/lib/iso3166/alpha3.ts +51 -0
- package/lib/iso3166/records.ts +149 -0
- package/lib/iso3166/relations.ts +30 -0
- package/lib/key.ts +146 -0
- package/lib/normalize.ts +31 -0
- package/lib/overlap/country-airport.ts +108 -0
- package/lib/rgy1/base64.ts +24 -0
- package/lib/rgy1/reader.ts +316 -0
- package/lib/rgy1/sections.generated.ts +79 -0
- package/lib/rgy1/views.ts +267 -0
- package/lib/types.ts +88 -74
- package/lib/wasm.ts +285 -0
- package/out/artifacts/country-airport-collision.d.ts +15 -0
- package/out/artifacts/country-airport-collision.d.ts.map +1 -0
- package/out/artifacts/country-airport-collision.js +21 -0
- package/out/artifacts/country-airport-collision.js.map +1 -0
- package/out/artifacts/iata-airport/membership.d.ts +15 -0
- package/out/artifacts/iata-airport/membership.d.ts.map +1 -0
- package/out/artifacts/iata-airport/membership.js +21 -0
- package/out/artifacts/iata-airport/membership.js.map +1 -0
- package/out/artifacts/iata-airport/records.d.ts +15 -0
- package/out/artifacts/iata-airport/records.d.ts.map +1 -0
- package/out/artifacts/iata-airport/records.js +21 -0
- package/out/artifacts/iata-airport/records.js.map +1 -0
- package/out/artifacts/iso3166-1/alpha2-membership.d.ts +15 -0
- package/out/artifacts/iso3166-1/alpha2-membership.d.ts.map +1 -0
- package/out/artifacts/iso3166-1/alpha2-membership.js +21 -0
- package/out/artifacts/iso3166-1/alpha2-membership.js.map +1 -0
- package/out/artifacts/iso3166-1/alpha3-membership.d.ts +15 -0
- package/out/artifacts/iso3166-1/alpha3-membership.d.ts.map +1 -0
- package/out/artifacts/iso3166-1/alpha3-membership.js +21 -0
- package/out/artifacts/iso3166-1/alpha3-membership.js.map +1 -0
- package/out/artifacts/iso3166-1/records.d.ts +15 -0
- package/out/artifacts/iso3166-1/records.d.ts.map +1 -0
- package/out/artifacts/iso3166-1/records.js +21 -0
- package/out/artifacts/iso3166-1/records.js.map +1 -0
- package/out/errors.d.ts +38 -0
- package/out/errors.d.ts.map +1 -0
- package/out/errors.js +35 -0
- package/out/errors.js.map +1 -0
- package/out/iata/airports/records.d.ts +44 -0
- package/out/iata/airports/records.d.ts.map +1 -0
- package/out/iata/airports/records.js +137 -0
- package/out/iata/airports/records.js.map +1 -0
- package/out/iata/airports/validate.d.ts +27 -0
- package/out/iata/airports/validate.d.ts.map +1 -0
- package/out/iata/airports/validate.js +42 -0
- package/out/iata/airports/validate.js.map +1 -0
- package/out/index.d.ts +19 -15
- package/out/index.d.ts.map +1 -1
- package/out/index.js +14 -15
- package/out/index.js.map +1 -1
- package/out/inspect.d.ts +38 -0
- package/out/inspect.d.ts.map +1 -0
- package/out/inspect.js +33 -0
- package/out/inspect.js.map +1 -0
- package/out/iso3166/alpha2.d.ts +24 -0
- package/out/iso3166/alpha2.d.ts.map +1 -0
- package/out/iso3166/alpha2.js +41 -0
- package/out/iso3166/alpha2.js.map +1 -0
- package/out/iso3166/alpha3.d.ts +29 -0
- package/out/iso3166/alpha3.d.ts.map +1 -0
- package/out/iso3166/alpha3.js +44 -0
- package/out/iso3166/alpha3.js.map +1 -0
- package/out/iso3166/records.d.ts +38 -0
- package/out/iso3166/records.d.ts.map +1 -0
- package/out/iso3166/records.js +105 -0
- package/out/iso3166/records.js.map +1 -0
- package/out/iso3166/relations.d.ts +20 -0
- package/out/iso3166/relations.d.ts.map +1 -0
- package/out/iso3166/relations.js +27 -0
- package/out/iso3166/relations.js.map +1 -0
- package/out/key.d.ts +68 -0
- package/out/key.d.ts.map +1 -0
- package/out/key.js +122 -0
- package/out/key.js.map +1 -0
- package/out/normalize.d.ts +25 -0
- package/out/normalize.d.ts.map +1 -0
- package/out/normalize.js +21 -0
- package/out/normalize.js.map +1 -0
- package/out/overlap/country-airport.d.ts +57 -0
- package/out/overlap/country-airport.d.ts.map +1 -0
- package/out/overlap/country-airport.js +71 -0
- package/out/overlap/country-airport.js.map +1 -0
- package/out/rgy1/base64.d.ts +15 -0
- package/out/rgy1/base64.d.ts.map +1 -0
- package/out/rgy1/base64.js +22 -0
- package/out/rgy1/base64.js.map +1 -0
- package/out/rgy1/reader.d.ts +103 -0
- package/out/rgy1/reader.d.ts.map +1 -0
- package/out/rgy1/reader.js +230 -0
- package/out/rgy1/reader.js.map +1 -0
- package/out/rgy1/sections.generated.d.ts +54 -0
- package/out/rgy1/sections.generated.d.ts.map +1 -0
- package/out/rgy1/sections.generated.js +69 -0
- package/out/rgy1/sections.generated.js.map +1 -0
- package/out/rgy1/views.d.ts +96 -0
- package/out/rgy1/views.d.ts.map +1 -0
- package/out/rgy1/views.js +218 -0
- package/out/rgy1/views.js.map +1 -0
- package/out/sdk/fetch.d.ts +53 -0
- package/out/sdk/fetch.d.ts.map +1 -0
- package/out/sdk/fetch.js +107 -0
- package/out/sdk/fetch.js.map +1 -0
- package/out/sdk/fetch.run.d.ts +14 -0
- package/out/sdk/fetch.run.d.ts.map +1 -0
- package/out/sdk/fetch.run.js +20 -0
- package/out/sdk/fetch.run.js.map +1 -0
- package/out/sdk/sources.d.ts +111 -0
- package/out/sdk/sources.d.ts.map +1 -0
- package/out/sdk/sources.js +98 -0
- package/out/sdk/sources.js.map +1 -0
- package/out/tools/artifact-path.d.ts +10 -0
- package/out/tools/artifact-path.d.ts.map +1 -0
- package/out/tools/artifact-path.js +12 -0
- package/out/tools/artifact-path.js.map +1 -0
- package/out/tools/bench.run.d.ts +19 -0
- package/out/tools/bench.run.d.ts.map +1 -0
- package/out/tools/bench.run.js +204 -0
- package/out/tools/bench.run.js.map +1 -0
- package/out/tools/build-wasm.run.d.ts +18 -0
- package/out/tools/build-wasm.run.d.ts.map +1 -0
- package/out/tools/build-wasm.run.js +71 -0
- package/out/tools/build-wasm.run.js.map +1 -0
- package/out/tools/generate-sections.run.d.ts +13 -0
- package/out/tools/generate-sections.run.d.ts.map +1 -0
- package/out/tools/generate-sections.run.js +136 -0
- package/out/tools/generate-sections.run.js.map +1 -0
- package/out/tools/generate.run.d.ts +18 -0
- package/out/tools/generate.run.d.ts.map +1 -0
- package/out/tools/generate.run.js +118 -0
- package/out/tools/generate.run.js.map +1 -0
- package/out/tools/normalize.d.ts +155 -0
- package/out/tools/normalize.d.ts.map +1 -0
- package/out/tools/normalize.js +303 -0
- package/out/tools/normalize.js.map +1 -0
- package/out/tools/normalize.run.d.ts +14 -0
- package/out/tools/normalize.run.d.ts.map +1 -0
- package/out/tools/normalize.run.js +29 -0
- package/out/tools/normalize.run.js.map +1 -0
- package/out/types.d.ts +90 -76
- package/out/types.d.ts.map +1 -1
- package/out/types.js +20 -4
- package/out/types.js.map +1 -1
- package/out/wasm.d.ts +98 -0
- package/out/wasm.d.ts.map +1 -0
- package/out/wasm.js +137 -0
- package/out/wasm.js.map +1 -0
- package/package.json +49 -28
- package/sdk/fetch.run.ts +24 -0
- package/sdk/fetch.ts +146 -0
- package/sdk/sources.ts +162 -0
- package/tools/artifact-path.ts +12 -0
- package/tools/bench.run.ts +265 -0
- package/tools/build-wasm.run.ts +82 -0
- package/tools/generate-sections.run.ts +152 -0
- package/tools/generate.run.ts +146 -0
- package/tools/normalize.run.ts +36 -0
- package/tools/normalize.ts +474 -0
- package/wasm/registry-simd.wasm +0 -0
- package/wasm/registry.wasm +0 -0
- package/lib/address-key.ts +0 -46
- package/lib/geocode-handler.ts +0 -37
- package/lib/geojson.ts +0 -73
- package/lib/ingest.ts +0 -349
- package/lib/learned-scorer.ts +0 -134
- package/lib/map-html.ts +0 -287
- package/lib/models/crosssource-gbt-en-us.ts +0 -43
- package/lib/models/dedup-gbt-en-us.ts +0 -47
- package/lib/models/org-crosssource-gbt-en-us.ts +0 -43
- package/lib/reconcile.ts +0 -239
- package/lib/resolve.ts +0 -570
- package/out/address-key.d.ts +0 -34
- package/out/address-key.d.ts.map +0 -1
- package/out/address-key.js +0 -41
- package/out/address-key.js.map +0 -1
- package/out/geocode-handler.d.ts +0 -20
- package/out/geocode-handler.d.ts.map +0 -1
- package/out/geocode-handler.js +0 -29
- package/out/geocode-handler.js.map +0 -1
- package/out/geojson.d.ts +0 -28
- package/out/geojson.d.ts.map +0 -1
- package/out/geojson.js +0 -63
- package/out/geojson.js.map +0 -1
- package/out/ingest.d.ts +0 -173
- package/out/ingest.d.ts.map +0 -1
- package/out/ingest.js +0 -185
- package/out/ingest.js.map +0 -1
- package/out/learned-scorer.d.ts +0 -61
- package/out/learned-scorer.d.ts.map +0 -1
- package/out/learned-scorer.js +0 -91
- package/out/learned-scorer.js.map +0 -1
- package/out/map-html.d.ts +0 -39
- package/out/map-html.d.ts.map +0 -1
- package/out/map-html.js +0 -220
- package/out/map-html.js.map +0 -1
- package/out/models/crosssource-gbt-en-us.d.ts +0 -45
- package/out/models/crosssource-gbt-en-us.d.ts.map +0 -1
- package/out/models/crosssource-gbt-en-us.js +0 -40
- package/out/models/crosssource-gbt-en-us.js.map +0 -1
- package/out/models/dedup-gbt-en-us.d.ts +0 -44
- package/out/models/dedup-gbt-en-us.d.ts.map +0 -1
- package/out/models/dedup-gbt-en-us.js +0 -44
- package/out/models/dedup-gbt-en-us.js.map +0 -1
- package/out/models/org-crosssource-gbt-en-us.d.ts +0 -45
- package/out/models/org-crosssource-gbt-en-us.d.ts.map +0 -1
- package/out/models/org-crosssource-gbt-en-us.js +0 -40
- package/out/models/org-crosssource-gbt-en-us.js.map +0 -1
- package/out/reconcile.d.ts +0 -96
- package/out/reconcile.d.ts.map +0 -1
- package/out/reconcile.js +0 -127
- package/out/reconcile.js.map +0 -1
- package/out/resolve.d.ts +0 -264
- package/out/resolve.d.ts.map +0 -1
- package/out/resolve.js +0 -282
- package/out/resolve.js.map +0 -1
- package/out/tools/coverage-reconciliation.d.ts +0 -67
- package/out/tools/coverage-reconciliation.d.ts.map +0 -1
- package/out/tools/coverage-reconciliation.js +0 -113
- package/out/tools/coverage-reconciliation.js.map +0 -1
- package/out/tools/cross/dataset-correlation.d.ts +0 -61
- package/out/tools/cross/dataset-correlation.d.ts.map +0 -1
- package/out/tools/cross/dataset-correlation.js +0 -244
- package/out/tools/cross/dataset-correlation.js.map +0 -1
- package/out/tools/cross/source-threshold-sweep.d.ts +0 -60
- package/out/tools/cross/source-threshold-sweep.d.ts.map +0 -1
- package/out/tools/cross/source-threshold-sweep.js +0 -264
- package/out/tools/cross/source-threshold-sweep.js.map +0 -1
- package/out/tools/dedup-ceiling.d.ts +0 -62
- package/out/tools/dedup-ceiling.d.ts.map +0 -1
- package/out/tools/dedup-ceiling.js +0 -171
- package/out/tools/dedup-ceiling.js.map +0 -1
- package/out/tools/eval-geocoder.d.ts +0 -68
- package/out/tools/eval-geocoder.d.ts.map +0 -1
- package/out/tools/eval-geocoder.js +0 -13
- package/out/tools/eval-geocoder.js.map +0 -1
- package/out/tools/geocoder/namesake-probe.d.ts +0 -33
- package/out/tools/geocoder/namesake-probe.d.ts.map +0 -1
- package/out/tools/geocoder/namesake-probe.js +0 -60
- package/out/tools/geocoder/namesake-probe.js.map +0 -1
- package/out/tools/geocoder/vs-provided-coords.d.ts +0 -53
- package/out/tools/geocoder/vs-provided-coords.d.ts.map +0 -1
- package/out/tools/geocoder/vs-provided-coords.js +0 -161
- package/out/tools/geocoder/vs-provided-coords.js.map +0 -1
- package/out/tools/gold-set-sample.d.ts +0 -67
- package/out/tools/gold-set-sample.d.ts.map +0 -1
- package/out/tools/gold-set-sample.js +0 -81
- package/out/tools/gold-set-sample.js.map +0 -1
- package/out/tools/learned/scorer/clustering-eval.d.ts +0 -77
- package/out/tools/learned/scorer/clustering-eval.d.ts.map +0 -1
- package/out/tools/learned/scorer/clustering-eval.js +0 -207
- package/out/tools/learned/scorer/clustering-eval.js.map +0 -1
- package/out/tools/learned/scorer/crossstate-eval.d.ts +0 -65
- package/out/tools/learned/scorer/crossstate-eval.d.ts.map +0 -1
- package/out/tools/learned/scorer/crossstate-eval.js +0 -168
- package/out/tools/learned/scorer/crossstate-eval.js.map +0 -1
- package/out/tools/learned/scorer/eval.d.ts +0 -64
- package/out/tools/learned/scorer/eval.d.ts.map +0 -1
- package/out/tools/learned/scorer/eval.js +0 -275
- package/out/tools/learned/scorer/eval.js.map +0 -1
- package/out/tools/matcher-scale.d.ts +0 -40
- package/out/tools/matcher-scale.d.ts.map +0 -1
- package/out/tools/matcher-scale.js +0 -111
- package/out/tools/matcher-scale.js.map +0 -1
- package/out/tools/nppes/dedup-benchmark.d.ts +0 -82
- package/out/tools/nppes/dedup-benchmark.d.ts.map +0 -1
- package/out/tools/nppes/dedup-benchmark.js +0 -226
- package/out/tools/nppes/dedup-benchmark.js.map +0 -1
- package/out/tools/nppes/org-name.d.ts +0 -15
- package/out/tools/nppes/org-name.d.ts.map +0 -1
- package/out/tools/nppes/org-name.js +0 -6
- package/out/tools/nppes/org-name.js.map +0 -1
- package/out/tools/nppes/overmerge-packet.d.ts +0 -43
- package/out/tools/nppes/overmerge-packet.d.ts.map +0 -1
- package/out/tools/nppes/overmerge-packet.js +0 -54
- package/out/tools/nppes/overmerge-packet.js.map +0 -1
- package/out/tools/nppes/report.d.ts +0 -97
- package/out/tools/nppes/report.d.ts.map +0 -1
- package/out/tools/nppes/report.js +0 -178
- package/out/tools/nppes/report.js.map +0 -1
- package/out/tools/nppes/sample.d.ts +0 -101
- package/out/tools/nppes/sample.d.ts.map +0 -1
- package/out/tools/nppes/sample.js +0 -127
- package/out/tools/nppes/sample.js.map +0 -1
- package/out/tools/nppes/scoring.d.ts +0 -37
- package/out/tools/nppes/scoring.d.ts.map +0 -1
- package/out/tools/nppes/scoring.js +0 -81
- package/out/tools/nppes/scoring.js.map +0 -1
- package/out/tools/nppes/settings.d.ts +0 -41
- package/out/tools/nppes/settings.d.ts.map +0 -1
- package/out/tools/nppes/settings.js +0 -79
- package/out/tools/nppes/settings.js.map +0 -1
- package/out/tools/nppes/truth-grains.d.ts +0 -63
- package/out/tools/nppes/truth-grains.d.ts.map +0 -1
- package/out/tools/nppes/truth-grains.js +0 -139
- package/out/tools/nppes/truth-grains.js.map +0 -1
- package/out/tools/shared.d.ts +0 -325
- package/out/tools/shared.d.ts.map +0 -1
- package/out/tools/shared.js +0 -453
- package/out/tools/shared.js.map +0 -1
- package/out/tools/train/cross-gbt.d.ts +0 -89
- package/out/tools/train/cross-gbt.d.ts.map +0 -1
- package/out/tools/train/cross-gbt.js +0 -132
- package/out/tools/train/cross-gbt.js.map +0 -1
- package/out/tools/train/gbt.d.ts +0 -85
- package/out/tools/train/gbt.d.ts.map +0 -1
- package/out/tools/train/gbt.js +0 -155
- package/out/tools/train/gbt.js.map +0 -1
- package/out/tools/train/org-cross-gbt.d.ts +0 -85
- package/out/tools/train/org-cross-gbt.d.ts.map +0 -1
- package/out/tools/train/org-cross-gbt.js +0 -122
- package/out/tools/train/org-cross-gbt.js.map +0 -1
- package/out/tools/txhhsc-to-oarow.d.ts +0 -42
- package/out/tools/txhhsc-to-oarow.d.ts.map +0 -1
- package/out/tools/txhhsc-to-oarow.js +0 -78
- package/out/tools/txhhsc-to-oarow.js.map +0 -1
- package/out/tools/viz/browser.d.ts +0 -31
- package/out/tools/viz/browser.d.ts.map +0 -1
- package/out/tools/viz/browser.js +0 -26
- package/out/tools/viz/browser.js.map +0 -1
- package/out/tools/viz/cross-dataset-map.d.ts +0 -39
- package/out/tools/viz/cross-dataset-map.d.ts.map +0 -1
- package/out/tools/viz/cross-dataset-map.js +0 -84
- package/out/tools/viz/cross-dataset-map.js.map +0 -1
- package/out/tools/viz/geocode-first-surface.d.ts +0 -36
- package/out/tools/viz/geocode-first-surface.d.ts.map +0 -1
- package/out/tools/viz/geocode-first-surface.js +0 -234
- package/out/tools/viz/geocode-first-surface.js.map +0 -1
- package/out/tools/viz/render/map.d.ts +0 -42
- package/out/tools/viz/render/map.d.ts.map +0 -1
- package/out/tools/viz/render/map.js +0 -40
- package/out/tools/viz/render/map.js.map +0 -1
- package/out/tools/viz/render.d.ts +0 -46
- package/out/tools/viz/render.d.ts.map +0 -1
- package/out/tools/viz/render.js +0 -49
- package/out/tools/viz/render.js.map +0 -1
- package/out/tools/viz/source-provenance-map.d.ts +0 -57
- package/out/tools/viz/source-provenance-map.d.ts.map +0 -1
- package/out/tools/viz/source-provenance-map.js +0 -82
- package/out/tools/viz/source-provenance-map.js.map +0 -1
- package/out/tools/viz/yardstick-figure.d.ts +0 -22
- package/out/tools/viz/yardstick-figure.d.ts.map +0 -1
- package/out/tools/viz/yardstick-figure.js +0 -106
- package/out/tools/viz/yardstick-figure.js.map +0 -1
- package/tools/coverage-reconciliation.ts +0 -192
- package/tools/cross/dataset-correlation.ts +0 -380
- package/tools/cross/source-threshold-sweep.ts +0 -416
- package/tools/dedup-ceiling.ts +0 -225
- package/tools/eval-geocoder.ts +0 -77
- package/tools/geocoder/namesake-probe.ts +0 -91
- package/tools/geocoder/vs-provided-coords.ts +0 -232
- package/tools/gold-set-sample.ts +0 -147
- package/tools/learned/scorer/clustering-eval.ts +0 -349
- package/tools/learned/scorer/crossstate-eval.ts +0 -280
- package/tools/learned/scorer/eval.ts +0 -429
- package/tools/matcher-scale.ts +0 -185
- package/tools/nppes/dedup-benchmark.ts +0 -364
- package/tools/nppes/org-name.ts +0 -15
- package/tools/nppes/overmerge-packet.ts +0 -98
- package/tools/nppes/report.ts +0 -380
- package/tools/nppes/sample.ts +0 -250
- package/tools/nppes/scoring.ts +0 -115
- package/tools/nppes/settings.ts +0 -102
- package/tools/nppes/truth-grains.ts +0 -181
- package/tools/shared.ts +0 -743
- package/tools/train/cross-gbt.ts +0 -214
- package/tools/train/gbt.ts +0 -261
- package/tools/train/org-cross-gbt.ts +0 -189
- package/tools/txhhsc-to-oarow.ts +0 -118
- package/tools/viz/browser.ts +0 -41
- package/tools/viz/cross-dataset-map.ts +0 -133
- package/tools/viz/geocode-first-surface.ts +0 -305
- package/tools/viz/render/map.ts +0 -61
- package/tools/viz/render.ts +0 -103
- package/tools/viz/source-provenance-map.ts +0 -154
- package/tools/viz/yardstick-figure.ts +0 -197
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
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.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { iso31661Alpha2MembershipArtifact } from "#artifacts/iso3166-1/alpha2-membership"
|
|
11
|
+
import { type Parsed, ParseFailure, shapeFailure } from "#errors"
|
|
12
|
+
import { encode2 } from "#key"
|
|
13
|
+
import { Artifact } from "#rgy1/reader"
|
|
14
|
+
import { BitsetView } from "#rgy1/views"
|
|
15
|
+
import type { ISO } from "#types"
|
|
16
|
+
|
|
17
|
+
let bitset: BitsetView | null = null
|
|
18
|
+
|
|
19
|
+
function membership(): BitsetView {
|
|
20
|
+
bitset ??= BitsetView.of(Artifact.parse(iso31661Alpha2MembershipArtifact()))
|
|
21
|
+
|
|
22
|
+
return bitset
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Whether `input` is an officially assigned alpha-2 code in its canonical spelling, in the built profile.
|
|
27
|
+
*
|
|
28
|
+
* `GB` is one.
|
|
29
|
+
* `gb`, ` GB` and `GBR` are not.
|
|
30
|
+
*
|
|
31
|
+
* `canonicalSpelling` is the step that accepts the case or the whitespace.
|
|
32
|
+
*/
|
|
33
|
+
export function isCountryCodeAlpha2(input: string): input is ISO.CountryCode_3166_1_Alpha2 {
|
|
34
|
+
return membership().test(encode2(input))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The branded alpha-2 code, or the reason the input was refused.
|
|
39
|
+
*/
|
|
40
|
+
export function parseCountryCodeAlpha2(input: string): Parsed<ISO.CountryCode_3166_1_Alpha2> {
|
|
41
|
+
const shape = shapeFailure(input, 2, true)
|
|
42
|
+
|
|
43
|
+
if (shape) return { ok: false, reason: shape, input }
|
|
44
|
+
|
|
45
|
+
if (!isCountryCodeAlpha2(input)) return { ok: false, reason: ParseFailure.NotFound, input }
|
|
46
|
+
|
|
47
|
+
return { ok: true, value: input }
|
|
48
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
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.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { iso31661Alpha3MembershipArtifact } from "#artifacts/iso3166-1/alpha3-membership"
|
|
11
|
+
import { type Parsed, ParseFailure, shapeFailure } from "#errors"
|
|
12
|
+
import { encode3 } from "#key"
|
|
13
|
+
import { Artifact } from "#rgy1/reader"
|
|
14
|
+
import { BitsetView } from "#rgy1/views"
|
|
15
|
+
import type { ISO } from "#types"
|
|
16
|
+
|
|
17
|
+
let bitset: BitsetView | null = null
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns the alpha-3 membership bitset, parsing the artifact on first use.
|
|
21
|
+
*/
|
|
22
|
+
export function alpha3Membership(): BitsetView {
|
|
23
|
+
bitset ??= BitsetView.of(Artifact.parse(iso31661Alpha3MembershipArtifact()))
|
|
24
|
+
|
|
25
|
+
return bitset
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Whether `input` is an officially assigned alpha-3 code in its canonical spelling, in the built profile.
|
|
30
|
+
*
|
|
31
|
+
* `AUS` is one.
|
|
32
|
+
* `aus` and `AU` are not.
|
|
33
|
+
*
|
|
34
|
+
* A former code such as `DDR` is not: the records artifact still describes it.
|
|
35
|
+
*/
|
|
36
|
+
export function isCountryCodeAlpha3(input: string): input is ISO.CountryCode_3166_1_Alpha3 {
|
|
37
|
+
return alpha3Membership().test(encode3(input))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The branded alpha-3 code, or the reason the input was refused.
|
|
42
|
+
*/
|
|
43
|
+
export function parseCountryCodeAlpha3(input: string): Parsed<ISO.CountryCode_3166_1_Alpha3> {
|
|
44
|
+
const shape = shapeFailure(input, 3, true)
|
|
45
|
+
|
|
46
|
+
if (shape) return { ok: false, reason: shape, input }
|
|
47
|
+
|
|
48
|
+
if (!isCountryCodeAlpha3(input)) return { ok: false, reason: ParseFailure.NotFound, input }
|
|
49
|
+
|
|
50
|
+
return { ok: true, value: input }
|
|
51
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
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.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { iso31661RecordsArtifact } from "#artifacts/iso3166-1/records"
|
|
14
|
+
import {
|
|
15
|
+
ARITY_NUMERIC,
|
|
16
|
+
CODE_LENGTH_2,
|
|
17
|
+
CODE_LENGTH_3,
|
|
18
|
+
decode2,
|
|
19
|
+
decode3,
|
|
20
|
+
decodeNumeric,
|
|
21
|
+
encode2,
|
|
22
|
+
encode3,
|
|
23
|
+
encodeNumeric,
|
|
24
|
+
} from "#key"
|
|
25
|
+
import { Artifact } from "#rgy1/reader"
|
|
26
|
+
import { ColumnView, IDTableView, StringPoolView } from "#rgy1/views"
|
|
27
|
+
import { type CountryRecord, CountryStatus } from "#types"
|
|
28
|
+
|
|
29
|
+
interface Tables {
|
|
30
|
+
artifact: Artifact
|
|
31
|
+
alpha2: IDTableView
|
|
32
|
+
alpha3: IDTableView
|
|
33
|
+
numeric: IDTableView
|
|
34
|
+
columns: {
|
|
35
|
+
alpha2Key: ColumnView
|
|
36
|
+
alpha3Key: ColumnView
|
|
37
|
+
numeric: ColumnView
|
|
38
|
+
status: ColumnView
|
|
39
|
+
name: ColumnView
|
|
40
|
+
entityID: ColumnView
|
|
41
|
+
}
|
|
42
|
+
pool: StringPoolView
|
|
43
|
+
records: Array<CountryRecord | undefined>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let tables: Tables | null = null
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The column order the compiler writes.
|
|
50
|
+
* `header.columns` states the same order.
|
|
51
|
+
*/
|
|
52
|
+
const COLUMN = {
|
|
53
|
+
alpha2Key: 0,
|
|
54
|
+
alpha3Key: 1,
|
|
55
|
+
numeric: 2,
|
|
56
|
+
status: 3,
|
|
57
|
+
name: 4,
|
|
58
|
+
entityID: 5,
|
|
59
|
+
} as const
|
|
60
|
+
|
|
61
|
+
function openCountryTables(): Tables {
|
|
62
|
+
if (tables) return tables
|
|
63
|
+
|
|
64
|
+
const artifact = Artifact.parse(iso31661RecordsArtifact())
|
|
65
|
+
|
|
66
|
+
tables = {
|
|
67
|
+
artifact,
|
|
68
|
+
alpha2: IDTableView.of(artifact, CODE_LENGTH_2),
|
|
69
|
+
alpha3: IDTableView.of(artifact, CODE_LENGTH_3),
|
|
70
|
+
numeric: IDTableView.of(artifact, ARITY_NUMERIC),
|
|
71
|
+
columns: {
|
|
72
|
+
alpha2Key: ColumnView.of(artifact, COLUMN.alpha2Key),
|
|
73
|
+
alpha3Key: ColumnView.of(artifact, COLUMN.alpha3Key),
|
|
74
|
+
numeric: ColumnView.of(artifact, COLUMN.numeric),
|
|
75
|
+
status: ColumnView.of(artifact, COLUMN.status),
|
|
76
|
+
name: ColumnView.of(artifact, COLUMN.name),
|
|
77
|
+
entityID: ColumnView.of(artifact, COLUMN.entityID),
|
|
78
|
+
},
|
|
79
|
+
pool: StringPoolView.of(artifact),
|
|
80
|
+
records: new Array<CountryRecord | undefined>(artifact.header.rows ?? 0),
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return tables
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const STATUSES: readonly CountryStatus[] = [CountryStatus.OfficiallyAssigned, CountryStatus.FormerlyUsed]
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The record at `row`, materialized once.
|
|
90
|
+
*/
|
|
91
|
+
export function countryRecordAt(row: number): CountryRecord | null {
|
|
92
|
+
const tables_ = openCountryTables()
|
|
93
|
+
|
|
94
|
+
if (row < 0 || row >= tables_.records.length) return null
|
|
95
|
+
|
|
96
|
+
let record = tables_.records[row]
|
|
97
|
+
|
|
98
|
+
if (!record) {
|
|
99
|
+
const { columns, pool } = tables_
|
|
100
|
+
|
|
101
|
+
record = Object.freeze({
|
|
102
|
+
entityID: pool.get(columns.entityID.integer(row)) ?? "",
|
|
103
|
+
alpha2: decode2(columns.alpha2Key.integer(row)),
|
|
104
|
+
alpha3: decode3(columns.alpha3Key.integer(row)),
|
|
105
|
+
numeric: decodeNumeric(columns.numeric.integer(row)),
|
|
106
|
+
name: pool.get(columns.name.integer(row)) ?? "",
|
|
107
|
+
status: STATUSES[columns.status.integer(row)] ?? CountryStatus.FormerlyUsed,
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
tables_.records[row] = record
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return record
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* The country holding an alpha-2 code in its canonical spelling, of any status, or `null`.
|
|
118
|
+
*/
|
|
119
|
+
export function getCountryByAlpha2(code: string): CountryRecord | null {
|
|
120
|
+
return countryRecordAt(openCountryTables().alpha2.get(encode2(code)))
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The country holding an alpha-3 code in its canonical spelling, of any status, or `null`.
|
|
125
|
+
*/
|
|
126
|
+
export function getCountryByAlpha3(code: string): CountryRecord | null {
|
|
127
|
+
return countryRecordAt(openCountryTables().alpha3.get(encode3(code)))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The country holding a three-digit numeric code, of any status, or `null`.
|
|
132
|
+
*/
|
|
133
|
+
export function getCountryByNumeric(code: string): CountryRecord | null {
|
|
134
|
+
return countryRecordAt(openCountryTables().numeric.get(encodeNumeric(code)))
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The number of country records of every status.
|
|
139
|
+
*/
|
|
140
|
+
export function countryRecordCount(): number {
|
|
141
|
+
return openCountryTables().records.length
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The records artifact's header: profile, sources and coverage.
|
|
146
|
+
*/
|
|
147
|
+
export function countryRecordsHeader(): Artifact["header"] {
|
|
148
|
+
return openCountryTables().artifact.header
|
|
149
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { getCountryByAlpha2, getCountryByAlpha3, getCountryByNumeric } from "#iso3166/records"
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The alpha-3 code of the entity an alpha-2 code identifies, or `null`.
|
|
13
|
+
*/
|
|
14
|
+
export function alpha3ForAlpha2(alpha2: string): string | null {
|
|
15
|
+
return getCountryByAlpha2(alpha2)?.alpha3 ?? null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The alpha-2 code of the entity an alpha-3 code identifies, or `null`.
|
|
20
|
+
*/
|
|
21
|
+
export function alpha2ForAlpha3(alpha3: string): string | null {
|
|
22
|
+
return getCountryByAlpha3(alpha3)?.alpha2 ?? null
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The alpha-2 code of the entity a numeric code identifies, or `null`.
|
|
27
|
+
*/
|
|
28
|
+
export function alpha2ForNumeric(numeric: string): string | null {
|
|
29
|
+
return getCountryByNumeric(numeric)?.alpha2 ?? null
|
|
30
|
+
}
|
package/lib/key.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Key encodings: the position of a code in its direct-address key space, mirroring `crates/registry-core/src/key.rs`.
|
|
7
|
+
*
|
|
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
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The number of two-letter keys, 26².
|
|
15
|
+
*/
|
|
16
|
+
export const KEY_SPACE_2 = 676
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The number of three-letter keys, 26³.
|
|
20
|
+
*/
|
|
21
|
+
export const KEY_SPACE_3 = 17_576
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The number of three-digit numeric keys.
|
|
25
|
+
*/
|
|
26
|
+
export const KEY_SPACE_NUMERIC = 1000
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The arity value a section's `aux` field holds for a numeric key space.
|
|
30
|
+
*/
|
|
31
|
+
export const ARITY_NUMERIC = 0
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The value an encoder answers for a code outside its grammar.
|
|
35
|
+
*/
|
|
36
|
+
export const NO_KEY = -1
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The length of a two-letter code.
|
|
40
|
+
*/
|
|
41
|
+
export const CODE_LENGTH_2 = 2
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The length of a three-letter or three-digit code.
|
|
45
|
+
*/
|
|
46
|
+
export const CODE_LENGTH_3 = 3
|
|
47
|
+
|
|
48
|
+
const LETTERS = 26
|
|
49
|
+
const A = 65
|
|
50
|
+
const Z = 90
|
|
51
|
+
const ZERO = 48
|
|
52
|
+
const NINE = 57
|
|
53
|
+
const DECIMAL = 10
|
|
54
|
+
|
|
55
|
+
function isUpperLetter(charCode: number): boolean {
|
|
56
|
+
return charCode >= A && charCode <= Z
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Encodes two upper-case ASCII letters, or answers {@link NO_KEY}.
|
|
61
|
+
*/
|
|
62
|
+
export function encode2(code: string): number {
|
|
63
|
+
if (code.length !== CODE_LENGTH_2) return NO_KEY
|
|
64
|
+
|
|
65
|
+
const a = code.charCodeAt(0)
|
|
66
|
+
const b = code.charCodeAt(1)
|
|
67
|
+
|
|
68
|
+
if (!isUpperLetter(a) || !isUpperLetter(b)) return NO_KEY
|
|
69
|
+
|
|
70
|
+
return (a - A) * LETTERS + (b - A)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Encodes three upper-case ASCII letters, or answers {@link NO_KEY}.
|
|
75
|
+
*/
|
|
76
|
+
export function encode3(code: string): number {
|
|
77
|
+
if (code.length !== CODE_LENGTH_3) return NO_KEY
|
|
78
|
+
|
|
79
|
+
const a = code.charCodeAt(0)
|
|
80
|
+
const b = code.charCodeAt(1)
|
|
81
|
+
const c = code.charCodeAt(2)
|
|
82
|
+
|
|
83
|
+
if (!isUpperLetter(a) || !isUpperLetter(b) || !isUpperLetter(c)) return NO_KEY
|
|
84
|
+
|
|
85
|
+
return ((a - A) * LETTERS + (b - A)) * LETTERS + (c - A)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Encodes three ASCII digits, keeping a leading zero's position, or answers {@link NO_KEY}.
|
|
90
|
+
*/
|
|
91
|
+
export function encodeNumeric(code: string): number {
|
|
92
|
+
if (code.length !== CODE_LENGTH_3) return NO_KEY
|
|
93
|
+
|
|
94
|
+
let value = 0
|
|
95
|
+
|
|
96
|
+
for (let index = 0; index < CODE_LENGTH_3; index++) {
|
|
97
|
+
const digit = code.charCodeAt(index)
|
|
98
|
+
|
|
99
|
+
if (digit < ZERO || digit > NINE) return NO_KEY
|
|
100
|
+
|
|
101
|
+
value = value * DECIMAL + (digit - ZERO)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return value
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Encodes a code for the arity a section declares.
|
|
109
|
+
*/
|
|
110
|
+
export function encodeForArity(arity: number, code: string): number {
|
|
111
|
+
switch (arity) {
|
|
112
|
+
case ARITY_NUMERIC:
|
|
113
|
+
return encodeNumeric(code)
|
|
114
|
+
case CODE_LENGTH_2:
|
|
115
|
+
return encode2(code)
|
|
116
|
+
case CODE_LENGTH_3:
|
|
117
|
+
return encode3(code)
|
|
118
|
+
default:
|
|
119
|
+
return NO_KEY
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The three letters of a three-letter key.
|
|
125
|
+
*/
|
|
126
|
+
export function decode3(key: number): string {
|
|
127
|
+
return String.fromCharCode(
|
|
128
|
+
A + Math.floor(key / KEY_SPACE_2),
|
|
129
|
+
A + (Math.floor(key / LETTERS) % LETTERS),
|
|
130
|
+
A + (key % LETTERS)
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The two letters of a two-letter key.
|
|
136
|
+
*/
|
|
137
|
+
export function decode2(key: number): string {
|
|
138
|
+
return String.fromCharCode(A + Math.floor(key / LETTERS), A + (key % LETTERS))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The three digits of a numeric key, with its leading zeroes.
|
|
143
|
+
*/
|
|
144
|
+
export function decodeNumeric(key: number): string {
|
|
145
|
+
return String(key).padStart(CODE_LENGTH_3, "0")
|
|
146
|
+
}
|
package/lib/normalize.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Explicit input normalization, separate from the strict predicates.
|
|
7
|
+
*
|
|
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.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* What {@link canonicalSpelling} changed.
|
|
16
|
+
*/
|
|
17
|
+
export interface Normalization {
|
|
18
|
+
value: string
|
|
19
|
+
trimmed: boolean
|
|
20
|
+
uppercased: boolean
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Trims ASCII whitespace and upper-cases ASCII letters, reporting each change.
|
|
25
|
+
*/
|
|
26
|
+
export function canonicalSpelling(input: string): Normalization {
|
|
27
|
+
const trimmedValue = input.replaceAll(/^[ \t\r\n]+|[ \t\r\n]+$/g, "")
|
|
28
|
+
const value = trimmedValue.replaceAll(/[a-z]+/g, (run) => run.toUpperCase())
|
|
29
|
+
|
|
30
|
+
return { value, trimmed: trimmedValue !== input, uppercased: value !== trimmedValue }
|
|
31
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
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
|
+
*
|
|
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.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { countryAirportCollisionArtifact } from "#artifacts/country-airport-collision"
|
|
17
|
+
import { airportRowByIATA, getAirportByIATA } from "#iata/airports/records"
|
|
18
|
+
import { getCountryByAlpha3 } from "#iso3166/records"
|
|
19
|
+
import { encode3 } from "#key"
|
|
20
|
+
import { Artifact } from "#rgy1/reader"
|
|
21
|
+
import { BitsetView } from "#rgy1/views"
|
|
22
|
+
import { type AirportCountryStatus, CountryStatus, type IATA, type ISO } from "#types"
|
|
23
|
+
|
|
24
|
+
let bitset: BitsetView | null = null
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns the collision bitset, parsing the artifact on first use.
|
|
28
|
+
*/
|
|
29
|
+
export function collisionMembership(): BitsetView {
|
|
30
|
+
bitset ??= BitsetView.of(Artifact.parse(countryAirportCollisionArtifact()))
|
|
31
|
+
|
|
32
|
+
return bitset
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Whether a three-letter code in its canonical spelling is both a current country code and an airport code.
|
|
37
|
+
*/
|
|
38
|
+
export function isCountryAirportCollision(input: string): boolean {
|
|
39
|
+
return collisionMembership().test(encode3(input))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* One interpretation of a three-letter spelling.
|
|
44
|
+
*/
|
|
45
|
+
export type CodeMatch =
|
|
46
|
+
| {
|
|
47
|
+
system: "iso3166-1-alpha3"
|
|
48
|
+
code: ISO.CountryCode_3166_1_Alpha3
|
|
49
|
+
/**
|
|
50
|
+
* The alpha-2 code of the same entity.
|
|
51
|
+
*/
|
|
52
|
+
country: string
|
|
53
|
+
entityID: string
|
|
54
|
+
name: string
|
|
55
|
+
}
|
|
56
|
+
| {
|
|
57
|
+
system: "iata-location"
|
|
58
|
+
code: IATA.AirportCode
|
|
59
|
+
kind: "airport"
|
|
60
|
+
/**
|
|
61
|
+
* The alpha-2 code the source places the airport in, or null for an extension or an unstated country.
|
|
62
|
+
*/
|
|
63
|
+
country: string | null
|
|
64
|
+
countryStatus: AirportCountryStatus
|
|
65
|
+
entityID: string
|
|
66
|
+
name: string
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Every namespace that holds the spelling, in namespace order: country first, then airport.
|
|
71
|
+
*
|
|
72
|
+
* The order is the namespace list's and is not a ranking.
|
|
73
|
+
* 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.
|
|
75
|
+
*/
|
|
76
|
+
export function interpretCountryOrAirportCode(input: string): CodeMatch[] {
|
|
77
|
+
const matches: CodeMatch[] = []
|
|
78
|
+
|
|
79
|
+
if (encode3(input) < 0) return matches
|
|
80
|
+
|
|
81
|
+
const country = getCountryByAlpha3(input)
|
|
82
|
+
|
|
83
|
+
if (country && country.status === CountryStatus.OfficiallyAssigned) {
|
|
84
|
+
matches.push({
|
|
85
|
+
system: "iso3166-1-alpha3",
|
|
86
|
+
code: input as ISO.CountryCode_3166_1_Alpha3,
|
|
87
|
+
country: country.alpha2,
|
|
88
|
+
entityID: country.entityID,
|
|
89
|
+
name: country.name,
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (airportRowByIATA(input) >= 0) {
|
|
94
|
+
const airport = getAirportByIATA(input)!
|
|
95
|
+
|
|
96
|
+
matches.push({
|
|
97
|
+
system: "iata-location",
|
|
98
|
+
code: airport.iata,
|
|
99
|
+
kind: "airport",
|
|
100
|
+
country: airport.countryStatus === "iso3166-1" ? airport.country : null,
|
|
101
|
+
countryStatus: airport.countryStatus,
|
|
102
|
+
entityID: airport.entityID,
|
|
103
|
+
name: airport.name,
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return matches
|
|
108
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Decodes a generated artifact module's base64 text into bytes, on the platforms the readers run on.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Decodes standard base64 into a fresh `Uint8Array`.
|
|
11
|
+
*
|
|
12
|
+
* `atob` is a global in Node 16 and later and in every browser, so the decoder
|
|
13
|
+
* needs no `Buffer` and no `node:` import.
|
|
14
|
+
*/
|
|
15
|
+
export function decodeBase64(text: string): Uint8Array {
|
|
16
|
+
const binary = atob(text)
|
|
17
|
+
const bytes = new Uint8Array(binary.length)
|
|
18
|
+
|
|
19
|
+
for (let index = 0; index < binary.length; index++) {
|
|
20
|
+
bytes[index] = binary.charCodeAt(index)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return bytes
|
|
24
|
+
}
|