@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,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Japan's analog of a "street-type" module — except the lesson here is the absence. Where
|
|
7
|
+
* `us/street-suffix.ts` and `de/street-type.ts` exist to recognize the named-street part of an
|
|
8
|
+
* address, Japan has **no street names** to recognize. A Japanese address is built from nested
|
|
9
|
+
* administrative units and numbered blocks/lots, written largest-to-smallest:
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* 東京都 千代田区 千代田 1丁目 1番 1号
|
|
13
|
+
* Tokyo-to · Chiyoda-ku · Chiyoda · 1-chōme · 1-ban · 1-gō
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* So instead of a street-suffix table this file ships two marker sets:
|
|
17
|
+
*
|
|
18
|
+
* - {@link JP_ADMIN_SUFFIXES} — the kanji that close an administrative-area name (都/道/府/県 at the
|
|
19
|
+
* prefecture level, then 市/区/郡/町/村 for city / ward / district / town / village). These are
|
|
20
|
+
* the Japanese equivalent of a US street suffix in the parsing sense: the token-final marker
|
|
21
|
+
* that tells you what KIND of unit the preceding name is.
|
|
22
|
+
* - {@link JP_BLOCK_MARKERS} — the markers that close the numbered tail (丁目 / 番地 / 番 / 号), the part
|
|
23
|
+
* that actually does the "house number" job in the absence of streets.
|
|
24
|
+
*
|
|
25
|
+
* Note the reverse field order: the admin suffixes appear FIRST in the string (prefecture leads),
|
|
26
|
+
* and the block markers LAST — the mirror image of a US line, where the house number leads and
|
|
27
|
+
* the ZIP trails. See `postal-code.ts` for why, with no street name, the postcode is the primary
|
|
28
|
+
* anchor.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* The kanji suffixes that close an administrative-area name, largest unit to smallest:
|
|
32
|
+
*
|
|
33
|
+
* - 都 (to) — metropolis; only Tokyo.
|
|
34
|
+
* - 道 (dō) — circuit; only Hokkaido.
|
|
35
|
+
* - 府 (fu) — urban prefecture; Osaka and Kyoto.
|
|
36
|
+
* - 県 (ken) — prefecture; the other 43.
|
|
37
|
+
* - 市 (shi) — city.
|
|
38
|
+
* - 区 (ku) — ward (a subdivision of a designated city, e.g. Tokyo's 23 special wards).
|
|
39
|
+
* - 郡 (gun) — district / county (rural grouping of towns and villages).
|
|
40
|
+
* - 町 (chō / machi) — town.
|
|
41
|
+
* - 村 (son / mura) — village.
|
|
42
|
+
*/
|
|
43
|
+
export declare const JP_ADMIN_SUFFIXES: readonly ["都", "道", "府", "県", "市", "区", "郡", "町", "村"];
|
|
44
|
+
/** A single administrative-area suffix kanji (`都`, `市`, `区`, …). */
|
|
45
|
+
export type JapaneseAdminSuffix = (typeof JP_ADMIN_SUFFIXES)[number];
|
|
46
|
+
/**
|
|
47
|
+
* The markers that close the numbered tail of an address — Japan's stand-in for a house number,
|
|
48
|
+
* since there is no named street to hang one on:
|
|
49
|
+
*
|
|
50
|
+
* - 丁目 (chōme) — a district block within a neighbourhood.
|
|
51
|
+
* - 番地 (banchi) — a lot number.
|
|
52
|
+
* - 番 (ban) — block number (the `番` in the modern `chōme-ban-gō` triple).
|
|
53
|
+
* - 号 (gō) — building number (the final element of the triple).
|
|
54
|
+
*/
|
|
55
|
+
export declare const JP_BLOCK_MARKERS: readonly ["丁目", "番地", "番", "号"];
|
|
56
|
+
/** A numbered-tail marker (`丁目`, `番地`, `番`, `号`). */
|
|
57
|
+
export type JapaneseBlockMarker = (typeof JP_BLOCK_MARKERS)[number];
|
|
58
|
+
/**
|
|
59
|
+
* True when a single kanji is one of the {@link JP_ADMIN_SUFFIXES} admin-area markers (`都`, `市`,
|
|
60
|
+
* `区`, …). Strictly single-character: a multi-character input (even one ending in a suffix) is not
|
|
61
|
+
* a suffix on its own.
|
|
62
|
+
*/
|
|
63
|
+
export declare function isJapaneseAdminSuffix(ch: unknown): ch is JapaneseAdminSuffix;
|
|
64
|
+
/**
|
|
65
|
+
* Strip a trailing admin-area suffix kanji from a place name, exposing the bare name (`東京都` → `東京`,
|
|
66
|
+
* `大阪市` → `大阪`, `千代田区` → `千代田`). Leaves a name untouched if it does not end in an admin suffix.
|
|
67
|
+
*
|
|
68
|
+
* Hokkaido (`北海道`) is the deliberate exception: its name ends in 道 but is indivisible, so it is
|
|
69
|
+
* returned whole rather than clipped to `北海` — mirroring the same carve-out in `prefecture.ts`.
|
|
70
|
+
*/
|
|
71
|
+
export declare function stripAdminSuffix(name: string): string;
|
|
72
|
+
//# sourceMappingURL=address-unit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address-unit.d.ts","sourceRoot":"","sources":["../../jp/address-unit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,wDAAyD,CAAA;AAEvF,oEAAoE;AACpE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEpE;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,iCAAkC,CAAA;AAE/D,qDAAqD;AACrD,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAA;AAInE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,mBAAmB,CAE5E;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKrD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Japan's analog of a "street-type" module — except the lesson here is the absence. Where
|
|
7
|
+
* `us/street-suffix.ts` and `de/street-type.ts` exist to recognize the named-street part of an
|
|
8
|
+
* address, Japan has **no street names** to recognize. A Japanese address is built from nested
|
|
9
|
+
* administrative units and numbered blocks/lots, written largest-to-smallest:
|
|
10
|
+
*
|
|
11
|
+
* ```
|
|
12
|
+
* 東京都 千代田区 千代田 1丁目 1番 1号
|
|
13
|
+
* Tokyo-to · Chiyoda-ku · Chiyoda · 1-chōme · 1-ban · 1-gō
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* So instead of a street-suffix table this file ships two marker sets:
|
|
17
|
+
*
|
|
18
|
+
* - {@link JP_ADMIN_SUFFIXES} — the kanji that close an administrative-area name (都/道/府/県 at the
|
|
19
|
+
* prefecture level, then 市/区/郡/町/村 for city / ward / district / town / village). These are
|
|
20
|
+
* the Japanese equivalent of a US street suffix in the parsing sense: the token-final marker
|
|
21
|
+
* that tells you what KIND of unit the preceding name is.
|
|
22
|
+
* - {@link JP_BLOCK_MARKERS} — the markers that close the numbered tail (丁目 / 番地 / 番 / 号), the part
|
|
23
|
+
* that actually does the "house number" job in the absence of streets.
|
|
24
|
+
*
|
|
25
|
+
* Note the reverse field order: the admin suffixes appear FIRST in the string (prefecture leads),
|
|
26
|
+
* and the block markers LAST — the mirror image of a US line, where the house number leads and
|
|
27
|
+
* the ZIP trails. See `postal-code.ts` for why, with no street name, the postcode is the primary
|
|
28
|
+
* anchor.
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* The kanji suffixes that close an administrative-area name, largest unit to smallest:
|
|
32
|
+
*
|
|
33
|
+
* - 都 (to) — metropolis; only Tokyo.
|
|
34
|
+
* - 道 (dō) — circuit; only Hokkaido.
|
|
35
|
+
* - 府 (fu) — urban prefecture; Osaka and Kyoto.
|
|
36
|
+
* - 県 (ken) — prefecture; the other 43.
|
|
37
|
+
* - 市 (shi) — city.
|
|
38
|
+
* - 区 (ku) — ward (a subdivision of a designated city, e.g. Tokyo's 23 special wards).
|
|
39
|
+
* - 郡 (gun) — district / county (rural grouping of towns and villages).
|
|
40
|
+
* - 町 (chō / machi) — town.
|
|
41
|
+
* - 村 (son / mura) — village.
|
|
42
|
+
*/
|
|
43
|
+
export const JP_ADMIN_SUFFIXES = ["都", "道", "府", "県", "市", "区", "郡", "町", "村"];
|
|
44
|
+
/**
|
|
45
|
+
* The markers that close the numbered tail of an address — Japan's stand-in for a house number,
|
|
46
|
+
* since there is no named street to hang one on:
|
|
47
|
+
*
|
|
48
|
+
* - 丁目 (chōme) — a district block within a neighbourhood.
|
|
49
|
+
* - 番地 (banchi) — a lot number.
|
|
50
|
+
* - 番 (ban) — block number (the `番` in the modern `chōme-ban-gō` triple).
|
|
51
|
+
* - 号 (gō) — building number (the final element of the triple).
|
|
52
|
+
*/
|
|
53
|
+
export const JP_BLOCK_MARKERS = ["丁目", "番地", "番", "号"];
|
|
54
|
+
const ADMIN_SUFFIX_SET = new Set(JP_ADMIN_SUFFIXES);
|
|
55
|
+
/**
|
|
56
|
+
* True when a single kanji is one of the {@link JP_ADMIN_SUFFIXES} admin-area markers (`都`, `市`,
|
|
57
|
+
* `区`, …). Strictly single-character: a multi-character input (even one ending in a suffix) is not
|
|
58
|
+
* a suffix on its own.
|
|
59
|
+
*/
|
|
60
|
+
export function isJapaneseAdminSuffix(ch) {
|
|
61
|
+
return typeof ch === "string" && ADMIN_SUFFIX_SET.has(ch);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Strip a trailing admin-area suffix kanji from a place name, exposing the bare name (`東京都` → `東京`,
|
|
65
|
+
* `大阪市` → `大阪`, `千代田区` → `千代田`). Leaves a name untouched if it does not end in an admin suffix.
|
|
66
|
+
*
|
|
67
|
+
* Hokkaido (`北海道`) is the deliberate exception: its name ends in 道 but is indivisible, so it is
|
|
68
|
+
* returned whole rather than clipped to `北海` — mirroring the same carve-out in `prefecture.ts`.
|
|
69
|
+
*/
|
|
70
|
+
export function stripAdminSuffix(name) {
|
|
71
|
+
if (typeof name !== "string" || name.length === 0)
|
|
72
|
+
return name;
|
|
73
|
+
if (name === "北海道")
|
|
74
|
+
return name;
|
|
75
|
+
const last = name[name.length - 1];
|
|
76
|
+
return ADMIN_SUFFIX_SET.has(last) ? name.slice(0, -1) : name;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=address-unit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address-unit.js","sourceRoot":"","sources":["../../jp/address-unit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAU,CAAA;AAKvF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,CAAU,CAAA;AAK/D,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAA;AAExE;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAAW;IAChD,OAAO,OAAO,EAAE,KAAK,QAAQ,IAAI,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAY;IAC5C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAC9D,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,IAAI,CAAA;IAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAE,CAAA;IACnC,OAAO,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AAC7D,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The Japanese address system (Japan Post / ISO 3166-2:JP): the 47 prefectures, the postal code
|
|
7
|
+
* that is the country's most reliable geographic anchor, and the address-unit markers that stand
|
|
8
|
+
* in for the street names Japan does not use.
|
|
9
|
+
*/
|
|
10
|
+
export * from "./address-unit.js";
|
|
11
|
+
export * from "./postal-code.js";
|
|
12
|
+
export * from "./prefecture.js";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../jp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}
|
package/out/jp/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* The Japanese address system (Japan Post / ISO 3166-2:JP): the 47 prefectures, the postal code
|
|
7
|
+
* that is the country's most reliable geographic anchor, and the address-unit markers that stand
|
|
8
|
+
* in for the street names Japan does not use.
|
|
9
|
+
*/
|
|
10
|
+
export * from "./address-unit.js";
|
|
11
|
+
export * from "./postal-code.js";
|
|
12
|
+
export * from "./prefecture.js";
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../jp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,mBAAmB,CAAA;AACjC,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Japanese postal codes (郵便番号, yūbin-bangō): the branded type, the shape, normalization, and the
|
|
7
|
+
* first-digit → coarse-region prior.
|
|
8
|
+
*
|
|
9
|
+
* This file is the far end of a spectrum whose other end is `us/zipcode.ts`. A US address leans on
|
|
10
|
+
* the street line — a named street plus a house number — and the ZIP is a routing convenience. A
|
|
11
|
+
* Japanese address is the inverse on two counts:
|
|
12
|
+
*
|
|
13
|
+
* - It is written **largest-to-smallest**: prefecture → city/ward → district → block → lot (`東京都 千代田区
|
|
14
|
+
* 千代田 1-1`), the reverse of the US smallest-to-largest line order.
|
|
15
|
+
* - There are **essentially no street names**. Outside a few Kyoto-style exceptions, you do not
|
|
16
|
+
* navigate by named streets; you navigate by nested administrative areas and numbered
|
|
17
|
+
* blocks/lots (丁目 / 番地 / 号 — see `address-unit.ts`).
|
|
18
|
+
*
|
|
19
|
+
* With no street name to anchor on and a reverse field order, the **postal code is the single most
|
|
20
|
+
* reliable geographic anchor** for a Japanese address — it pins the chōme-level area directly,
|
|
21
|
+
* far tighter than a US ZIP pins a US address. So where the US parser treats the postcode as a
|
|
22
|
+
* tie-breaker behind the street, the Japan parser should treat it as the primary key.
|
|
23
|
+
*/
|
|
24
|
+
import type { Tagged } from "type-fest";
|
|
25
|
+
/**
|
|
26
|
+
* A Japanese postal code: three digits, a hyphen, then four digits (`100-0001`), conventionally
|
|
27
|
+
* written after the 〒 mark (`〒100-0001`). Branded so a normalized code is distinct from an
|
|
28
|
+
* arbitrary string — the 7-digit shape alone does not prove a code is real, only well-formed.
|
|
29
|
+
*
|
|
30
|
+
* @category Postal
|
|
31
|
+
* @type string
|
|
32
|
+
* @title 郵便番号
|
|
33
|
+
* @pattern ^\d{3}-?\d{4}$
|
|
34
|
+
*/
|
|
35
|
+
export type PostalCode = Tagged<string, "JpPostalCode">;
|
|
36
|
+
/** The postal-code shape: `NNN-NNNN`, the hyphen optional on input (`1000001` or `100-0001`). */
|
|
37
|
+
export declare const JP_POSTAL_CODE_PATTERN: RegExp;
|
|
38
|
+
/**
|
|
39
|
+
* Normalize a postal-code surface form to the canonical hyphenated `NNN-NNNN`: strip a leading 〒
|
|
40
|
+
* mark and any whitespace, then re-insert the hyphen if the input gave the bare seven digits
|
|
41
|
+
* (`〒100-0001` → `100-0001`, `1000001` → `100-0001`). Returns null if the result is not seven
|
|
42
|
+
* digits.
|
|
43
|
+
*/
|
|
44
|
+
export declare function normalizeJpPostalCode(raw: unknown): PostalCode | null;
|
|
45
|
+
/** Type-predicate for a Japanese postal code (hyphen optional, `100-0001` or `1000001`). */
|
|
46
|
+
export declare function isJpPostalCode(input: unknown): input is PostalCode;
|
|
47
|
+
/**
|
|
48
|
+
* First digit of the postal code → a coarse region label. Japan Post's numbering grows roughly
|
|
49
|
+
* outward from Tokyo (`1xx`) and is **approximate** at this granularity — a single leading digit
|
|
50
|
+
* spans large, irregular areas and the boundaries are postal-routing, not administrative. Use it as
|
|
51
|
+
* a weak prior, never as a hard region assignment; the full code is what actually anchors the
|
|
52
|
+
* address.
|
|
53
|
+
*
|
|
54
|
+
* Approximate — the labels below are illustrative routing regions, not precise prefecture sets.
|
|
55
|
+
*/
|
|
56
|
+
export declare const JP_FIRST_DIGIT_REGION: Record<string, string>;
|
|
57
|
+
/**
|
|
58
|
+
* The coarse region label for a postal code's first digit, or null if the input is not a Japanese
|
|
59
|
+
* postal code. A weak, approximate prior (see {@link JP_FIRST_DIGIT_REGION}); the full code anchors
|
|
60
|
+
* the address.
|
|
61
|
+
*/
|
|
62
|
+
export declare function firstDigitRegion(postalCode: unknown): string | null;
|
|
63
|
+
//# sourceMappingURL=postal-code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postal-code.d.ts","sourceRoot":"","sources":["../../jp/postal-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAEvC;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAEvD,iGAAiG;AACjG,eAAO,MAAM,sBAAsB,QAAmB,CAAA;AAEtD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAMrE;AAED,4FAA4F;AAC5F,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAElE;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAWxD,CAAA;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAInE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*
|
|
6
|
+
* Japanese postal codes (郵便番号, yūbin-bangō): the branded type, the shape, normalization, and the
|
|
7
|
+
* first-digit → coarse-region prior.
|
|
8
|
+
*
|
|
9
|
+
* This file is the far end of a spectrum whose other end is `us/zipcode.ts`. A US address leans on
|
|
10
|
+
* the street line — a named street plus a house number — and the ZIP is a routing convenience. A
|
|
11
|
+
* Japanese address is the inverse on two counts:
|
|
12
|
+
*
|
|
13
|
+
* - It is written **largest-to-smallest**: prefecture → city/ward → district → block → lot (`東京都 千代田区
|
|
14
|
+
* 千代田 1-1`), the reverse of the US smallest-to-largest line order.
|
|
15
|
+
* - There are **essentially no street names**. Outside a few Kyoto-style exceptions, you do not
|
|
16
|
+
* navigate by named streets; you navigate by nested administrative areas and numbered
|
|
17
|
+
* blocks/lots (丁目 / 番地 / 号 — see `address-unit.ts`).
|
|
18
|
+
*
|
|
19
|
+
* With no street name to anchor on and a reverse field order, the **postal code is the single most
|
|
20
|
+
* reliable geographic anchor** for a Japanese address — it pins the chōme-level area directly,
|
|
21
|
+
* far tighter than a US ZIP pins a US address. So where the US parser treats the postcode as a
|
|
22
|
+
* tie-breaker behind the street, the Japan parser should treat it as the primary key.
|
|
23
|
+
*/
|
|
24
|
+
/** The postal-code shape: `NNN-NNNN`, the hyphen optional on input (`1000001` or `100-0001`). */
|
|
25
|
+
export const JP_POSTAL_CODE_PATTERN = /^\d{3}-?\d{4}$/;
|
|
26
|
+
/**
|
|
27
|
+
* Normalize a postal-code surface form to the canonical hyphenated `NNN-NNNN`: strip a leading 〒
|
|
28
|
+
* mark and any whitespace, then re-insert the hyphen if the input gave the bare seven digits
|
|
29
|
+
* (`〒100-0001` → `100-0001`, `1000001` → `100-0001`). Returns null if the result is not seven
|
|
30
|
+
* digits.
|
|
31
|
+
*/
|
|
32
|
+
export function normalizeJpPostalCode(raw) {
|
|
33
|
+
if (typeof raw !== "string")
|
|
34
|
+
return null;
|
|
35
|
+
// Drop the 〒 mark and all whitespace, then keep only the digits.
|
|
36
|
+
const digits = raw.replace(/〒/g, "").replace(/\s+/g, "").replace(/-/g, "");
|
|
37
|
+
if (!/^\d{7}$/.test(digits))
|
|
38
|
+
return null;
|
|
39
|
+
return `${digits.slice(0, 3)}-${digits.slice(3)}`;
|
|
40
|
+
}
|
|
41
|
+
/** Type-predicate for a Japanese postal code (hyphen optional, `100-0001` or `1000001`). */
|
|
42
|
+
export function isJpPostalCode(input) {
|
|
43
|
+
return typeof input === "string" && JP_POSTAL_CODE_PATTERN.test(input);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* First digit of the postal code → a coarse region label. Japan Post's numbering grows roughly
|
|
47
|
+
* outward from Tokyo (`1xx`) and is **approximate** at this granularity — a single leading digit
|
|
48
|
+
* spans large, irregular areas and the boundaries are postal-routing, not administrative. Use it as
|
|
49
|
+
* a weak prior, never as a hard region assignment; the full code is what actually anchors the
|
|
50
|
+
* address.
|
|
51
|
+
*
|
|
52
|
+
* Approximate — the labels below are illustrative routing regions, not precise prefecture sets.
|
|
53
|
+
*/
|
|
54
|
+
export const JP_FIRST_DIGIT_REGION = {
|
|
55
|
+
"0": "Hokkaido & northern Tōhoku",
|
|
56
|
+
"1": "Tokyo & Kanto",
|
|
57
|
+
"2": "Kanagawa / Shizuoka & central",
|
|
58
|
+
"3": "northern Kanto / Tōhoku",
|
|
59
|
+
"4": "Tōkai / Chūbu",
|
|
60
|
+
"5": "Kinki / Kansai",
|
|
61
|
+
"6": "Kinki / Chūgoku west",
|
|
62
|
+
"7": "Chūgoku / Shikoku",
|
|
63
|
+
"8": "Kyūshū",
|
|
64
|
+
"9": "Tōhoku north / other",
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* The coarse region label for a postal code's first digit, or null if the input is not a Japanese
|
|
68
|
+
* postal code. A weak, approximate prior (see {@link JP_FIRST_DIGIT_REGION}); the full code anchors
|
|
69
|
+
* the address.
|
|
70
|
+
*/
|
|
71
|
+
export function firstDigitRegion(postalCode) {
|
|
72
|
+
const normalized = normalizeJpPostalCode(postalCode);
|
|
73
|
+
if (!normalized)
|
|
74
|
+
return null;
|
|
75
|
+
return JP_FIRST_DIGIT_REGION[normalized[0]] ?? null;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=postal-code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postal-code.js","sourceRoot":"","sources":["../../jp/postal-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAgBH,iGAAiG;AACjG,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAY;IACjD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAA;IACxC,iEAAiE;IACjE,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IAC1E,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAA;IACxC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAgB,CAAA;AAChE,CAAC;AAED,4FAA4F;AAC5F,MAAM,UAAU,cAAc,CAAC,KAAc;IAC5C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,sBAAsB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;AACvE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAA2B;IAC5D,GAAG,EAAE,4BAA4B;IACjC,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,+BAA+B;IACpC,GAAG,EAAE,yBAAyB;IAC9B,GAAG,EAAE,eAAe;IACpB,GAAG,EAAE,gBAAgB;IACrB,GAAG,EAAE,sBAAsB;IAC3B,GAAG,EAAE,mBAAmB;IACxB,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,sBAAsB;CAC3B,CAAA;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,UAAmB;IACnD,MAAM,UAAU,GAAG,qBAAqB,CAAC,UAAU,CAAC,CAAA;IACpD,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAA;IAC5B,OAAO,qBAAqB,CAAC,UAAU,CAAC,CAAC,CAAE,CAAC,IAAI,IAAI,CAAA;AACrD,CAAC"}
|