japanese_address_parser 3.1.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile.lock +4 -4
- data/js/node_modules/.package-lock.json +3 -3
- data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/lib/cacheRegexes.d.ts +9 -2
- data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/main-browser.js +121 -18
- data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/main-es.js +121 -18
- data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/main-node.d.ts +6 -0
- data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/main-node.js +183 -47
- data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/normalize.d.ts +46 -2
- data/js/node_modules/@geolonia/normalize-japanese-addresses/package.json +4 -3
- data/js/node_modules/@geolonia/normalize-japanese-addresses/src/config.ts +1 -0
- data/js/node_modules/@geolonia/normalize-japanese-addresses/src/lib/cacheRegexes.ts +55 -9
- data/js/node_modules/@geolonia/normalize-japanese-addresses/src/lib/kan2num.ts +6 -2
- data/js/node_modules/@geolonia/normalize-japanese-addresses/src/main-node.ts +41 -12
- data/js/node_modules/@geolonia/normalize-japanese-addresses/src/normalize.ts +163 -35
- data/js/package-lock.json +7 -7
- data/js/package.json +1 -1
- data/lib/japanese_address_parser/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53a31a273123299a2e48aea1fa82e3bd4d0d33d7e8f1a694ef39a1926004576a
|
4
|
+
data.tar.gz: 21198c935bf0dc0892f5ff395403ef4aaa08d03f60d576e7cfbeaa556ae9ebed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 742a64618c177ef65bf6dcb0677993ba531f734efda24b81dc2a5f0839aef47ae42c57e829b5c9a3e9b984dbb4b1960303a1b05c8d88dcfc516b473948f8219e
|
7
|
+
data.tar.gz: dab2e5dedbeda742af992a5b9574697523f9816c9765741c8f6b9eec6b06723c98247f9248d20a61aeebdcaf541d09d734c2a30a12ca22a47b5b2f1ab2da5694
|
data/CHANGELOG.md
CHANGED
@@ -17,6 +17,16 @@ Change Log の形式は [Keep a Changelog](http://keepachangelog.com/) に従い
|
|
17
17
|
|
18
18
|
### Security
|
19
19
|
|
20
|
+
## [3.1.1] - 2023-09-07
|
21
|
+
|
22
|
+
### Changed
|
23
|
+
|
24
|
+
- [#95](https://github.com/yamat47/japanese_address_parser/pull/95) Bump @geolonia/normalize-japanese-addresses from 2.8.0 to 2.9.2 in /js([@yamat47](https://github.com/yamat47))
|
25
|
+
|
26
|
+
### Security
|
27
|
+
|
28
|
+
- [#94](https://github.com/yamat47/japanese_address_parser/pull/94) Bump activesupport from 7.0.4.3 to 7.0.7.1([@yamat47](https://github.com/yamat47))
|
29
|
+
|
20
30
|
## [3.1.0] - 2023-07-24
|
21
31
|
|
22
32
|
### Changed
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
japanese_address_parser (3.1.
|
4
|
+
japanese_address_parser (3.1.1)
|
5
5
|
schmooze
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (7.0.
|
10
|
+
activesupport (7.0.7.1)
|
11
11
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
12
|
i18n (>= 1.6, < 2)
|
13
13
|
minitest (>= 5.1)
|
@@ -18,14 +18,14 @@ GEM
|
|
18
18
|
factory_bot (6.2.1)
|
19
19
|
activesupport (>= 5.0.0)
|
20
20
|
ffi (1.15.5)
|
21
|
-
i18n (1.
|
21
|
+
i18n (1.14.1)
|
22
22
|
concurrent-ruby (~> 1.0)
|
23
23
|
json (2.6.2)
|
24
24
|
language_server-protocol (3.17.0.1)
|
25
25
|
listen (3.7.1)
|
26
26
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
27
27
|
rb-inotify (~> 0.9, >= 0.9.10)
|
28
|
-
minitest (5.
|
28
|
+
minitest (5.19.0)
|
29
29
|
parallel (1.22.1)
|
30
30
|
parser (3.1.2.1)
|
31
31
|
ast (~> 2.4.1)
|
@@ -9,9 +9,9 @@
|
|
9
9
|
"integrity": "sha512-xzSsIHhyyjqNpW8qSh5bFMu3FJvyJGBbNZ/t8clPHkigjUdZ7Ck8wkzCkcwlVd00RkoHwGDLnvXx5W0WiGK0TQ=="
|
10
10
|
},
|
11
11
|
"node_modules/@geolonia/normalize-japanese-addresses": {
|
12
|
-
"version": "2.
|
13
|
-
"resolved": "https://registry.npmjs.org/@geolonia/normalize-japanese-addresses/-/normalize-japanese-addresses-2.
|
14
|
-
"integrity": "sha512-
|
12
|
+
"version": "2.9.2",
|
13
|
+
"resolved": "https://registry.npmjs.org/@geolonia/normalize-japanese-addresses/-/normalize-japanese-addresses-2.9.2.tgz",
|
14
|
+
"integrity": "sha512-sbeV/seJ/ue6pn2sLo+Ccunl6eB3yNhrUIzNpT2IiR9Fw6fW5f1lLdApODqhTmz++xr1dyPwZOzTXCGEaXejDA==",
|
15
15
|
"dependencies": {
|
16
16
|
"@geolonia/japanese-numeral": "^0.1.16",
|
17
17
|
"isomorphic-unfetch": "^3.1.0",
|
@@ -1,4 +1,4 @@
|
|
1
|
-
declare type PrefectureList = {
|
1
|
+
export declare type PrefectureList = {
|
2
2
|
[key: string]: string[];
|
3
3
|
};
|
4
4
|
interface SingleTown {
|
@@ -8,7 +8,13 @@ interface SingleTown {
|
|
8
8
|
lat: string;
|
9
9
|
lng: string;
|
10
10
|
}
|
11
|
-
declare type TownList = SingleTown[];
|
11
|
+
export declare type TownList = SingleTown[];
|
12
|
+
interface SingleAddr {
|
13
|
+
addr: string;
|
14
|
+
lat: string | null;
|
15
|
+
lng: string | null;
|
16
|
+
}
|
17
|
+
export declare type AddrList = SingleAddr[];
|
12
18
|
interface GaikuListItem {
|
13
19
|
gaiku: string;
|
14
20
|
lat: string;
|
@@ -28,6 +34,7 @@ export declare const getCityRegexPatterns: (pref: string, cities: string[]) => [
|
|
28
34
|
export declare const getTowns: (pref: string, city: string) => Promise<TownList>;
|
29
35
|
export declare const getGaikuList: (pref: string, city: string, town: string) => Promise<GaikuListItem[]>;
|
30
36
|
export declare const getResidentials: (pref: string, city: string, town: string) => Promise<ResidentialList>;
|
37
|
+
export declare const getAddrs: (pref: string, city: string, town: string) => Promise<AddrList>;
|
31
38
|
export declare const getTownRegexPatterns: (pref: string, city: string) => Promise<[SingleTown, string][]>;
|
32
39
|
export declare const getSameNamedPrefectureCityRegexPatterns: (prefs: string[], prefList: PrefectureList) => [string, string][];
|
33
40
|
export {};
|
@@ -348,6 +348,7 @@
|
|
348
348
|
|
349
349
|
var gh_pages_endpoint = 'https://geolonia.github.io/japanese-addresses/api/ja';
|
350
350
|
var currentConfig = {
|
351
|
+
interfaceVersion: 1,
|
351
352
|
japaneseAddressesApi: gh_pages_endpoint,
|
352
353
|
townCacheSize: 1000,
|
353
354
|
};
|
@@ -355,8 +356,13 @@
|
|
355
356
|
var kan2num = function (string) {
|
356
357
|
var kanjiNumbers = dist.findKanjiNumbers(string);
|
357
358
|
for (var i = 0; i < kanjiNumbers.length; i++) {
|
358
|
-
|
359
|
-
|
359
|
+
try {
|
360
|
+
// @ts-ignore
|
361
|
+
string = string.replace(kanjiNumbers[i], dist.kanji2number(kanjiNumbers[i]));
|
362
|
+
}
|
363
|
+
catch (error) {
|
364
|
+
// ignore
|
365
|
+
}
|
360
366
|
}
|
361
367
|
return string;
|
362
368
|
};
|
@@ -1228,6 +1234,7 @@
|
|
1228
1234
|
var cachedTowns = {};
|
1229
1235
|
var cachedGaikuListItem = {};
|
1230
1236
|
var cachedResidentials = {};
|
1237
|
+
var cachedAddrs = {}; // TODO: use LRU
|
1231
1238
|
var cachedSameNamedPrefectureCityRegexPatterns = undefined;
|
1232
1239
|
var getPrefectures = function () { return __awaiter(void 0, void 0, void 0, function () {
|
1233
1240
|
var prefsResp, data;
|
@@ -1237,7 +1244,7 @@
|
|
1237
1244
|
if (typeof cachedPrefectures !== 'undefined') {
|
1238
1245
|
return [2 /*return*/, cachedPrefectures];
|
1239
1246
|
}
|
1240
|
-
return [4 /*yield*/, __internals.fetch('.json')]; // ja.json
|
1247
|
+
return [4 /*yield*/, __internals.fetch('.json', { level: 1 })]; // ja.json
|
1241
1248
|
case 1:
|
1242
1249
|
prefsResp = _a.sent() // ja.json
|
1243
1250
|
;
|
@@ -1291,7 +1298,7 @@
|
|
1291
1298
|
if (typeof cachedTown !== 'undefined') {
|
1292
1299
|
return [2 /*return*/, cachedTown];
|
1293
1300
|
}
|
1294
|
-
return [4 /*yield*/, __internals.fetch(['', encodeURI(pref), encodeURI(city) + '.json'].join('/'))];
|
1301
|
+
return [4 /*yield*/, __internals.fetch(['', encodeURI(pref), encodeURI(city) + '.json'].join('/'), { level: 3, pref: pref, city: city })];
|
1295
1302
|
case 1:
|
1296
1303
|
townsResp = _a.sent();
|
1297
1304
|
return [4 /*yield*/, townsResp.json()];
|
@@ -1306,7 +1313,10 @@
|
|
1306
1313
|
return __generator(this, function (_b) {
|
1307
1314
|
switch (_b.label) {
|
1308
1315
|
case 0:
|
1309
|
-
|
1316
|
+
if (currentConfig.interfaceVersion > 1) {
|
1317
|
+
throw new Error("Invalid config.interfaceVersion: " + currentConfig.interfaceVersion + "'}. Please set config.interfaceVersion to 1.");
|
1318
|
+
}
|
1319
|
+
cacheKey = pref + "-" + city + "-" + town + "-v" + currentConfig.interfaceVersion;
|
1310
1320
|
cache = cachedGaikuListItem[cacheKey];
|
1311
1321
|
if (typeof cache !== 'undefined') {
|
1312
1322
|
return [2 /*return*/, cache];
|
@@ -1334,7 +1344,10 @@
|
|
1334
1344
|
return __generator(this, function (_b) {
|
1335
1345
|
switch (_b.label) {
|
1336
1346
|
case 0:
|
1337
|
-
|
1347
|
+
if (currentConfig.interfaceVersion > 1) {
|
1348
|
+
throw new Error("Invalid config.interfaceVersion: " + currentConfig.interfaceVersion + "'}. Please set config.interfaceVersion to 1.");
|
1349
|
+
}
|
1350
|
+
cacheKey = pref + "-" + city + "-" + town + "-v" + currentConfig.interfaceVersion;
|
1338
1351
|
cache = cachedResidentials[cacheKey];
|
1339
1352
|
if (typeof cache !== 'undefined') {
|
1340
1353
|
return [2 /*return*/, cache];
|
@@ -1368,6 +1381,39 @@
|
|
1368
1381
|
}
|
1369
1382
|
});
|
1370
1383
|
}); };
|
1384
|
+
var getAddrs = function (pref, city, town) { return __awaiter(void 0, void 0, void 0, function () {
|
1385
|
+
var cacheKey, cache, addrsResp, addrs;
|
1386
|
+
return __generator(this, function (_b) {
|
1387
|
+
switch (_b.label) {
|
1388
|
+
case 0:
|
1389
|
+
if (currentConfig.interfaceVersion < 2) {
|
1390
|
+
throw new Error("Invalid config.interfaceVersion: " + currentConfig.interfaceVersion + "'}. Please set config.interfaceVersion to 2 or higher");
|
1391
|
+
}
|
1392
|
+
cacheKey = pref + "-" + city + "-" + town + "-v" + currentConfig.interfaceVersion;
|
1393
|
+
cache = cachedAddrs[cacheKey];
|
1394
|
+
if (typeof cache !== 'undefined') {
|
1395
|
+
return [2 /*return*/, cache];
|
1396
|
+
}
|
1397
|
+
return [4 /*yield*/, __internals.fetch(['', encodeURI(pref), encodeURI(city), encodeURI(town) + '.json'].join('/'), { level: 8, pref: pref, city: city, town: town })];
|
1398
|
+
case 1:
|
1399
|
+
addrsResp = _b.sent();
|
1400
|
+
_b.label = 2;
|
1401
|
+
case 2:
|
1402
|
+
_b.trys.push([2, 4, , 5]);
|
1403
|
+
return [4 /*yield*/, addrsResp.json()];
|
1404
|
+
case 3:
|
1405
|
+
addrs = (_b.sent());
|
1406
|
+
return [3 /*break*/, 5];
|
1407
|
+
case 4:
|
1408
|
+
_b.sent();
|
1409
|
+
addrs = [];
|
1410
|
+
return [3 /*break*/, 5];
|
1411
|
+
case 5:
|
1412
|
+
addrs.sort(function (res1, res2) { return res1.addr.length - res2.addr.length; });
|
1413
|
+
return [2 /*return*/, (cachedAddrs[cacheKey] = addrs)];
|
1414
|
+
}
|
1415
|
+
});
|
1416
|
+
}); };
|
1371
1417
|
// 十六町 のように漢数字と町が連結しているか
|
1372
1418
|
var isKanjiNumberFollewedByCho = function (targetTownName) {
|
1373
1419
|
var xCho = targetTownName.match(/.町/g);
|
@@ -1599,10 +1645,32 @@
|
|
1599
1645
|
}
|
1600
1646
|
});
|
1601
1647
|
}); };
|
1648
|
+
var normalizeAddrPart = function (addr, pref, city, town) { return __awaiter(void 0, void 0, void 0, function () {
|
1649
|
+
var addrListItem, addrItem, other;
|
1650
|
+
return __generator(this, function (_a) {
|
1651
|
+
switch (_a.label) {
|
1652
|
+
case 0: return [4 /*yield*/, getAddrs(pref, city, town)
|
1653
|
+
// 住居表示住所、および地番住所が見つからなかった
|
1654
|
+
];
|
1655
|
+
case 1:
|
1656
|
+
addrListItem = _a.sent();
|
1657
|
+
// 住居表示住所、および地番住所が見つからなかった
|
1658
|
+
if (addrListItem.length === 0) {
|
1659
|
+
return [2 /*return*/, null];
|
1660
|
+
}
|
1661
|
+
addrItem = addrListItem.find(function (item) { return addr.startsWith(item.addr); });
|
1662
|
+
if (addrItem) {
|
1663
|
+
other = addr.replace(addrItem.addr, '').trim();
|
1664
|
+
return [2 /*return*/, { addr: addrItem.addr, other: other, lat: addrItem.lat, lng: addrItem.lng }];
|
1665
|
+
}
|
1666
|
+
return [2 /*return*/, null];
|
1667
|
+
}
|
1668
|
+
});
|
1669
|
+
}); };
|
1602
1670
|
var normalize$1 = function (address, _option) {
|
1603
1671
|
if (_option === void 0) { _option = defaultOption; }
|
1604
1672
|
return __awaiter(void 0, void 0, void 0, function () {
|
1605
|
-
var option, addr, pref, city, town, lat, lng, level, normalized, prefectures, prefs, prefPatterns, sameNamedPrefectureCityRegexPatterns, i, _a, prefectureCity, reg, match, i, _b, _pref, pattern, match, matched, _pref, cities, cityPatterns, i, _c, _city, pattern, match, i, normalized_1, cities, cityPatterns, i, _d, _city, pattern, match, result;
|
1673
|
+
var option, addr, pref, city, town, lat, lng, level, normalized, prefectures, prefs, prefPatterns, sameNamedPrefectureCityRegexPatterns, i, _a, prefectureCity, reg, match, i, _b, _pref, pattern, match, matched, _pref, cities, cityPatterns, i, _c, _city, pattern, match, i, normalized_1, cities, cityPatterns, i, _d, _city, pattern, match, normalizedAddrPart, other, result, result;
|
1606
1674
|
return __generator(this, function (_e) {
|
1607
1675
|
switch (_e.label) {
|
1608
1676
|
case 0:
|
@@ -1762,7 +1830,7 @@
|
|
1762
1830
|
// `-1` のようなケース
|
1763
1831
|
return kan2num(s);
|
1764
1832
|
})
|
1765
|
-
.replace(/-[^0-9]
|
1833
|
+
.replace(/-[^0-9]([0-9〇一二三四五六七八九十百千]+)/, function (s) {
|
1766
1834
|
// `-あ1` のようなケース
|
1767
1835
|
return kan2num(zen2han(s));
|
1768
1836
|
})
|
@@ -1775,12 +1843,52 @@
|
|
1775
1843
|
_e.label = 8;
|
1776
1844
|
case 8:
|
1777
1845
|
addr = patchAddr(pref, city, town, addr);
|
1778
|
-
if (
|
1779
|
-
|
1846
|
+
if (pref)
|
1847
|
+
level = level + 1;
|
1848
|
+
if (city)
|
1849
|
+
level = level + 1;
|
1850
|
+
if (town)
|
1851
|
+
level = level + 1;
|
1852
|
+
if (option.level <= 3 || level < 3) {
|
1853
|
+
return [2 /*return*/, { pref: pref, city: city, town: town, addr: addr, level: level, lat: lat, lng: lng }];
|
1854
|
+
}
|
1855
|
+
if (!(currentConfig.interfaceVersion === 2)) return [3 /*break*/, 10];
|
1856
|
+
return [4 /*yield*/, normalizeAddrPart(addr, pref, city, town)];
|
1780
1857
|
case 9:
|
1781
|
-
|
1782
|
-
|
1858
|
+
normalizedAddrPart = _e.sent();
|
1859
|
+
other = undefined;
|
1860
|
+
if (normalizedAddrPart) {
|
1861
|
+
addr = normalizedAddrPart.addr;
|
1862
|
+
if (normalizedAddrPart.other) {
|
1863
|
+
other = normalizedAddrPart.other;
|
1864
|
+
}
|
1865
|
+
if (normalizedAddrPart.lat !== null)
|
1866
|
+
lat = parseFloat(normalizedAddrPart.lat);
|
1867
|
+
if (normalizedAddrPart.lng !== null)
|
1868
|
+
lng = parseFloat(normalizedAddrPart.lng);
|
1869
|
+
level = 8;
|
1870
|
+
}
|
1871
|
+
result = {
|
1872
|
+
pref: pref,
|
1873
|
+
city: city,
|
1874
|
+
town: town,
|
1875
|
+
addr: addr,
|
1876
|
+
level: level,
|
1877
|
+
lat: lat,
|
1878
|
+
lng: lng,
|
1879
|
+
};
|
1880
|
+
if (other) {
|
1881
|
+
result.other = other;
|
1882
|
+
}
|
1883
|
+
return [2 /*return*/, result];
|
1783
1884
|
case 10:
|
1885
|
+
if (!(currentConfig.interfaceVersion === 1)) return [3 /*break*/, 13];
|
1886
|
+
if (!(option.level > 3 && normalized && town)) return [3 /*break*/, 12];
|
1887
|
+
return [4 /*yield*/, normalizeResidentialPart(addr, pref, city, town)];
|
1888
|
+
case 11:
|
1889
|
+
normalized = _e.sent();
|
1890
|
+
_e.label = 12;
|
1891
|
+
case 12:
|
1784
1892
|
if (normalized) {
|
1785
1893
|
lat = parseFloat(normalized.lat);
|
1786
1894
|
lng = parseFloat(normalized.lng);
|
@@ -1789,12 +1897,6 @@
|
|
1789
1897
|
lat = null;
|
1790
1898
|
lng = null;
|
1791
1899
|
}
|
1792
|
-
if (pref)
|
1793
|
-
level = level + 1;
|
1794
|
-
if (city)
|
1795
|
-
level = level + 1;
|
1796
|
-
if (town)
|
1797
|
-
level = level + 1;
|
1798
1900
|
result = {
|
1799
1901
|
pref: pref,
|
1800
1902
|
city: city,
|
@@ -1814,6 +1916,7 @@
|
|
1814
1916
|
result.level = 8;
|
1815
1917
|
}
|
1816
1918
|
return [2 /*return*/, result];
|
1919
|
+
case 13: throw new Error('invalid interfaceVersion');
|
1817
1920
|
}
|
1818
1921
|
});
|
1819
1922
|
});
|
@@ -342,6 +342,7 @@ exports.findKanjiNumbers = findKanjiNumbers;
|
|
342
342
|
|
343
343
|
var gh_pages_endpoint = 'https://geolonia.github.io/japanese-addresses/api/ja';
|
344
344
|
var currentConfig = {
|
345
|
+
interfaceVersion: 1,
|
345
346
|
japaneseAddressesApi: gh_pages_endpoint,
|
346
347
|
townCacheSize: 1000,
|
347
348
|
};
|
@@ -349,8 +350,13 @@ var currentConfig = {
|
|
349
350
|
var kan2num = function (string) {
|
350
351
|
var kanjiNumbers = dist.findKanjiNumbers(string);
|
351
352
|
for (var i = 0; i < kanjiNumbers.length; i++) {
|
352
|
-
|
353
|
-
|
353
|
+
try {
|
354
|
+
// @ts-ignore
|
355
|
+
string = string.replace(kanjiNumbers[i], dist.kanji2number(kanjiNumbers[i]));
|
356
|
+
}
|
357
|
+
catch (error) {
|
358
|
+
// ignore
|
359
|
+
}
|
354
360
|
}
|
355
361
|
return string;
|
356
362
|
};
|
@@ -1222,6 +1228,7 @@ var cachedPrefectures = undefined;
|
|
1222
1228
|
var cachedTowns = {};
|
1223
1229
|
var cachedGaikuListItem = {};
|
1224
1230
|
var cachedResidentials = {};
|
1231
|
+
var cachedAddrs = {}; // TODO: use LRU
|
1225
1232
|
var cachedSameNamedPrefectureCityRegexPatterns = undefined;
|
1226
1233
|
var getPrefectures = function () { return __awaiter(void 0, void 0, void 0, function () {
|
1227
1234
|
var prefsResp, data;
|
@@ -1231,7 +1238,7 @@ var getPrefectures = function () { return __awaiter(void 0, void 0, void 0, func
|
|
1231
1238
|
if (typeof cachedPrefectures !== 'undefined') {
|
1232
1239
|
return [2 /*return*/, cachedPrefectures];
|
1233
1240
|
}
|
1234
|
-
return [4 /*yield*/, __internals.fetch('.json')]; // ja.json
|
1241
|
+
return [4 /*yield*/, __internals.fetch('.json', { level: 1 })]; // ja.json
|
1235
1242
|
case 1:
|
1236
1243
|
prefsResp = _a.sent() // ja.json
|
1237
1244
|
;
|
@@ -1285,7 +1292,7 @@ var getTowns = function (pref, city) { return __awaiter(void 0, void 0, void 0,
|
|
1285
1292
|
if (typeof cachedTown !== 'undefined') {
|
1286
1293
|
return [2 /*return*/, cachedTown];
|
1287
1294
|
}
|
1288
|
-
return [4 /*yield*/, __internals.fetch(['', encodeURI(pref), encodeURI(city) + '.json'].join('/'))];
|
1295
|
+
return [4 /*yield*/, __internals.fetch(['', encodeURI(pref), encodeURI(city) + '.json'].join('/'), { level: 3, pref: pref, city: city })];
|
1289
1296
|
case 1:
|
1290
1297
|
townsResp = _a.sent();
|
1291
1298
|
return [4 /*yield*/, townsResp.json()];
|
@@ -1300,7 +1307,10 @@ var getGaikuList = function (pref, city, town) { return __awaiter(void 0, void 0
|
|
1300
1307
|
return __generator(this, function (_b) {
|
1301
1308
|
switch (_b.label) {
|
1302
1309
|
case 0:
|
1303
|
-
|
1310
|
+
if (currentConfig.interfaceVersion > 1) {
|
1311
|
+
throw new Error("Invalid config.interfaceVersion: " + currentConfig.interfaceVersion + "'}. Please set config.interfaceVersion to 1.");
|
1312
|
+
}
|
1313
|
+
cacheKey = pref + "-" + city + "-" + town + "-v" + currentConfig.interfaceVersion;
|
1304
1314
|
cache = cachedGaikuListItem[cacheKey];
|
1305
1315
|
if (typeof cache !== 'undefined') {
|
1306
1316
|
return [2 /*return*/, cache];
|
@@ -1328,7 +1338,10 @@ var getResidentials = function (pref, city, town) { return __awaiter(void 0, voi
|
|
1328
1338
|
return __generator(this, function (_b) {
|
1329
1339
|
switch (_b.label) {
|
1330
1340
|
case 0:
|
1331
|
-
|
1341
|
+
if (currentConfig.interfaceVersion > 1) {
|
1342
|
+
throw new Error("Invalid config.interfaceVersion: " + currentConfig.interfaceVersion + "'}. Please set config.interfaceVersion to 1.");
|
1343
|
+
}
|
1344
|
+
cacheKey = pref + "-" + city + "-" + town + "-v" + currentConfig.interfaceVersion;
|
1332
1345
|
cache = cachedResidentials[cacheKey];
|
1333
1346
|
if (typeof cache !== 'undefined') {
|
1334
1347
|
return [2 /*return*/, cache];
|
@@ -1362,6 +1375,39 @@ var getResidentials = function (pref, city, town) { return __awaiter(void 0, voi
|
|
1362
1375
|
}
|
1363
1376
|
});
|
1364
1377
|
}); };
|
1378
|
+
var getAddrs = function (pref, city, town) { return __awaiter(void 0, void 0, void 0, function () {
|
1379
|
+
var cacheKey, cache, addrsResp, addrs;
|
1380
|
+
return __generator(this, function (_b) {
|
1381
|
+
switch (_b.label) {
|
1382
|
+
case 0:
|
1383
|
+
if (currentConfig.interfaceVersion < 2) {
|
1384
|
+
throw new Error("Invalid config.interfaceVersion: " + currentConfig.interfaceVersion + "'}. Please set config.interfaceVersion to 2 or higher");
|
1385
|
+
}
|
1386
|
+
cacheKey = pref + "-" + city + "-" + town + "-v" + currentConfig.interfaceVersion;
|
1387
|
+
cache = cachedAddrs[cacheKey];
|
1388
|
+
if (typeof cache !== 'undefined') {
|
1389
|
+
return [2 /*return*/, cache];
|
1390
|
+
}
|
1391
|
+
return [4 /*yield*/, __internals.fetch(['', encodeURI(pref), encodeURI(city), encodeURI(town) + '.json'].join('/'), { level: 8, pref: pref, city: city, town: town })];
|
1392
|
+
case 1:
|
1393
|
+
addrsResp = _b.sent();
|
1394
|
+
_b.label = 2;
|
1395
|
+
case 2:
|
1396
|
+
_b.trys.push([2, 4, , 5]);
|
1397
|
+
return [4 /*yield*/, addrsResp.json()];
|
1398
|
+
case 3:
|
1399
|
+
addrs = (_b.sent());
|
1400
|
+
return [3 /*break*/, 5];
|
1401
|
+
case 4:
|
1402
|
+
_b.sent();
|
1403
|
+
addrs = [];
|
1404
|
+
return [3 /*break*/, 5];
|
1405
|
+
case 5:
|
1406
|
+
addrs.sort(function (res1, res2) { return res1.addr.length - res2.addr.length; });
|
1407
|
+
return [2 /*return*/, (cachedAddrs[cacheKey] = addrs)];
|
1408
|
+
}
|
1409
|
+
});
|
1410
|
+
}); };
|
1365
1411
|
// 十六町 のように漢数字と町が連結しているか
|
1366
1412
|
var isKanjiNumberFollewedByCho = function (targetTownName) {
|
1367
1413
|
var xCho = targetTownName.match(/.町/g);
|
@@ -1593,10 +1639,32 @@ var normalizeResidentialPart = function (addr, pref, city, town) { return __awai
|
|
1593
1639
|
}
|
1594
1640
|
});
|
1595
1641
|
}); };
|
1642
|
+
var normalizeAddrPart = function (addr, pref, city, town) { return __awaiter(void 0, void 0, void 0, function () {
|
1643
|
+
var addrListItem, addrItem, other;
|
1644
|
+
return __generator(this, function (_a) {
|
1645
|
+
switch (_a.label) {
|
1646
|
+
case 0: return [4 /*yield*/, getAddrs(pref, city, town)
|
1647
|
+
// 住居表示住所、および地番住所が見つからなかった
|
1648
|
+
];
|
1649
|
+
case 1:
|
1650
|
+
addrListItem = _a.sent();
|
1651
|
+
// 住居表示住所、および地番住所が見つからなかった
|
1652
|
+
if (addrListItem.length === 0) {
|
1653
|
+
return [2 /*return*/, null];
|
1654
|
+
}
|
1655
|
+
addrItem = addrListItem.find(function (item) { return addr.startsWith(item.addr); });
|
1656
|
+
if (addrItem) {
|
1657
|
+
other = addr.replace(addrItem.addr, '').trim();
|
1658
|
+
return [2 /*return*/, { addr: addrItem.addr, other: other, lat: addrItem.lat, lng: addrItem.lng }];
|
1659
|
+
}
|
1660
|
+
return [2 /*return*/, null];
|
1661
|
+
}
|
1662
|
+
});
|
1663
|
+
}); };
|
1596
1664
|
var normalize$1 = function (address, _option) {
|
1597
1665
|
if (_option === void 0) { _option = defaultOption; }
|
1598
1666
|
return __awaiter(void 0, void 0, void 0, function () {
|
1599
|
-
var option, addr, pref, city, town, lat, lng, level, normalized, prefectures, prefs, prefPatterns, sameNamedPrefectureCityRegexPatterns, i, _a, prefectureCity, reg, match, i, _b, _pref, pattern, match, matched, _pref, cities, cityPatterns, i, _c, _city, pattern, match, i, normalized_1, cities, cityPatterns, i, _d, _city, pattern, match, result;
|
1667
|
+
var option, addr, pref, city, town, lat, lng, level, normalized, prefectures, prefs, prefPatterns, sameNamedPrefectureCityRegexPatterns, i, _a, prefectureCity, reg, match, i, _b, _pref, pattern, match, matched, _pref, cities, cityPatterns, i, _c, _city, pattern, match, i, normalized_1, cities, cityPatterns, i, _d, _city, pattern, match, normalizedAddrPart, other, result, result;
|
1600
1668
|
return __generator(this, function (_e) {
|
1601
1669
|
switch (_e.label) {
|
1602
1670
|
case 0:
|
@@ -1756,7 +1824,7 @@ var normalize$1 = function (address, _option) {
|
|
1756
1824
|
// `-1` のようなケース
|
1757
1825
|
return kan2num(s);
|
1758
1826
|
})
|
1759
|
-
.replace(/-[^0-9]
|
1827
|
+
.replace(/-[^0-9]([0-9〇一二三四五六七八九十百千]+)/, function (s) {
|
1760
1828
|
// `-あ1` のようなケース
|
1761
1829
|
return kan2num(zen2han(s));
|
1762
1830
|
})
|
@@ -1769,12 +1837,52 @@ var normalize$1 = function (address, _option) {
|
|
1769
1837
|
_e.label = 8;
|
1770
1838
|
case 8:
|
1771
1839
|
addr = patchAddr(pref, city, town, addr);
|
1772
|
-
if (
|
1773
|
-
|
1840
|
+
if (pref)
|
1841
|
+
level = level + 1;
|
1842
|
+
if (city)
|
1843
|
+
level = level + 1;
|
1844
|
+
if (town)
|
1845
|
+
level = level + 1;
|
1846
|
+
if (option.level <= 3 || level < 3) {
|
1847
|
+
return [2 /*return*/, { pref: pref, city: city, town: town, addr: addr, level: level, lat: lat, lng: lng }];
|
1848
|
+
}
|
1849
|
+
if (!(currentConfig.interfaceVersion === 2)) return [3 /*break*/, 10];
|
1850
|
+
return [4 /*yield*/, normalizeAddrPart(addr, pref, city, town)];
|
1774
1851
|
case 9:
|
1775
|
-
|
1776
|
-
|
1852
|
+
normalizedAddrPart = _e.sent();
|
1853
|
+
other = undefined;
|
1854
|
+
if (normalizedAddrPart) {
|
1855
|
+
addr = normalizedAddrPart.addr;
|
1856
|
+
if (normalizedAddrPart.other) {
|
1857
|
+
other = normalizedAddrPart.other;
|
1858
|
+
}
|
1859
|
+
if (normalizedAddrPart.lat !== null)
|
1860
|
+
lat = parseFloat(normalizedAddrPart.lat);
|
1861
|
+
if (normalizedAddrPart.lng !== null)
|
1862
|
+
lng = parseFloat(normalizedAddrPart.lng);
|
1863
|
+
level = 8;
|
1864
|
+
}
|
1865
|
+
result = {
|
1866
|
+
pref: pref,
|
1867
|
+
city: city,
|
1868
|
+
town: town,
|
1869
|
+
addr: addr,
|
1870
|
+
level: level,
|
1871
|
+
lat: lat,
|
1872
|
+
lng: lng,
|
1873
|
+
};
|
1874
|
+
if (other) {
|
1875
|
+
result.other = other;
|
1876
|
+
}
|
1877
|
+
return [2 /*return*/, result];
|
1777
1878
|
case 10:
|
1879
|
+
if (!(currentConfig.interfaceVersion === 1)) return [3 /*break*/, 13];
|
1880
|
+
if (!(option.level > 3 && normalized && town)) return [3 /*break*/, 12];
|
1881
|
+
return [4 /*yield*/, normalizeResidentialPart(addr, pref, city, town)];
|
1882
|
+
case 11:
|
1883
|
+
normalized = _e.sent();
|
1884
|
+
_e.label = 12;
|
1885
|
+
case 12:
|
1778
1886
|
if (normalized) {
|
1779
1887
|
lat = parseFloat(normalized.lat);
|
1780
1888
|
lng = parseFloat(normalized.lng);
|
@@ -1783,12 +1891,6 @@ var normalize$1 = function (address, _option) {
|
|
1783
1891
|
lat = null;
|
1784
1892
|
lng = null;
|
1785
1893
|
}
|
1786
|
-
if (pref)
|
1787
|
-
level = level + 1;
|
1788
|
-
if (city)
|
1789
|
-
level = level + 1;
|
1790
|
-
if (town)
|
1791
|
-
level = level + 1;
|
1792
1894
|
result = {
|
1793
1895
|
pref: pref,
|
1794
1896
|
city: city,
|
@@ -1808,6 +1910,7 @@ var normalize$1 = function (address, _option) {
|
|
1808
1910
|
result.level = 8;
|
1809
1911
|
}
|
1810
1912
|
return [2 /*return*/, result];
|
1913
|
+
case 13: throw new Error('invalid interfaceVersion');
|
1811
1914
|
}
|
1812
1915
|
});
|
1813
1916
|
});
|
@@ -1,3 +1,9 @@
|
|
1
1
|
import * as Normalize from './normalize';
|
2
|
+
export declare const requestHandlers: {
|
3
|
+
file: (fileURL: URL) => {
|
4
|
+
json: () => Promise<any>;
|
5
|
+
};
|
6
|
+
http: (fileURL: URL) => Promise<Response>;
|
7
|
+
};
|
2
8
|
export declare const config: Normalize.Config;
|
3
9
|
export declare const normalize: Normalize.Normalizer;
|