japanese_address_parser 3.1.0 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c6eb9e4ea89bdffa891da4f3854646b82b78e4d9e94965fe537227a1f0705361
4
- data.tar.gz: 7bd4611b889b08db8673fdf0f0d12aa80c5f3eb9eb74e34017e3d51923f14b3b
3
+ metadata.gz: 8e7eba0bfa985b9d552b921c17067cd1d395be525f75cf764387541365e98123
4
+ data.tar.gz: f46311345d534ef8ed62c8e6d82c134b7771a3e5af8ff7933cfcf627429651bc
5
5
  SHA512:
6
- metadata.gz: f63cdb14a5a9bd9de00ce62908f94cfb749043aa5f16e5c8bef464f5900708f9c123e02fb2118b02b99ca916e2fcf901435d13af1a467e9fb93ea216aad1634e
7
- data.tar.gz: c6b74305c0445243169db577bd48150ca88f04ff8b4855af588924d7fc9fa0d63cc570da9661db7828002c383d21b94c45fac186c48ebc04d9b15c351e475530
6
+ metadata.gz: f06728834e1b7ce93824f928f5a4bb5fc3e56e2dfcbbc6f5b3b69b071587526b0a196fb48a3493e103ff815f427b12a41003d5485e3e0e0deaa7a348de6a9280
7
+ data.tar.gz: e66fdb4fd59a480f01758aee66e1cb13ccc483191b19882a996b9a36eca295c25d913e4ee11fa5f7d8eda559c38f8176be168d8bcdfe99f519c3d168ab081ccd
data/CHANGELOG.md CHANGED
@@ -5,6 +5,7 @@ Change Log の形式は [Keep a Changelog](http://keepachangelog.com/) に従い
5
5
  またバージョンの付け方は [Semantic Versioning](https://semver.org/) に従います。
6
6
 
7
7
  ## [Unreleased]
8
+
8
9
  ### Added
9
10
 
10
11
  ### Changed
@@ -17,6 +18,26 @@ Change Log の形式は [Keep a Changelog](http://keepachangelog.com/) に従い
17
18
 
18
19
  ### Security
19
20
 
21
+ ## [3.1.2] - 2023-09-23
22
+
23
+ ### Changed
24
+
25
+ - [#97](https://github.com/yamat47/japanese_address_parser/pull/97) parser gem のバージョンを最新の(3.2.2.3)にアップデートする([@takatea](https://github.com/takatea))
26
+
27
+ ### Fixed
28
+
29
+ - [#99](https://github.com/yamat47/japanese_address_parser/pull/99) 最新のRuby(head)でCIを実行できるようにする
30
+
31
+ ## [3.1.1] - 2023-09-07
32
+
33
+ ### Changed
34
+
35
+ - [#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))
36
+
37
+ ### Security
38
+
39
+ - [#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))
40
+
20
41
  ## [3.1.0] - 2023-07-24
21
42
 
22
43
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,13 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- japanese_address_parser (3.1.0)
4
+ japanese_address_parser (3.1.2)
5
5
  schmooze
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (7.0.4.3)
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,17 +18,19 @@ GEM
18
18
  factory_bot (6.2.1)
19
19
  activesupport (>= 5.0.0)
20
20
  ffi (1.15.5)
21
- i18n (1.12.0)
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.18.0)
28
+ minitest (5.19.0)
29
29
  parallel (1.22.1)
30
- parser (3.1.2.1)
30
+ parser (3.2.2.3)
31
31
  ast (~> 2.4.1)
32
+ racc
33
+ racc (1.7.1)
32
34
  rainbow (3.1.1)
33
35
  rake (13.0.6)
34
36
  rb-fsevent (0.11.2)
@@ -9,9 +9,9 @@
9
9
  "integrity": "sha512-xzSsIHhyyjqNpW8qSh5bFMu3FJvyJGBbNZ/t8clPHkigjUdZ7Ck8wkzCkcwlVd00RkoHwGDLnvXx5W0WiGK0TQ=="
10
10
  },
11
11
  "node_modules/@geolonia/normalize-japanese-addresses": {
12
- "version": "2.8.0",
13
- "resolved": "https://registry.npmjs.org/@geolonia/normalize-japanese-addresses/-/normalize-japanese-addresses-2.8.0.tgz",
14
- "integrity": "sha512-BNKTl+38nq+ZKABa9nmwixLyDTXDPYDWSG3DluTjvhog3LEVWcTOHy0taIWXpumlvoz67ingq2qxdjtvW8ktzQ==",
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
- // @ts-ignore
359
- string = string.replace(kanjiNumbers[i], dist.kanji2number(kanjiNumbers[i]));
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
- cacheKey = pref + "-" + city + "-" + town;
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
- cacheKey = pref + "-" + city + "-" + town;
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]+([0-9〇一二三四五六七八九十百千]+)/, function (s) {
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 (!(option.level > 3 && normalized && town)) return [3 /*break*/, 10];
1779
- return [4 /*yield*/, normalizeResidentialPart(addr, pref, city, town)];
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
- normalized = _e.sent();
1782
- _e.label = 10;
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
- // @ts-ignore
353
- string = string.replace(kanjiNumbers[i], dist.kanji2number(kanjiNumbers[i]));
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
- cacheKey = pref + "-" + city + "-" + town;
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
- cacheKey = pref + "-" + city + "-" + town;
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]+([0-9〇一二三四五六七八九十百千]+)/, function (s) {
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 (!(option.level > 3 && normalized && town)) return [3 /*break*/, 10];
1773
- return [4 /*yield*/, normalizeResidentialPart(addr, pref, city, town)];
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
- normalized = _e.sent();
1776
- _e.label = 10;
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;