@mailwoman/codex 4.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/out/ca/index.d.ts +12 -0
- package/out/ca/index.d.ts.map +1 -0
- package/out/ca/index.js +12 -0
- package/out/ca/index.js.map +1 -0
- package/out/ca/postal-code.d.ts +74 -0
- package/out/ca/postal-code.d.ts.map +1 -0
- package/out/ca/postal-code.js +100 -0
- package/out/ca/postal-code.js.map +1 -0
- package/out/ca/province.d.ts +114 -0
- package/out/ca/province.d.ts.map +1 -0
- package/out/ca/province.js +79 -0
- package/out/ca/province.js.map +1 -0
- package/out/ca/street-type.d.ts +57 -0
- package/out/ca/street-type.d.ts.map +1 -0
- package/out/ca/street-type.js +156 -0
- package/out/ca/street-type.js.map +1 -0
- package/out/de/bundesland.d.ts +124 -0
- package/out/de/bundesland.d.ts.map +1 -0
- package/out/de/bundesland.js +81 -0
- package/out/de/bundesland.js.map +1 -0
- package/out/de/index.d.ts +12 -0
- package/out/de/index.d.ts.map +1 -0
- package/out/de/index.js +12 -0
- package/out/de/index.js.map +1 -0
- package/out/de/postleitzahl.d.ts +108 -0
- package/out/de/postleitzahl.d.ts.map +1 -0
- package/out/de/postleitzahl.js +63 -0
- package/out/de/postleitzahl.js.map +1 -0
- package/out/de/street-type.d.ts +58 -0
- package/out/de/street-type.d.ts.map +1 -0
- package/out/de/street-type.js +79 -0
- package/out/de/street-type.js.map +1 -0
- package/out/fr/code-postal.d.ts +68 -0
- package/out/fr/code-postal.d.ts.map +1 -0
- package/out/fr/code-postal.js +84 -0
- package/out/fr/code-postal.js.map +1 -0
- package/out/fr/departement.d.ts +538 -0
- package/out/fr/departement.d.ts.map +1 -0
- package/out/fr/departement.js +127 -0
- package/out/fr/departement.js.map +1 -0
- package/out/fr/index.d.ts +13 -0
- package/out/fr/index.d.ts.map +1 -0
- package/out/fr/index.js +13 -0
- package/out/fr/index.js.map +1 -0
- package/out/fr/region.d.ts +113 -0
- package/out/fr/region.d.ts.map +1 -0
- package/out/fr/region.js +76 -0
- package/out/fr/region.js.map +1 -0
- package/out/fr/voie.d.ts +64 -0
- package/out/fr/voie.d.ts.map +1 -0
- package/out/fr/voie.js +88 -0
- package/out/fr/voie.js.map +1 -0
- package/out/gb/country.d.ts +51 -0
- package/out/gb/country.d.ts.map +1 -0
- package/out/gb/country.js +56 -0
- package/out/gb/country.js.map +1 -0
- package/out/gb/index.d.ts +14 -0
- package/out/gb/index.d.ts.map +1 -0
- package/out/gb/index.js +14 -0
- package/out/gb/index.js.map +1 -0
- package/out/gb/postcode-area.d.ts +46 -0
- package/out/gb/postcode-area.d.ts.map +1 -0
- package/out/gb/postcode-area.js +101 -0
- package/out/gb/postcode-area.js.map +1 -0
- package/out/gb/postcode.d.ts +73 -0
- package/out/gb/postcode.d.ts.map +1 -0
- package/out/gb/postcode.js +88 -0
- package/out/gb/postcode.js.map +1 -0
- package/out/gb/street-type.d.ts +36 -0
- package/out/gb/street-type.d.ts.map +1 -0
- package/out/gb/street-type.js +86 -0
- package/out/gb/street-type.js.map +1 -0
- package/out/index.d.ts +27 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +27 -0
- package/out/index.js.map +1 -0
- package/out/jp/address-unit.d.ts +72 -0
- package/out/jp/address-unit.d.ts.map +1 -0
- package/out/jp/address-unit.js +78 -0
- package/out/jp/address-unit.js.map +1 -0
- package/out/jp/index.d.ts +13 -0
- package/out/jp/index.d.ts.map +1 -0
- package/out/jp/index.js +13 -0
- package/out/jp/index.js.map +1 -0
- package/out/jp/postal-code.d.ts +63 -0
- package/out/jp/postal-code.d.ts.map +1 -0
- package/out/jp/postal-code.js +77 -0
- package/out/jp/postal-code.js.map +1 -0
- package/out/jp/prefecture.d.ts +347 -0
- package/out/jp/prefecture.d.ts.map +1 -0
- package/out/jp/prefecture.js +147 -0
- package/out/jp/prefecture.js.map +1 -0
- package/out/postcode-systems.d.ts +31 -0
- package/out/postcode-systems.d.ts.map +1 -0
- package/out/postcode-systems.js +58 -0
- package/out/postcode-systems.js.map +1 -0
- package/out/us/index.d.ts +12 -0
- package/out/us/index.d.ts.map +1 -0
- package/out/us/index.js +12 -0
- package/out/us/index.js.map +1 -0
- package/out/us/state.d.ts +26 -0
- package/out/us/state.d.ts.map +1 -0
- package/out/us/state.js +84 -0
- package/out/us/state.js.map +1 -0
- package/out/us/street-suffix.d.ts +499 -0
- package/out/us/street-suffix.d.ts.map +1 -0
- package/out/us/street-suffix.js +313 -0
- package/out/us/street-suffix.js.map +1 -0
- package/out/us/zipcode.d.ts +184 -0
- package/out/us/zipcode.d.ts.map +1 -0
- package/out/us/zipcode.js +127 -0
- package/out/us/zipcode.js.map +1 -0
- package/package.json +34 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The four constituent countries of the United Kingdom, keyed by their ISO 3166-2:GB code: England
|
|
7
|
+
* (`ENG`), Scotland (`SCT`), Wales (`WLS`), Northern Ireland (`NIR`).
|
|
8
|
+
*
|
|
9
|
+
* The UK's top-level admin tier is itself the first oddity of this system. France has régions,
|
|
10
|
+
* Germany has Bundesländer, the US has states — a single flat layer. The UK has _countries_
|
|
11
|
+
* inside a country, and an address almost never names which one: a line reads `street, town,
|
|
12
|
+
* postcode`, and the constituent country is inferred — usually, but not always cleanly, from the
|
|
13
|
+
* postcode area (see `postcode-area.ts`). So this file is the coarse admin label, and the
|
|
14
|
+
* postcode is the thing that actually carries the geography.
|
|
15
|
+
*/
|
|
16
|
+
/** ISO 3166-2:GB country code → info, for all four constituent countries. */
|
|
17
|
+
export const GB_COUNTRIES = {
|
|
18
|
+
ENG: { code: "ENG", name: "England" },
|
|
19
|
+
SCT: { code: "SCT", name: "Scotland" },
|
|
20
|
+
WLS: { code: "WLS", name: "Wales" },
|
|
21
|
+
NIR: { code: "NIR", name: "Northern Ireland" },
|
|
22
|
+
};
|
|
23
|
+
const COUNTRY_CODE_SET = new Set(Object.keys(GB_COUNTRIES));
|
|
24
|
+
/** Type-predicate for an ISO 3166-2:GB country code. Case-insensitive. */
|
|
25
|
+
export function isUkCountryCode(input) {
|
|
26
|
+
return typeof input === "string" && COUNTRY_CODE_SET.has(input.toUpperCase());
|
|
27
|
+
}
|
|
28
|
+
/** Lowercase + collapse non-alphanumerics so `Northern Ireland`, `northern-ireland` key alike. */
|
|
29
|
+
function foldName(s) {
|
|
30
|
+
return s
|
|
31
|
+
.toLowerCase()
|
|
32
|
+
.replace(/[^a-z0-9]+/g, " ")
|
|
33
|
+
.trim();
|
|
34
|
+
}
|
|
35
|
+
/** Folded country name / code → ISO 3166-2:GB code, so a surface form maps regardless of casing. */
|
|
36
|
+
const COUNTRY_NAME_TO_CODE = (() => {
|
|
37
|
+
const out = new Map();
|
|
38
|
+
for (const code of Object.keys(GB_COUNTRIES)) {
|
|
39
|
+
out.set(foldName(GB_COUNTRIES[code].name), code);
|
|
40
|
+
out.set(code.toLowerCase(), code);
|
|
41
|
+
}
|
|
42
|
+
return out;
|
|
43
|
+
})();
|
|
44
|
+
/**
|
|
45
|
+
* Resolve a UK constituent-country surface form (ISO code or English name) to its ISO code; null if
|
|
46
|
+
* unknown. Accepts `ENG`, `England`, `Northern Ireland`, `scotland`, etc.
|
|
47
|
+
*/
|
|
48
|
+
export function lookupUkCountry(input) {
|
|
49
|
+
if (!input || typeof input !== "string")
|
|
50
|
+
return null;
|
|
51
|
+
const upper = input.trim().toUpperCase();
|
|
52
|
+
if (COUNTRY_CODE_SET.has(upper))
|
|
53
|
+
return upper;
|
|
54
|
+
return COUNTRY_NAME_TO_CODE.get(foldName(input)) ?? null;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=country.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"country.js","sourceRoot":"","sources":["../../gb/country.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAUH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG;IAC3B,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE;IACrC,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE;IACtC,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE;IACnC,GAAG,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE;CACG,CAAA;AAKlD,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAA;AAEhF,0EAA0E;AAC1E,MAAM,UAAU,eAAe,CAAC,KAAc;IAC7C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;AAC9E,CAAC;AAED,kGAAkG;AAClG,SAAS,QAAQ,CAAC,CAAS;IAC1B,OAAO,CAAC;SACN,WAAW,EAAE;SACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;SAC3B,IAAI,EAAE,CAAA;AACT,CAAC;AAED,oGAAoG;AACpG,MAAM,oBAAoB,GAAuC,CAAC,GAAG,EAAE;IACtE,MAAM,GAAG,GAAG,IAAI,GAAG,EAAyB,CAAA;IAC5C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAoB,EAAE,CAAC;QACjE,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,CAAA;QAChD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAA;IAClC,CAAC;IACD,OAAO,GAAG,CAAA;AACX,CAAC,CAAC,EAAE,CAAA;AAEJ;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,KAAgC;IAC/D,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IACpD,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAA;IACxC,IAAI,gBAAgB,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO,KAAsB,CAAA;IAC9D,OAAO,oBAAoB,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,CAAA;AACzD,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The United Kingdom address system (Royal Mail / ISO 3166-2:GB): the variable-length alphanumeric
|
|
7
|
+
* postcode and its Royal-Mail postcode areas, the four constituent countries, and British street
|
|
8
|
+
* vocabulary.
|
|
9
|
+
*/
|
|
10
|
+
export * from "./country.js";
|
|
11
|
+
export * from "./postcode-area.js";
|
|
12
|
+
export * from "./postcode.js";
|
|
13
|
+
export * from "./street-type.js";
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../gb/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
|
package/out/gb/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The United Kingdom address system (Royal Mail / ISO 3166-2:GB): the variable-length alphanumeric
|
|
7
|
+
* postcode and its Royal-Mail postcode areas, the four constituent countries, and British street
|
|
8
|
+
* vocabulary.
|
|
9
|
+
*/
|
|
10
|
+
export * from "./country.js";
|
|
11
|
+
export * from "./postcode-area.js";
|
|
12
|
+
export * from "./postcode.js";
|
|
13
|
+
export * from "./street-type.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../gb/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,cAAc,CAAA;AAC5B,cAAc,oBAAoB,CAAA;AAClC,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Postcode AREA → constituent country, the Royal Mail mapping — and the concrete proof of the
|
|
7
|
+
* lesson in `postcode.ts` that UK postcodes do NOT track administrative geography.
|
|
8
|
+
*
|
|
9
|
+
* A postcode area is the leading one or two letters of a postcode (`SW`, `M`, `EH`, `BT`), named
|
|
10
|
+
* after the sorting town Royal Mail routes it through, NOT after a county or a constituent
|
|
11
|
+
* country. There is no clean postcode→admin hierarchy to inherit the way France gives you a
|
|
12
|
+
* département from the first two digits. The only honest thing we _can_ derive is which of the
|
|
13
|
+
* four UK countries an area predominantly falls in — and even that has border exceptions:
|
|
14
|
+
*
|
|
15
|
+
* - **TD** (Galashiels) and **SY** (Shrewsbury) straddle the Scotland/England and Wales/England
|
|
16
|
+
* borders respectively; each is assigned to its MAJORITY country here (TD → Scotland, SY →
|
|
17
|
+
* Wales). A handful of individual postcodes on the wrong side of the line are a gazetteer
|
|
18
|
+
* concern, not a thing this coarse table tries to model.
|
|
19
|
+
*
|
|
20
|
+
* So this is the ROYAL MAIL area→country mapping, and the fact that it needs a hand-built
|
|
21
|
+
* non-England set with documented border fudges — rather than a tidy prefix rule — is exactly why
|
|
22
|
+
* a UK postcode is not a county.
|
|
23
|
+
*/
|
|
24
|
+
import type { UkCountryCode } from "./country.js";
|
|
25
|
+
/**
|
|
26
|
+
* The explicit non-England postcode areas, area → constituent country. England is intentionally
|
|
27
|
+
* absent: it is the DEFAULT (the great majority of UK areas are English), so listing it would be
|
|
28
|
+
* both enormous and a maintenance trap. Keeping only the non-England set makes the default
|
|
29
|
+
* transparent — anything not named here is England.
|
|
30
|
+
*/
|
|
31
|
+
export declare const GB_POSTCODE_AREA_COUNTRY: Record<string, UkCountryCode>;
|
|
32
|
+
/**
|
|
33
|
+
* The constituent country a postcode AREA belongs to. Returns the explicit country for a known
|
|
34
|
+
* non-England area (e.g. `BT` → `NIR`, `G` → `SCT`, `CF` → `WLS`), and `ENG` as the default for any
|
|
35
|
+
* other validly-shaped area — England is by far the largest, so the default is transparent and the
|
|
36
|
+
* non-England exceptions live in {@link GB_POSTCODE_AREA_COUNTRY}. Returns null for clearly-invalid
|
|
37
|
+
* input (not one-or-two letters), so a malformed token is not silently called England.
|
|
38
|
+
*/
|
|
39
|
+
export declare function countryOfPostcodeArea(area: unknown): UkCountryCode | null;
|
|
40
|
+
/**
|
|
41
|
+
* The constituent country a whole postcode resolves to, by extracting its area. `BT1 1AA` → `NIR`,
|
|
42
|
+
* `EH1 1BB` → `SCT`, `CF10 1AA` → `WLS`, `SW1A 1AA` → `ENG`. Null if the input has no extractable
|
|
43
|
+
* postcode area.
|
|
44
|
+
*/
|
|
45
|
+
export declare function countryOfPostcode(postcode: unknown): UkCountryCode | null;
|
|
46
|
+
//# sourceMappingURL=postcode-area.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postcode-area.d.ts","sourceRoot":"","sources":["../../gb/postcode-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAyCjD;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAIlE,CAAA;AAOD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAGzE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAMzE"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Postcode AREA → constituent country, the Royal Mail mapping — and the concrete proof of the
|
|
7
|
+
* lesson in `postcode.ts` that UK postcodes do NOT track administrative geography.
|
|
8
|
+
*
|
|
9
|
+
* A postcode area is the leading one or two letters of a postcode (`SW`, `M`, `EH`, `BT`), named
|
|
10
|
+
* after the sorting town Royal Mail routes it through, NOT after a county or a constituent
|
|
11
|
+
* country. There is no clean postcode→admin hierarchy to inherit the way France gives you a
|
|
12
|
+
* département from the first two digits. The only honest thing we _can_ derive is which of the
|
|
13
|
+
* four UK countries an area predominantly falls in — and even that has border exceptions:
|
|
14
|
+
*
|
|
15
|
+
* - **TD** (Galashiels) and **SY** (Shrewsbury) straddle the Scotland/England and Wales/England
|
|
16
|
+
* borders respectively; each is assigned to its MAJORITY country here (TD → Scotland, SY →
|
|
17
|
+
* Wales). A handful of individual postcodes on the wrong side of the line are a gazetteer
|
|
18
|
+
* concern, not a thing this coarse table tries to model.
|
|
19
|
+
*
|
|
20
|
+
* So this is the ROYAL MAIL area→country mapping, and the fact that it needs a hand-built
|
|
21
|
+
* non-England set with documented border fudges — rather than a tidy prefix rule — is exactly why
|
|
22
|
+
* a UK postcode is not a county.
|
|
23
|
+
*/
|
|
24
|
+
/** Northern Ireland is a single postcode area: BT (Belfast). */
|
|
25
|
+
const NORTHERN_IRELAND_AREAS = ["BT"];
|
|
26
|
+
/**
|
|
27
|
+
* Scotland's postcode areas. TD (Galashiels) straddles the border with England and is assigned to
|
|
28
|
+
* Scotland as its majority country.
|
|
29
|
+
*/
|
|
30
|
+
const SCOTLAND_AREAS = [
|
|
31
|
+
"AB", // Aberdeen
|
|
32
|
+
"DD", // Dundee
|
|
33
|
+
"DG", // Dumfries
|
|
34
|
+
"EH", // Edinburgh
|
|
35
|
+
"FK", // Falkirk
|
|
36
|
+
"G", // Glasgow
|
|
37
|
+
"HS", // Outer Hebrides (Na h-Eileanan Siar)
|
|
38
|
+
"IV", // Inverness
|
|
39
|
+
"KA", // Kilmarnock
|
|
40
|
+
"KW", // Kirkwall (Orkney + Caithness)
|
|
41
|
+
"KY", // Kirkcaldy (Fife)
|
|
42
|
+
"ML", // Motherwell
|
|
43
|
+
"PA", // Paisley
|
|
44
|
+
"PH", // Perth
|
|
45
|
+
"TD", // Galashiels (Scottish Borders) — straddles the England border, majority Scotland
|
|
46
|
+
"ZE", // Lerwick (Shetland)
|
|
47
|
+
];
|
|
48
|
+
/**
|
|
49
|
+
* Wales's postcode areas. SY (Shrewsbury) straddles the border with England and is assigned to
|
|
50
|
+
* Wales as its majority country.
|
|
51
|
+
*/
|
|
52
|
+
const WALES_AREAS = [
|
|
53
|
+
"CF", // Cardiff
|
|
54
|
+
"LD", // Llandrindod Wells
|
|
55
|
+
"LL", // Llandudno
|
|
56
|
+
"NP", // Newport
|
|
57
|
+
"SA", // Swansea
|
|
58
|
+
"SY", // Shrewsbury — straddles the Wales/England border, majority Wales
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* The explicit non-England postcode areas, area → constituent country. England is intentionally
|
|
62
|
+
* absent: it is the DEFAULT (the great majority of UK areas are English), so listing it would be
|
|
63
|
+
* both enormous and a maintenance trap. Keeping only the non-England set makes the default
|
|
64
|
+
* transparent — anything not named here is England.
|
|
65
|
+
*/
|
|
66
|
+
export const GB_POSTCODE_AREA_COUNTRY = {
|
|
67
|
+
...Object.fromEntries(NORTHERN_IRELAND_AREAS.map((a) => [a, "NIR"])),
|
|
68
|
+
...Object.fromEntries(SCOTLAND_AREAS.map((a) => [a, "SCT"])),
|
|
69
|
+
...Object.fromEntries(WALES_AREAS.map((a) => [a, "WLS"])),
|
|
70
|
+
};
|
|
71
|
+
/** True when `area` looks like a valid postcode-area string: one or two ASCII letters. */
|
|
72
|
+
function isAreaShape(area) {
|
|
73
|
+
return typeof area === "string" && /^[A-Z]{1,2}$/i.test(area);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The constituent country a postcode AREA belongs to. Returns the explicit country for a known
|
|
77
|
+
* non-England area (e.g. `BT` → `NIR`, `G` → `SCT`, `CF` → `WLS`), and `ENG` as the default for any
|
|
78
|
+
* other validly-shaped area — England is by far the largest, so the default is transparent and the
|
|
79
|
+
* non-England exceptions live in {@link GB_POSTCODE_AREA_COUNTRY}. Returns null for clearly-invalid
|
|
80
|
+
* input (not one-or-two letters), so a malformed token is not silently called England.
|
|
81
|
+
*/
|
|
82
|
+
export function countryOfPostcodeArea(area) {
|
|
83
|
+
if (!isAreaShape(area))
|
|
84
|
+
return null;
|
|
85
|
+
return GB_POSTCODE_AREA_COUNTRY[area.toUpperCase()] ?? "ENG";
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* The constituent country a whole postcode resolves to, by extracting its area. `BT1 1AA` → `NIR`,
|
|
89
|
+
* `EH1 1BB` → `SCT`, `CF10 1AA` → `WLS`, `SW1A 1AA` → `ENG`. Null if the input has no extractable
|
|
90
|
+
* postcode area.
|
|
91
|
+
*/
|
|
92
|
+
export function countryOfPostcode(postcode) {
|
|
93
|
+
if (typeof postcode !== "string")
|
|
94
|
+
return null;
|
|
95
|
+
// Extract the leading 1-2 letters directly, tolerating the inward code / spacing.
|
|
96
|
+
const match = /^\s*([A-Z]{1,2})/i.exec(postcode);
|
|
97
|
+
if (!match)
|
|
98
|
+
return null;
|
|
99
|
+
return countryOfPostcodeArea(match[1]);
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=postcode-area.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postcode-area.js","sourceRoot":"","sources":["../../gb/postcode-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,gEAAgE;AAChE,MAAM,sBAAsB,GAAG,CAAC,IAAI,CAAU,CAAA;AAE9C;;;GAGG;AACH,MAAM,cAAc,GAAG;IACtB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,SAAS;IACf,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,UAAU;IAChB,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,sCAAsC;IAC5C,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,aAAa;IACnB,IAAI,EAAE,gCAAgC;IACtC,IAAI,EAAE,mBAAmB;IACzB,IAAI,EAAE,aAAa;IACnB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,kFAAkF;IACxF,IAAI,EAAE,qBAAqB;CAClB,CAAA;AAEV;;;GAGG;AACH,MAAM,WAAW,GAAG;IACnB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,oBAAoB;IAC1B,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,kEAAkE;CAC/D,CAAA;AAEV;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAkC;IACtE,GAAG,MAAM,CAAC,WAAW,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAc,CAAC,CAAC,CAAC;IAC7E,GAAG,MAAM,CAAC,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAc,CAAC,CAAC,CAAC;IACrE,GAAG,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAc,CAAC,CAAC,CAAC;CAClE,CAAA;AAED,0FAA0F;AAC1F,SAAS,WAAW,CAAC,IAAa;IACjC,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC9D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAa;IAClD,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IACnC,OAAO,wBAAwB,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,IAAI,KAAK,CAAA;AAC7D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAiB;IAClD,IAAI,OAAO,QAAQ,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IAC7C,kFAAkF;IAClF,MAAM,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAChD,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAA;IACvB,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* UK postcodes: the branded type, the validation shape, normalization, and the outward/inward
|
|
7
|
+
* split.
|
|
8
|
+
*
|
|
9
|
+
* This is the MOST COMPLEX postcode of any system in the codex, and the contrast is the whole point
|
|
10
|
+
* of the file. A US ZIP, a German PLZ, and a French code postal are all a fixed five digits — the
|
|
11
|
+
* shape is trivial and the only interesting question is what admin unit the prefix maps to. The
|
|
12
|
+
* UK postcode is none of that:
|
|
13
|
+
*
|
|
14
|
+
* - It is **variable-length alphanumeric**, from six characters (`M1 1AE`) to eight (`SW1A 1AA`),
|
|
15
|
+
* across forms like `B33 8TH`, `CR2 6XH`, `DN55 1PT`.
|
|
16
|
+
* - It splits into an **OUTWARD code** (area + district, the part before the space — `SW1A`) and an
|
|
17
|
+
* **INWARD code** (sector + unit, the three chars after — `1AA`). Royal Mail sorts on the
|
|
18
|
+
* outward to a delivery office, then on the inward to a walk.
|
|
19
|
+
* - And — the lesson that propagates to `postcode-area.ts` — it does **NOT align with administrative
|
|
20
|
+
* geography**. A postcode area is a Royal Mail routing construct named after a sorting town
|
|
21
|
+
* (`SW` = south-west London, `EH` = Edinburgh), NOT a county or a constituent country. You
|
|
22
|
+
* cannot read a county off a UK postcode the way you read a département off a French one; the
|
|
23
|
+
* postcode→country mapping in `postcode-area.ts` exists precisely _because_ there is no clean
|
|
24
|
+
* hierarchy to inherit.
|
|
25
|
+
*
|
|
26
|
+
* So unlike the other systems, the hard work here is the shape itself — validating, normalizing the
|
|
27
|
+
* internal space, and cleaving outward from inward — not a prefix→admin lookup.
|
|
28
|
+
*/
|
|
29
|
+
import type { Tagged } from "type-fest";
|
|
30
|
+
/**
|
|
31
|
+
* A UK postcode: variable-length alphanumeric, outward + inward (`SW1A 1AA`, `M1 1AE`). The
|
|
32
|
+
* canonical form carries exactly one space before the final three characters. Unlike a US/DE/FR
|
|
33
|
+
* postcode, the shape is not a fixed-width numeric string — see {@link UK_POSTCODE_PATTERN}.
|
|
34
|
+
*
|
|
35
|
+
* @category Postal
|
|
36
|
+
* @type string
|
|
37
|
+
* @title UK postcode
|
|
38
|
+
* @pattern ^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$
|
|
39
|
+
*/
|
|
40
|
+
export type Postcode = Tagged<string, "UkPostcode">;
|
|
41
|
+
/**
|
|
42
|
+
* UK postcode shape. A robust, slightly permissive form of the Royal Mail / UK-gov regex: one or
|
|
43
|
+
* two leading letters (the area), a district digit, an optional district letter-or-digit, then the
|
|
44
|
+
* inward sector digit and two unit letters, with the inward space optional so an un-spaced
|
|
45
|
+
* `SW1A1AA` still validates. The full UK-gov pattern additionally whitelists the British Overseas
|
|
46
|
+
* Territory codes (`ASCN`, `STHL`, `BBND`, …); those are rare enough to leave to the gazetteer.
|
|
47
|
+
*/
|
|
48
|
+
export declare const UK_POSTCODE_PATTERN: RegExp;
|
|
49
|
+
/**
|
|
50
|
+
* Normalize a UK postcode surface form: uppercase, strip surrounding whitespace, and ensure exactly
|
|
51
|
+
* one space before the final three characters (the inward code). `sw1a1aa` → `SW1A 1AA`, `M11AE` →
|
|
52
|
+
* `M1 1AE`, `b33 8th` → `B33 8TH`. Returns null if the result is not a valid postcode.
|
|
53
|
+
*/
|
|
54
|
+
export declare function normalizeUkPostcode(raw: unknown): Postcode | null;
|
|
55
|
+
/** Type-predicate for a UK postcode surface form (space optional). */
|
|
56
|
+
export declare function isUkPostcode(input: unknown): input is Postcode;
|
|
57
|
+
/**
|
|
58
|
+
* The OUTWARD code — the part before the space (area + district), e.g. `SW1A 1AA` → `SW1A`, `M1
|
|
59
|
+
* 1AE` → `M1`. Normalizes first so an un-spaced input still cleaves correctly; null if invalid.
|
|
60
|
+
*/
|
|
61
|
+
export declare function outwardCode(pc: unknown): string | null;
|
|
62
|
+
/**
|
|
63
|
+
* The INWARD code — the three characters after the space (sector + unit), e.g. `SW1A 1AA` → `1AA`,
|
|
64
|
+
* `M1 1AE` → `1AE`. Null if invalid.
|
|
65
|
+
*/
|
|
66
|
+
export declare function inwardCode(pc: unknown): string | null;
|
|
67
|
+
/**
|
|
68
|
+
* The POSTCODE AREA — the leading one or two LETTERS of the outward code, the Royal Mail routing
|
|
69
|
+
* region named after a sorting town: `SW1A 1AA` → `SW`, `M1 1AE` → `M`, `B33 8TH` → `B`. This is
|
|
70
|
+
* the key into `postcode-area.ts`'s area→country map. Null if the input is not a valid postcode.
|
|
71
|
+
*/
|
|
72
|
+
export declare function postcodeArea(pc: unknown): string | null;
|
|
73
|
+
//# sourceMappingURL=postcode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postcode.d.ts","sourceRoot":"","sources":["../../gb/postcode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;AAEnD;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,QAAwC,CAAA;AAExE;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,QAAQ,GAAG,IAAI,CAOjE;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ,CAE9D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAItD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAIrD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAKvD"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* UK postcodes: the branded type, the validation shape, normalization, and the outward/inward
|
|
7
|
+
* split.
|
|
8
|
+
*
|
|
9
|
+
* This is the MOST COMPLEX postcode of any system in the codex, and the contrast is the whole point
|
|
10
|
+
* of the file. A US ZIP, a German PLZ, and a French code postal are all a fixed five digits — the
|
|
11
|
+
* shape is trivial and the only interesting question is what admin unit the prefix maps to. The
|
|
12
|
+
* UK postcode is none of that:
|
|
13
|
+
*
|
|
14
|
+
* - It is **variable-length alphanumeric**, from six characters (`M1 1AE`) to eight (`SW1A 1AA`),
|
|
15
|
+
* across forms like `B33 8TH`, `CR2 6XH`, `DN55 1PT`.
|
|
16
|
+
* - It splits into an **OUTWARD code** (area + district, the part before the space — `SW1A`) and an
|
|
17
|
+
* **INWARD code** (sector + unit, the three chars after — `1AA`). Royal Mail sorts on the
|
|
18
|
+
* outward to a delivery office, then on the inward to a walk.
|
|
19
|
+
* - And — the lesson that propagates to `postcode-area.ts` — it does **NOT align with administrative
|
|
20
|
+
* geography**. A postcode area is a Royal Mail routing construct named after a sorting town
|
|
21
|
+
* (`SW` = south-west London, `EH` = Edinburgh), NOT a county or a constituent country. You
|
|
22
|
+
* cannot read a county off a UK postcode the way you read a département off a French one; the
|
|
23
|
+
* postcode→country mapping in `postcode-area.ts` exists precisely _because_ there is no clean
|
|
24
|
+
* hierarchy to inherit.
|
|
25
|
+
*
|
|
26
|
+
* So unlike the other systems, the hard work here is the shape itself — validating, normalizing the
|
|
27
|
+
* internal space, and cleaving outward from inward — not a prefix→admin lookup.
|
|
28
|
+
*/
|
|
29
|
+
/**
|
|
30
|
+
* UK postcode shape. A robust, slightly permissive form of the Royal Mail / UK-gov regex: one or
|
|
31
|
+
* two leading letters (the area), a district digit, an optional district letter-or-digit, then the
|
|
32
|
+
* inward sector digit and two unit letters, with the inward space optional so an un-spaced
|
|
33
|
+
* `SW1A1AA` still validates. The full UK-gov pattern additionally whitelists the British Overseas
|
|
34
|
+
* Territory codes (`ASCN`, `STHL`, `BBND`, …); those are rare enough to leave to the gazetteer.
|
|
35
|
+
*/
|
|
36
|
+
export const UK_POSTCODE_PATTERN = /^[A-Z]{1,2}\d[A-Z\d]? ?\d[A-Z]{2}$/i;
|
|
37
|
+
/**
|
|
38
|
+
* Normalize a UK postcode surface form: uppercase, strip surrounding whitespace, and ensure exactly
|
|
39
|
+
* one space before the final three characters (the inward code). `sw1a1aa` → `SW1A 1AA`, `M11AE` →
|
|
40
|
+
* `M1 1AE`, `b33 8th` → `B33 8TH`. Returns null if the result is not a valid postcode.
|
|
41
|
+
*/
|
|
42
|
+
export function normalizeUkPostcode(raw) {
|
|
43
|
+
if (typeof raw !== "string")
|
|
44
|
+
return null;
|
|
45
|
+
// Drop all whitespace, uppercase, then re-insert the single canonical space before the inward 3.
|
|
46
|
+
const compact = raw.replace(/\s+/g, "").toUpperCase();
|
|
47
|
+
if (compact.length < 5)
|
|
48
|
+
return null;
|
|
49
|
+
const spaced = `${compact.slice(0, -3)} ${compact.slice(-3)}`;
|
|
50
|
+
return UK_POSTCODE_PATTERN.test(spaced) ? spaced : null;
|
|
51
|
+
}
|
|
52
|
+
/** Type-predicate for a UK postcode surface form (space optional). */
|
|
53
|
+
export function isUkPostcode(input) {
|
|
54
|
+
return typeof input === "string" && UK_POSTCODE_PATTERN.test(input.trim());
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The OUTWARD code — the part before the space (area + district), e.g. `SW1A 1AA` → `SW1A`, `M1
|
|
58
|
+
* 1AE` → `M1`. Normalizes first so an un-spaced input still cleaves correctly; null if invalid.
|
|
59
|
+
*/
|
|
60
|
+
export function outwardCode(pc) {
|
|
61
|
+
const normalized = normalizeUkPostcode(pc);
|
|
62
|
+
if (!normalized)
|
|
63
|
+
return null;
|
|
64
|
+
return normalized.slice(0, normalized.indexOf(" "));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The INWARD code — the three characters after the space (sector + unit), e.g. `SW1A 1AA` → `1AA`,
|
|
68
|
+
* `M1 1AE` → `1AE`. Null if invalid.
|
|
69
|
+
*/
|
|
70
|
+
export function inwardCode(pc) {
|
|
71
|
+
const normalized = normalizeUkPostcode(pc);
|
|
72
|
+
if (!normalized)
|
|
73
|
+
return null;
|
|
74
|
+
return normalized.slice(normalized.indexOf(" ") + 1);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The POSTCODE AREA — the leading one or two LETTERS of the outward code, the Royal Mail routing
|
|
78
|
+
* region named after a sorting town: `SW1A 1AA` → `SW`, `M1 1AE` → `M`, `B33 8TH` → `B`. This is
|
|
79
|
+
* the key into `postcode-area.ts`'s area→country map. Null if the input is not a valid postcode.
|
|
80
|
+
*/
|
|
81
|
+
export function postcodeArea(pc) {
|
|
82
|
+
const outward = outwardCode(pc);
|
|
83
|
+
if (!outward)
|
|
84
|
+
return null;
|
|
85
|
+
const match = /^[A-Z]{1,2}/.exec(outward);
|
|
86
|
+
return match ? match[0] : null;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=postcode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postcode.js","sourceRoot":"","sources":["../../gb/postcode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAgBH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,qCAAqC,CAAA;AAExE;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAY;IAC/C,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IACxC,iGAAiG;IACjG,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAA;IACrD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,IAAI,CAAA;IACnC,MAAM,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IAC7D,OAAO,mBAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAE,MAAmB,CAAC,CAAC,CAAC,IAAI,CAAA;AACtE,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,YAAY,CAAC,KAAc;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;AAC3E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,EAAW;IACtC,MAAM,UAAU,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAA;IAC1C,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAA;IAC5B,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;AACpD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EAAW;IACrC,MAAM,UAAU,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAA;IAC1C,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAA;IAC5B,OAAO,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;AACrD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,EAAW;IACvC,MAAM,OAAO,GAAG,WAAW,CAAC,EAAE,CAAC,CAAA;IAC/B,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,CAAA;IACzB,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACzC,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAC/B,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* British street vocabulary (thoroughfare types).
|
|
7
|
+
*
|
|
8
|
+
* The contrast across the codex's street files is structural. A US street type is a trailing word
|
|
9
|
+
* with a USPS-standardized abbreviation (`Main Street` → `ST`). A German street type is a fused
|
|
10
|
+
* agglutinative suffix (`Hauptstraße`). A French type is a leading standalone word (`Rue de la
|
|
11
|
+
* Paix`). British practice is the US shape — a separate TRAILING word — but with a notably RICHER
|
|
12
|
+
* and more local vocabulary: alongside the everyday `Road`/`Street`/`Avenue` sit `Crescent`,
|
|
13
|
+
* `Mews`, `Close`, `Wynd`, `Brae`, `Gait`, `Croft`, `Dene` and a long tail of landscape words
|
|
14
|
+
* (`Brook`, `Copse`, `Dell`, `Hollow`, `Spinney`) that read as thoroughfare types in the UK and
|
|
15
|
+
* essentially nowhere else.
|
|
16
|
+
*
|
|
17
|
+
* So detection is, like French, a whole-token match — {@link isBritishStreetWord} asks "is this
|
|
18
|
+
* token a known British thoroughfare word" rather than testing a suffix — because these are
|
|
19
|
+
* distinct trailing words, not fused endings.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The British thoroughfare vocabulary. Lowercase canonical forms, matched as whole tokens. Spans
|
|
23
|
+
* the common core (`street`, `road`, `lane`, `avenue`) through the distinctively British
|
|
24
|
+
* (`crescent`, `mews`, `close`, `terrace`) and the regional/landscape tail (`wynd`, `brae`, `gait`,
|
|
25
|
+
* `croft`, `dene`, `spinney`, `dell`, `hollow`).
|
|
26
|
+
*/
|
|
27
|
+
export declare const GB_STREET_TYPES: readonly ["street", "road", "lane", "avenue", "close", "crescent", "court", "drive", "place", "way", "gardens", "grove", "terrace", "mews", "walk", "hill", "green", "park", "rise", "view", "row", "square", "parade", "vale", "wharf", "yard", "gate", "croft", "dene", "end", "fields", "meadow", "brook", "chase", "copse", "dale", "dell", "glen", "hollow", "paddock", "ridge", "spinney", "wynd", "brae", "gait"];
|
|
28
|
+
/** A canonical British thoroughfare word (e.g. `street`, `crescent`, `mews`). */
|
|
29
|
+
export type BritishStreetType = (typeof GB_STREET_TYPES)[number];
|
|
30
|
+
/**
|
|
31
|
+
* True when a token is a British thoroughfare type word (case-insensitive, whole-token match) —
|
|
32
|
+
* `Crescent`, `Mews`, `Close`, `Road`. Matches the WHOLE token, not a suffix, so an unrelated place
|
|
33
|
+
* name (`Tokyo`, `Bordeaux`) is not flagged the way an `-endsWith` test might.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isBritishStreetWord(token: unknown): boolean;
|
|
36
|
+
//# sourceMappingURL=street-type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"street-type.d.ts","sourceRoot":"","sources":["../../gb/street-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,eAAe,0ZA8ClB,CAAA;AAEV,iFAAiF;AACjF,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAA;AAIhE;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAI3D"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* British street vocabulary (thoroughfare types).
|
|
7
|
+
*
|
|
8
|
+
* The contrast across the codex's street files is structural. A US street type is a trailing word
|
|
9
|
+
* with a USPS-standardized abbreviation (`Main Street` → `ST`). A German street type is a fused
|
|
10
|
+
* agglutinative suffix (`Hauptstraße`). A French type is a leading standalone word (`Rue de la
|
|
11
|
+
* Paix`). British practice is the US shape — a separate TRAILING word — but with a notably RICHER
|
|
12
|
+
* and more local vocabulary: alongside the everyday `Road`/`Street`/`Avenue` sit `Crescent`,
|
|
13
|
+
* `Mews`, `Close`, `Wynd`, `Brae`, `Gait`, `Croft`, `Dene` and a long tail of landscape words
|
|
14
|
+
* (`Brook`, `Copse`, `Dell`, `Hollow`, `Spinney`) that read as thoroughfare types in the UK and
|
|
15
|
+
* essentially nowhere else.
|
|
16
|
+
*
|
|
17
|
+
* So detection is, like French, a whole-token match — {@link isBritishStreetWord} asks "is this
|
|
18
|
+
* token a known British thoroughfare word" rather than testing a suffix — because these are
|
|
19
|
+
* distinct trailing words, not fused endings.
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* The British thoroughfare vocabulary. Lowercase canonical forms, matched as whole tokens. Spans
|
|
23
|
+
* the common core (`street`, `road`, `lane`, `avenue`) through the distinctively British
|
|
24
|
+
* (`crescent`, `mews`, `close`, `terrace`) and the regional/landscape tail (`wynd`, `brae`, `gait`,
|
|
25
|
+
* `croft`, `dene`, `spinney`, `dell`, `hollow`).
|
|
26
|
+
*/
|
|
27
|
+
export const GB_STREET_TYPES = [
|
|
28
|
+
"street",
|
|
29
|
+
"road",
|
|
30
|
+
"lane",
|
|
31
|
+
"avenue",
|
|
32
|
+
"close",
|
|
33
|
+
"crescent",
|
|
34
|
+
"court",
|
|
35
|
+
"drive",
|
|
36
|
+
"place",
|
|
37
|
+
"way",
|
|
38
|
+
"gardens",
|
|
39
|
+
"grove",
|
|
40
|
+
"terrace",
|
|
41
|
+
"mews",
|
|
42
|
+
"walk",
|
|
43
|
+
"hill",
|
|
44
|
+
"green",
|
|
45
|
+
"park",
|
|
46
|
+
"rise",
|
|
47
|
+
"view",
|
|
48
|
+
"row",
|
|
49
|
+
"square",
|
|
50
|
+
"parade",
|
|
51
|
+
"vale",
|
|
52
|
+
"wharf",
|
|
53
|
+
"yard",
|
|
54
|
+
"gate",
|
|
55
|
+
"croft",
|
|
56
|
+
"dene",
|
|
57
|
+
"end",
|
|
58
|
+
"fields",
|
|
59
|
+
"meadow",
|
|
60
|
+
"brook",
|
|
61
|
+
"chase",
|
|
62
|
+
"copse",
|
|
63
|
+
"dale",
|
|
64
|
+
"dell",
|
|
65
|
+
"glen",
|
|
66
|
+
"hollow",
|
|
67
|
+
"paddock",
|
|
68
|
+
"ridge",
|
|
69
|
+
"spinney",
|
|
70
|
+
"wynd",
|
|
71
|
+
"brae",
|
|
72
|
+
"gait",
|
|
73
|
+
];
|
|
74
|
+
const STREET_TYPE_SET = new Set(GB_STREET_TYPES);
|
|
75
|
+
/**
|
|
76
|
+
* True when a token is a British thoroughfare type word (case-insensitive, whole-token match) —
|
|
77
|
+
* `Crescent`, `Mews`, `Close`, `Road`. Matches the WHOLE token, not a suffix, so an unrelated place
|
|
78
|
+
* name (`Tokyo`, `Bordeaux`) is not flagged the way an `-endsWith` test might.
|
|
79
|
+
*/
|
|
80
|
+
export function isBritishStreetWord(token) {
|
|
81
|
+
if (typeof token !== "string")
|
|
82
|
+
return false;
|
|
83
|
+
const t = token.toLowerCase().replace(/[^a-z]/g, "");
|
|
84
|
+
return t.length > 0 && STREET_TYPE_SET.has(t);
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=street-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"street-type.js","sourceRoot":"","sources":["../../gb/street-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC9B,QAAQ;IACR,MAAM;IACN,MAAM;IACN,QAAQ;IACR,OAAO;IACP,UAAU;IACV,OAAO;IACP,OAAO;IACP,OAAO;IACP,KAAK;IACL,SAAS;IACT,OAAO;IACP,SAAS;IACT,MAAM;IACN,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,OAAO;IACP,MAAM;IACN,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,OAAO;IACP,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,MAAM;IACN,MAAM;IACN,MAAM;CACG,CAAA;AAKV,MAAM,eAAe,GAAwB,IAAI,GAAG,CAAC,eAAe,CAAC,CAAA;AAErE;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAc;IACjD,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC3C,MAAM,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAA;IACpD,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;AAC9C,CAAC"}
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* `@mailwoman/codex` — per-address-system postal reference data and branded types.
|
|
7
|
+
*
|
|
8
|
+
* Each address system (the USPS for the United States, La Poste for France, Deutsche Post for
|
|
9
|
+
* Germany, …) has its own conventions for what a postcode, a street suffix, or a unit designator
|
|
10
|
+
* looks like. This package is the shared, dependency-free home for that reference knowledge, kept
|
|
11
|
+
* apart from the locale-agnostic tokenizer/solver in `@mailwoman/core` and from the training
|
|
12
|
+
* pipeline in `@mailwoman/corpus`. The parser, the resolver, and the synthesis layer all reach
|
|
13
|
+
* for the same tables instead of each carrying their own copy.
|
|
14
|
+
*
|
|
15
|
+
* Systems are exposed as namespaces (`import { us } from "@mailwoman/codex"`) and as subpaths
|
|
16
|
+
* (`import { lookupStreetSuffix } from "@mailwoman/codex/us"`). The cross-system
|
|
17
|
+
* `candidateSystemsForPostcode` (the inverse of the per-slice postcode patterns) is a top-level
|
|
18
|
+
* export.
|
|
19
|
+
*/
|
|
20
|
+
export * as ca from "./ca/index.js";
|
|
21
|
+
export * as de from "./de/index.js";
|
|
22
|
+
export * as fr from "./fr/index.js";
|
|
23
|
+
export * as gb from "./gb/index.js";
|
|
24
|
+
export * as jp from "./jp/index.js";
|
|
25
|
+
export { candidateSystemsForPostcode, type SystemCode } from "./postcode-systems.js";
|
|
26
|
+
export * as us from "./us/index.js";
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,EAAE,2BAA2B,EAAE,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACpF,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA"}
|
package/out/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* `@mailwoman/codex` — per-address-system postal reference data and branded types.
|
|
7
|
+
*
|
|
8
|
+
* Each address system (the USPS for the United States, La Poste for France, Deutsche Post for
|
|
9
|
+
* Germany, …) has its own conventions for what a postcode, a street suffix, or a unit designator
|
|
10
|
+
* looks like. This package is the shared, dependency-free home for that reference knowledge, kept
|
|
11
|
+
* apart from the locale-agnostic tokenizer/solver in `@mailwoman/core` and from the training
|
|
12
|
+
* pipeline in `@mailwoman/corpus`. The parser, the resolver, and the synthesis layer all reach
|
|
13
|
+
* for the same tables instead of each carrying their own copy.
|
|
14
|
+
*
|
|
15
|
+
* Systems are exposed as namespaces (`import { us } from "@mailwoman/codex"`) and as subpaths
|
|
16
|
+
* (`import { lookupStreetSuffix } from "@mailwoman/codex/us"`). The cross-system
|
|
17
|
+
* `candidateSystemsForPostcode` (the inverse of the per-slice postcode patterns) is a top-level
|
|
18
|
+
* export.
|
|
19
|
+
*/
|
|
20
|
+
export * as ca from "./ca/index.js";
|
|
21
|
+
export * as de from "./de/index.js";
|
|
22
|
+
export * as fr from "./fr/index.js";
|
|
23
|
+
export * as gb from "./gb/index.js";
|
|
24
|
+
export * as jp from "./jp/index.js";
|
|
25
|
+
export { candidateSystemsForPostcode } from "./postcode-systems.js";
|
|
26
|
+
export * as us from "./us/index.js";
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
package/out/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA;AACnC,OAAO,EAAE,2BAA2B,EAAmB,MAAM,uBAAuB,CAAA;AACpF,OAAO,KAAK,EAAE,MAAM,eAAe,CAAA"}
|