japanese_address_parser 3.0.4 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +17 -0
  3. data/Gemfile.lock +5 -5
  4. data/js/node_modules/.package-lock.json +86 -1
  5. data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/main-browser.js +20 -7
  6. data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/main-es.d.ts +3 -0
  7. data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/main-es.js +1819 -0
  8. data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/main-node.js +21 -8
  9. data/js/node_modules/@geolonia/normalize-japanese-addresses/dist/normalize.d.ts +1 -1
  10. data/js/node_modules/@geolonia/normalize-japanese-addresses/package.json +7 -4
  11. data/js/node_modules/@geolonia/normalize-japanese-addresses/rollup.config.ts +9 -0
  12. data/js/node_modules/@geolonia/normalize-japanese-addresses/src/lib/cacheRegexes.ts +16 -2
  13. data/js/node_modules/@geolonia/normalize-japanese-addresses/src/lib/dict.ts +3 -2
  14. data/js/node_modules/@geolonia/normalize-japanese-addresses/src/main-es.ts +4 -0
  15. data/js/node_modules/@geolonia/normalize-japanese-addresses/src/main-node.ts +1 -1
  16. data/js/node_modules/@geolonia/normalize-japanese-addresses/src/normalize.ts +2 -2
  17. data/js/package-lock.json +7 -7
  18. data/js/package.json +1 -1
  19. data/lib/japanese_address_parser/data/03-03206.csv +1 -0
  20. data/lib/japanese_address_parser/data/04-04421.csv +8 -8
  21. data/lib/japanese_address_parser/data/05-05203.csv +5 -0
  22. data/lib/japanese_address_parser/data/08-08222.csv +4 -0
  23. data/lib/japanese_address_parser/data/11-11442.csv +2 -0
  24. data/lib/japanese_address_parser/data/13-13225.csv +3 -0
  25. data/lib/japanese_address_parser/data/14-14134.csv +3 -0
  26. data/lib/japanese_address_parser/data/15-15104.csv +1 -1
  27. data/lib/japanese_address_parser/data/15-15222.csv +1 -1
  28. data/lib/japanese_address_parser/data/15-15225.csv +1 -1
  29. data/lib/japanese_address_parser/data/18-18202.csv +1 -1
  30. data/lib/japanese_address_parser/data/22-22102.csv +6 -0
  31. data/lib/japanese_address_parser/data/23-23202.csv +1 -0
  32. data/lib/japanese_address_parser/data/23-23207.csv +5 -0
  33. data/lib/japanese_address_parser/data/23-23213.csv +1 -0
  34. data/lib/japanese_address_parser/data/23-23236.csv +1 -0
  35. data/lib/japanese_address_parser/data/25-25206.csv +4 -0
  36. data/lib/japanese_address_parser/data/27-27212.csv +4 -0
  37. data/lib/japanese_address_parser/data/28-28108.csv +1 -0
  38. data/lib/japanese_address_parser/data/28-28204.csv +1 -1
  39. data/lib/japanese_address_parser/data/28-28226.csv +1 -0
  40. data/lib/japanese_address_parser/data/29-29201.csv +1 -1
  41. data/lib/japanese_address_parser/data/34-34207.csv +3 -0
  42. data/lib/japanese_address_parser/data/35-35215.csv +3 -0
  43. data/lib/japanese_address_parser/data/38-38204.csv +17 -0
  44. data/lib/japanese_address_parser/data/40-40131.csv +1 -0
  45. data/lib/japanese_address_parser/data/40-40342.csv +4 -0
  46. data/lib/japanese_address_parser/data/44-44201.csv +27 -0
  47. data/lib/japanese_address_parser/data/46-46201.csv +4 -0
  48. data/lib/japanese_address_parser/data/47-47205.csv +4 -0
  49. data/lib/japanese_address_parser/version.rb +1 -1
  50. metadata +6 -3
@@ -0,0 +1,1819 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+
16
+ var __assign = function() {
17
+ __assign = Object.assign || function __assign(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
21
+ }
22
+ return t;
23
+ };
24
+ return __assign.apply(this, arguments);
25
+ };
26
+
27
+ function __awaiter(thisArg, _arguments, P, generator) {
28
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
+ return new (P || (P = Promise))(function (resolve, reject) {
30
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
34
+ });
35
+ }
36
+
37
+ function __generator(thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ }
64
+
65
+ function getAugmentedNamespace(n) {
66
+ if (n.__esModule) return n;
67
+ var a = Object.defineProperty({}, '__esModule', {value: true});
68
+ Object.keys(n).forEach(function (k) {
69
+ var d = Object.getOwnPropertyDescriptor(n, k);
70
+ Object.defineProperty(a, k, d.get ? d : {
71
+ enumerable: true,
72
+ get: function () {
73
+ return n[k];
74
+ }
75
+ });
76
+ });
77
+ return a;
78
+ }
79
+
80
+ function createCommonjsModule(fn) {
81
+ var module = { exports: {} };
82
+ return fn(module, module.exports), module.exports;
83
+ }
84
+
85
+ const oldJapaneseNumerics = {
86
+ 零: '〇',
87
+ 壱: '一',
88
+ 壹: '一',
89
+ 弐: '二',
90
+ 弍: '二',
91
+ 貳: '二',
92
+ 貮: '二',
93
+ 参: '三',
94
+ 參: '三',
95
+ 肆: '四',
96
+ 伍: '五',
97
+ 陸: '六',
98
+ 漆: '七',
99
+ 捌: '八',
100
+ 玖: '九',
101
+ 拾: '十',
102
+ 廿: '二十',
103
+ 陌: '百',
104
+ 佰: '百',
105
+ 阡: '千',
106
+ 仟: '千',
107
+ 萬: '万',
108
+ };
109
+ var _default$1 = oldJapaneseNumerics;
110
+
111
+ var oldJapaneseNumerics_1 = /*#__PURE__*/Object.defineProperty({
112
+ default: _default$1
113
+ }, '__esModule', {value: true});
114
+
115
+ const japaneseNumerics = {
116
+ 〇: 0,
117
+ 一: 1,
118
+ 二: 2,
119
+ 三: 3,
120
+ 四: 4,
121
+ 五: 5,
122
+ 六: 6,
123
+ 七: 7,
124
+ 八: 8,
125
+ 九: 9,
126
+ '0': 0,
127
+ '1': 1,
128
+ '2': 2,
129
+ '3': 3,
130
+ '4': 4,
131
+ '5': 5,
132
+ '6': 6,
133
+ '7': 7,
134
+ '8': 8,
135
+ '9': 9,
136
+ };
137
+ var _default = japaneseNumerics;
138
+
139
+ var japaneseNumerics_1 = /*#__PURE__*/Object.defineProperty({
140
+ default: _default
141
+ }, '__esModule', {value: true});
142
+
143
+ var utils = createCommonjsModule(function (module, exports) {
144
+ Object.defineProperty(exports, "__esModule", { value: true });
145
+ exports.zen2han = exports.n2kan = exports.kan2n = exports.splitLargeNumber = exports.normalize = exports.smallNumbers = exports.largeNumbers = void 0;
146
+
147
+
148
+ exports.largeNumbers = { '兆': 1000000000000, '億': 100000000, '万': 10000 };
149
+ exports.smallNumbers = { '千': 1000, '百': 100, '十': 10 };
150
+ function normalize(japanese) {
151
+ for (const key in oldJapaneseNumerics_1.default) {
152
+ const reg = new RegExp(key, 'g');
153
+ japanese = japanese.replace(reg, oldJapaneseNumerics_1.default[key]);
154
+ }
155
+ return japanese;
156
+ }
157
+ exports.normalize = normalize;
158
+ /**
159
+ * 漢数字を兆、億、万単位に分割する
160
+ */
161
+ function splitLargeNumber(japanese) {
162
+ let kanji = japanese;
163
+ const numbers = {};
164
+ for (const key in exports.largeNumbers) {
165
+ const reg = new RegExp(`(.+)${key}`);
166
+ const match = kanji.match(reg);
167
+ if (match) {
168
+ numbers[key] = kan2n(match[1]);
169
+ kanji = kanji.replace(match[0], '');
170
+ }
171
+ else {
172
+ numbers[key] = 0;
173
+ }
174
+ }
175
+ if (kanji) {
176
+ numbers['千'] = kan2n(kanji);
177
+ }
178
+ else {
179
+ numbers['千'] = 0;
180
+ }
181
+ return numbers;
182
+ }
183
+ exports.splitLargeNumber = splitLargeNumber;
184
+ /**
185
+ * 千単位以下の漢数字を数字に変換する(例: 三千 => 3000)
186
+ *
187
+ * @param japanese
188
+ */
189
+ function kan2n(japanese) {
190
+ if (japanese.match(/^[0-9]+$/)) {
191
+ return Number(japanese);
192
+ }
193
+ let kanji = zen2han(japanese);
194
+ let number = 0;
195
+ for (const key in exports.smallNumbers) {
196
+ const reg = new RegExp(`(.*)${key}`);
197
+ const match = kanji.match(reg);
198
+ if (match) {
199
+ let n = 1;
200
+ if (match[1]) {
201
+ if (match[1].match(/^[0-9]+$/)) {
202
+ n = Number(match[1]);
203
+ }
204
+ else {
205
+ n = japaneseNumerics_1.default[match[1]];
206
+ }
207
+ }
208
+ number = number + (n * exports.smallNumbers[key]);
209
+ kanji = kanji.replace(match[0], '');
210
+ }
211
+ }
212
+ if (kanji) {
213
+ if (kanji.match(/^[0-9]+$/)) {
214
+ number = number + Number(kanji);
215
+ }
216
+ else {
217
+ for (let index = 0; index < kanji.length; index++) {
218
+ const char = kanji[index];
219
+ const digit = kanji.length - index - 1;
220
+ number = number + japaneseNumerics_1.default[char] * (10 ** digit);
221
+ }
222
+ }
223
+ }
224
+ return number;
225
+ }
226
+ exports.kan2n = kan2n;
227
+ /**
228
+ * Converts number less than 10000 to kanji.
229
+ *
230
+ * @param num
231
+ */
232
+ function n2kan(num) {
233
+ const kanjiNumbers = Object.keys(japaneseNumerics_1.default);
234
+ let number = num;
235
+ let kanji = '';
236
+ for (const key in exports.smallNumbers) {
237
+ const n = Math.floor(number / exports.smallNumbers[key]);
238
+ if (n) {
239
+ number = number - (n * exports.smallNumbers[key]);
240
+ if (1 === n) {
241
+ kanji = `${kanji}${key}`;
242
+ }
243
+ else {
244
+ kanji = `${kanji}${kanjiNumbers[n]}${key}`;
245
+ }
246
+ }
247
+ }
248
+ if (number) {
249
+ kanji = `${kanji}${kanjiNumbers[number]}`;
250
+ }
251
+ return kanji;
252
+ }
253
+ exports.n2kan = n2kan;
254
+ /**
255
+ * Converts double-width number to number as string.
256
+ *
257
+ * @param num
258
+ */
259
+ function zen2han(str) {
260
+ return str.replace(/[0-9]/g, (s) => {
261
+ return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
262
+ });
263
+ }
264
+ exports.zen2han = zen2han;
265
+ });
266
+
267
+ var dist = createCommonjsModule(function (module, exports) {
268
+ Object.defineProperty(exports, "__esModule", { value: true });
269
+ exports.findKanjiNumbers = exports.number2kanji = exports.kanji2number = void 0;
270
+
271
+
272
+ function kanji2number(japanese) {
273
+ japanese = utils.normalize(japanese);
274
+ if (japanese.match('〇') || japanese.match(/^[〇一二三四五六七八九]+$/)) {
275
+ for (const key in japaneseNumerics_1.default) {
276
+ const reg = new RegExp(key, 'g');
277
+ japanese = japanese.replace(reg, japaneseNumerics_1.default[key].toString());
278
+ }
279
+ return Number(japanese);
280
+ }
281
+ else {
282
+ let number = 0;
283
+ const numbers = utils.splitLargeNumber(japanese);
284
+ // 万以上の数字を数値に変換
285
+ for (const key in utils.largeNumbers) {
286
+ if (numbers[key]) {
287
+ const n = utils.largeNumbers[key] * numbers[key];
288
+ number = number + n;
289
+ }
290
+ }
291
+ if (!Number.isInteger(number) || !Number.isInteger(numbers['千'])) {
292
+ throw new TypeError('The attribute of kanji2number() must be a Japanese numeral as integer.');
293
+ }
294
+ // 千以下の数字を足す
295
+ return number + numbers['千'];
296
+ }
297
+ }
298
+ exports.kanji2number = kanji2number;
299
+ function number2kanji(num) {
300
+ if (!num.toString().match(/^[0-9]+$/)) {
301
+ throw new TypeError('The attribute of number2kanji() must be integer.');
302
+ }
303
+ Object.keys(japaneseNumerics_1.default);
304
+ let number = num;
305
+ let kanji = '';
306
+ // 万以上の数字を漢字に変換
307
+ for (const key in utils.largeNumbers) {
308
+ const n = Math.floor(number / utils.largeNumbers[key]);
309
+ if (n) {
310
+ number = number - (n * utils.largeNumbers[key]);
311
+ kanji = `${kanji}${utils.n2kan(n)}${key}`;
312
+ }
313
+ }
314
+ if (number) {
315
+ kanji = `${kanji}${utils.n2kan(number)}`;
316
+ }
317
+ return kanji;
318
+ }
319
+ exports.number2kanji = number2kanji;
320
+ function findKanjiNumbers(text) {
321
+ const num = '([0-90-9]*)|([〇一二三四五六七八九壱壹弐弍貳貮参參肆伍陸漆捌玖]*)';
322
+ const basePattern = `((${num})(千|阡|仟))?((${num})(百|陌|佰))?((${num})(十|拾))?(${num})?`;
323
+ const pattern = `((${basePattern}兆)?(${basePattern}億)?(${basePattern}(万|萬))?${basePattern})`;
324
+ const regex = new RegExp(pattern, 'g');
325
+ const match = text.match(regex);
326
+ if (match) {
327
+ return match.filter((item) => {
328
+ if ((!item.match(/^[0-90-9]+$/)) && (item.length && '兆' !== item && '億' !== item && '万' !== item && '萬' !== item)) {
329
+ return true;
330
+ }
331
+ else {
332
+ return false;
333
+ }
334
+ });
335
+ }
336
+ else {
337
+ return [];
338
+ }
339
+ }
340
+ exports.findKanjiNumbers = findKanjiNumbers;
341
+ });
342
+
343
+ var gh_pages_endpoint = 'https://geolonia.github.io/japanese-addresses/api/ja';
344
+ var currentConfig = {
345
+ japaneseAddressesApi: gh_pages_endpoint,
346
+ townCacheSize: 1000,
347
+ };
348
+
349
+ var kan2num = function (string) {
350
+ var kanjiNumbers = dist.findKanjiNumbers(string);
351
+ for (var i = 0; i < kanjiNumbers.length; i++) {
352
+ // @ts-ignore
353
+ string = string.replace(kanjiNumbers[i], dist.kanji2number(kanjiNumbers[i]));
354
+ }
355
+ return string;
356
+ };
357
+
358
+ var zen2han = function (str) {
359
+ return str.replace(/[A-Za-z0-9]/g, function (s) {
360
+ return String.fromCharCode(s.charCodeAt(0) - 0xfee0);
361
+ });
362
+ };
363
+
364
+ var addrPatches = [
365
+ {
366
+ pref: '香川県',
367
+ city: '仲多度郡まんのう町',
368
+ town: '勝浦',
369
+ pattern: '^字?家6',
370
+ result: '家六',
371
+ },
372
+ {
373
+ pref: '愛知県',
374
+ city: 'あま市',
375
+ town: '西今宿',
376
+ pattern: '^字?梶村1',
377
+ result: '梶村一',
378
+ },
379
+ {
380
+ pref: '香川県',
381
+ city: '丸亀市',
382
+ town: '原田町',
383
+ pattern: '^字?東三分1',
384
+ result: '東三分一',
385
+ },
386
+ ];
387
+ var patchAddr = function (pref, city, town, addr) {
388
+ var _addr = addr;
389
+ for (var i = 0; i < addrPatches.length; i++) {
390
+ var patch = addrPatches[i];
391
+ if (patch.pref === pref && patch.city === city && patch.town === town) {
392
+ _addr = _addr.replace(new RegExp(patch.pattern), patch.result);
393
+ }
394
+ }
395
+ return _addr;
396
+ };
397
+
398
+ // JIS 第2水準 => 第1水準 及び 旧字体 => 新字体
399
+ var JIS_OLD_KANJI = '亞,圍,壹,榮,驛,應,櫻,假,會,懷,覺,樂,陷,歡,氣,戲,據,挾,區,徑,溪,輕,藝,儉,圈,權,嚴,恆,國,齋,雜,蠶,殘,兒,實,釋,從,縱,敍,燒,條,剩,壤,釀,眞,盡,醉,髓,聲,竊,淺,錢,禪,爭,插,騷,屬,對,滯,擇,單,斷,癡,鑄,敕,鐵,傳,黨,鬪,屆,腦,廢,發,蠻,拂,邊,瓣,寶,沒,滿,藥,餘,樣,亂,兩,禮,靈,爐,灣,惡,醫,飮,營,圓,歐,奧,價,繪,擴,學,罐,勸,觀,歸,犧,擧,狹,驅,莖,經,繼,缺,劍,檢,顯,廣,鑛,碎,劑,參,慘,絲,辭,舍,壽,澁,肅,將,證,乘,疊,孃,觸,寢,圖,穗,樞,齊,攝,戰,潛,雙,莊,裝,藏,續,體,臺,澤,膽,彈,蟲,廳,鎭,點,燈,盜,獨,貳,霸,賣,髮,祕,佛,變,辯,豐,飜,默,與,譽,謠,覽,獵,勵,齡,勞,壓,爲,隱,衞,鹽,毆,穩,畫,壞,殼,嶽,卷,關,顏,僞,舊,峽,曉,勳,惠,螢,鷄,縣,險,獻,驗,效,號,濟,册,棧,贊,齒,濕,寫,收,獸,處,稱,奬,淨,繩,讓,囑,愼,粹,隨,數,靜,專,踐,纖,壯,搜,總,臟,墮,帶,瀧,擔,團,遲,晝,聽,遞,轉,當,稻,讀,惱,拜,麥,拔,濱,竝,辨,舖,襃,萬,譯,豫,搖,來,龍,壘,隸,戀,樓,鰺,鶯,蠣,攪,竈,灌,諫,頸,礦,蘂,靱,賤,壺,礪,檮,濤,邇,蠅,檜,儘,藪,籠,彌,麩'.split(/,/);
400
+ var JIS_NEW_KANJI = '亜,囲,壱,栄,駅,応,桜,仮,会,懐,覚,楽,陥,歓,気,戯,拠,挟,区,径,渓,軽,芸,倹,圏,権,厳,恒,国,斎,雑,蚕,残,児,実,釈,従,縦,叙,焼,条,剰,壌,醸,真,尽,酔,髄,声,窃,浅,銭,禅,争,挿,騒,属,対,滞,択,単,断,痴,鋳,勅,鉄,伝,党,闘,届,脳,廃,発,蛮,払,辺,弁,宝,没,満,薬,余,様,乱,両,礼,霊,炉,湾,悪,医,飲,営,円,欧,奥,価,絵,拡,学,缶,勧,観,帰,犠,挙,狭,駆,茎,経,継,欠,剣,検,顕,広,鉱,砕,剤,参,惨,糸,辞,舎,寿,渋,粛,将,証,乗,畳,嬢,触,寝,図,穂,枢,斉,摂,戦,潜,双,荘,装,蔵,続,体,台,沢,胆,弾,虫,庁,鎮,点,灯,盗,独,弐,覇,売,髪,秘,仏,変,弁,豊,翻,黙,与,誉,謡,覧,猟,励,齢,労,圧,為,隠,衛,塩,殴,穏,画,壊,殻,岳,巻,関,顔,偽,旧,峡,暁,勲,恵,蛍,鶏,県,険,献,験,効,号,済,冊,桟,賛,歯,湿,写,収,獣,処,称,奨,浄,縄,譲,嘱,慎,粋,随,数,静,専,践,繊,壮,捜,総,臓,堕,帯,滝,担,団,遅,昼,聴,逓,転,当,稲,読,悩,拝,麦,抜,浜,並,弁,舗,褒,万,訳,予,揺,来,竜,塁,隷,恋,楼,鯵,鴬,蛎,撹,竃,潅,諌,頚,砿,蕊,靭,賎,壷,砺,梼,涛,迩,蝿,桧,侭,薮,篭,弥,麸'.split(/,/);
401
+ var JIS_KANJI_REGEX_PATTERNS = JIS_OLD_KANJI.map(function (old, i) {
402
+ var pattern = old + "|" + JIS_NEW_KANJI[i];
403
+ return [pattern, old, JIS_NEW_KANJI[i]];
404
+ });
405
+ var jisKanji = function (str) {
406
+ var _str = str;
407
+ for (var i = 0; i < JIS_KANJI_REGEX_PATTERNS.length; i++) {
408
+ var _a = JIS_KANJI_REGEX_PATTERNS[i], pattern = _a[0], oldKanji = _a[1], newKanji = _a[2];
409
+ _str = _str.replace(new RegExp(pattern, 'g'), "(" + oldKanji + "|" + newKanji + ")");
410
+ }
411
+ return _str;
412
+ };
413
+ var toRegexPattern = function (string) {
414
+ var _str = string;
415
+ // 以下なるべく文字数が多いものほど上にすること
416
+ _str = _str
417
+ .replace(/三栄町|四谷三栄町/g, '(三栄町|四谷三栄町)')
418
+ .replace(/鬮野川|くじ野川|くじの川/g, '(鬮野川|くじ野川|くじの川)')
419
+ .replace(/柿碕町|柿さき町/g, '(柿碕町|柿さき町)')
420
+ .replace(/通り|とおり/g, '(通り|とおり)')
421
+ .replace(/埠頭|ふ頭/g, '(埠頭|ふ頭)')
422
+ .replace(/番町|番丁/g, '(番町|番丁)')
423
+ .replace(/大冝|大宜/g, '(大冝|大宜)')
424
+ .replace(/穝|さい/g, '(穝|さい)')
425
+ .replace(/杁|えぶり/g, '(杁|えぶり)')
426
+ .replace(/薭|稗|ひえ|ヒエ/g, '(薭|稗|ひえ|ヒエ)')
427
+ .replace(/[之ノの]/g, '[之ノの]')
428
+ .replace(/[ヶケが]/g, '[ヶケが]')
429
+ .replace(/[ヵカか力]/g, '[ヵカか力]')
430
+ .replace(/[ッツっつ]/g, '[ッツっつ]')
431
+ .replace(/[ニ二]/g, '[ニ二]')
432
+ .replace(/[ハ八]/g, '[ハ八]')
433
+ .replace(/塚|塚/g, '(塚|塚)')
434
+ .replace(/釜|竈/g, '(釜|竈)')
435
+ .replace(/條|条/g, '(條|条)')
436
+ .replace(/狛|拍/g, '(狛|拍)')
437
+ .replace(/藪|薮/g, '(藪|薮)')
438
+ .replace(/渕|淵/g, '(渕|淵)')
439
+ .replace(/エ|ヱ|え/g, '(エ|ヱ|え)')
440
+ .replace(/曾|曽/g, '(曾|曽)')
441
+ .replace(/舟|船/g, '(舟|船)')
442
+ .replace(/莵|菟/g, '(莵|菟)')
443
+ .replace(/市|巿/g, '(市|巿)');
444
+ _str = jisKanji(_str);
445
+ return _str;
446
+ };
447
+
448
+ var iterator = function (Yallist) {
449
+ Yallist.prototype[Symbol.iterator] = function* () {
450
+ for (let walker = this.head; walker; walker = walker.next) {
451
+ yield walker.value;
452
+ }
453
+ };
454
+ };
455
+
456
+ var yallist = Yallist;
457
+
458
+ Yallist.Node = Node;
459
+ Yallist.create = Yallist;
460
+
461
+ function Yallist (list) {
462
+ var self = this;
463
+ if (!(self instanceof Yallist)) {
464
+ self = new Yallist();
465
+ }
466
+
467
+ self.tail = null;
468
+ self.head = null;
469
+ self.length = 0;
470
+
471
+ if (list && typeof list.forEach === 'function') {
472
+ list.forEach(function (item) {
473
+ self.push(item);
474
+ });
475
+ } else if (arguments.length > 0) {
476
+ for (var i = 0, l = arguments.length; i < l; i++) {
477
+ self.push(arguments[i]);
478
+ }
479
+ }
480
+
481
+ return self
482
+ }
483
+
484
+ Yallist.prototype.removeNode = function (node) {
485
+ if (node.list !== this) {
486
+ throw new Error('removing node which does not belong to this list')
487
+ }
488
+
489
+ var next = node.next;
490
+ var prev = node.prev;
491
+
492
+ if (next) {
493
+ next.prev = prev;
494
+ }
495
+
496
+ if (prev) {
497
+ prev.next = next;
498
+ }
499
+
500
+ if (node === this.head) {
501
+ this.head = next;
502
+ }
503
+ if (node === this.tail) {
504
+ this.tail = prev;
505
+ }
506
+
507
+ node.list.length--;
508
+ node.next = null;
509
+ node.prev = null;
510
+ node.list = null;
511
+
512
+ return next
513
+ };
514
+
515
+ Yallist.prototype.unshiftNode = function (node) {
516
+ if (node === this.head) {
517
+ return
518
+ }
519
+
520
+ if (node.list) {
521
+ node.list.removeNode(node);
522
+ }
523
+
524
+ var head = this.head;
525
+ node.list = this;
526
+ node.next = head;
527
+ if (head) {
528
+ head.prev = node;
529
+ }
530
+
531
+ this.head = node;
532
+ if (!this.tail) {
533
+ this.tail = node;
534
+ }
535
+ this.length++;
536
+ };
537
+
538
+ Yallist.prototype.pushNode = function (node) {
539
+ if (node === this.tail) {
540
+ return
541
+ }
542
+
543
+ if (node.list) {
544
+ node.list.removeNode(node);
545
+ }
546
+
547
+ var tail = this.tail;
548
+ node.list = this;
549
+ node.prev = tail;
550
+ if (tail) {
551
+ tail.next = node;
552
+ }
553
+
554
+ this.tail = node;
555
+ if (!this.head) {
556
+ this.head = node;
557
+ }
558
+ this.length++;
559
+ };
560
+
561
+ Yallist.prototype.push = function () {
562
+ for (var i = 0, l = arguments.length; i < l; i++) {
563
+ push(this, arguments[i]);
564
+ }
565
+ return this.length
566
+ };
567
+
568
+ Yallist.prototype.unshift = function () {
569
+ for (var i = 0, l = arguments.length; i < l; i++) {
570
+ unshift(this, arguments[i]);
571
+ }
572
+ return this.length
573
+ };
574
+
575
+ Yallist.prototype.pop = function () {
576
+ if (!this.tail) {
577
+ return undefined
578
+ }
579
+
580
+ var res = this.tail.value;
581
+ this.tail = this.tail.prev;
582
+ if (this.tail) {
583
+ this.tail.next = null;
584
+ } else {
585
+ this.head = null;
586
+ }
587
+ this.length--;
588
+ return res
589
+ };
590
+
591
+ Yallist.prototype.shift = function () {
592
+ if (!this.head) {
593
+ return undefined
594
+ }
595
+
596
+ var res = this.head.value;
597
+ this.head = this.head.next;
598
+ if (this.head) {
599
+ this.head.prev = null;
600
+ } else {
601
+ this.tail = null;
602
+ }
603
+ this.length--;
604
+ return res
605
+ };
606
+
607
+ Yallist.prototype.forEach = function (fn, thisp) {
608
+ thisp = thisp || this;
609
+ for (var walker = this.head, i = 0; walker !== null; i++) {
610
+ fn.call(thisp, walker.value, i, this);
611
+ walker = walker.next;
612
+ }
613
+ };
614
+
615
+ Yallist.prototype.forEachReverse = function (fn, thisp) {
616
+ thisp = thisp || this;
617
+ for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
618
+ fn.call(thisp, walker.value, i, this);
619
+ walker = walker.prev;
620
+ }
621
+ };
622
+
623
+ Yallist.prototype.get = function (n) {
624
+ for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
625
+ // abort out of the list early if we hit a cycle
626
+ walker = walker.next;
627
+ }
628
+ if (i === n && walker !== null) {
629
+ return walker.value
630
+ }
631
+ };
632
+
633
+ Yallist.prototype.getReverse = function (n) {
634
+ for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
635
+ // abort out of the list early if we hit a cycle
636
+ walker = walker.prev;
637
+ }
638
+ if (i === n && walker !== null) {
639
+ return walker.value
640
+ }
641
+ };
642
+
643
+ Yallist.prototype.map = function (fn, thisp) {
644
+ thisp = thisp || this;
645
+ var res = new Yallist();
646
+ for (var walker = this.head; walker !== null;) {
647
+ res.push(fn.call(thisp, walker.value, this));
648
+ walker = walker.next;
649
+ }
650
+ return res
651
+ };
652
+
653
+ Yallist.prototype.mapReverse = function (fn, thisp) {
654
+ thisp = thisp || this;
655
+ var res = new Yallist();
656
+ for (var walker = this.tail; walker !== null;) {
657
+ res.push(fn.call(thisp, walker.value, this));
658
+ walker = walker.prev;
659
+ }
660
+ return res
661
+ };
662
+
663
+ Yallist.prototype.reduce = function (fn, initial) {
664
+ var acc;
665
+ var walker = this.head;
666
+ if (arguments.length > 1) {
667
+ acc = initial;
668
+ } else if (this.head) {
669
+ walker = this.head.next;
670
+ acc = this.head.value;
671
+ } else {
672
+ throw new TypeError('Reduce of empty list with no initial value')
673
+ }
674
+
675
+ for (var i = 0; walker !== null; i++) {
676
+ acc = fn(acc, walker.value, i);
677
+ walker = walker.next;
678
+ }
679
+
680
+ return acc
681
+ };
682
+
683
+ Yallist.prototype.reduceReverse = function (fn, initial) {
684
+ var acc;
685
+ var walker = this.tail;
686
+ if (arguments.length > 1) {
687
+ acc = initial;
688
+ } else if (this.tail) {
689
+ walker = this.tail.prev;
690
+ acc = this.tail.value;
691
+ } else {
692
+ throw new TypeError('Reduce of empty list with no initial value')
693
+ }
694
+
695
+ for (var i = this.length - 1; walker !== null; i--) {
696
+ acc = fn(acc, walker.value, i);
697
+ walker = walker.prev;
698
+ }
699
+
700
+ return acc
701
+ };
702
+
703
+ Yallist.prototype.toArray = function () {
704
+ var arr = new Array(this.length);
705
+ for (var i = 0, walker = this.head; walker !== null; i++) {
706
+ arr[i] = walker.value;
707
+ walker = walker.next;
708
+ }
709
+ return arr
710
+ };
711
+
712
+ Yallist.prototype.toArrayReverse = function () {
713
+ var arr = new Array(this.length);
714
+ for (var i = 0, walker = this.tail; walker !== null; i++) {
715
+ arr[i] = walker.value;
716
+ walker = walker.prev;
717
+ }
718
+ return arr
719
+ };
720
+
721
+ Yallist.prototype.slice = function (from, to) {
722
+ to = to || this.length;
723
+ if (to < 0) {
724
+ to += this.length;
725
+ }
726
+ from = from || 0;
727
+ if (from < 0) {
728
+ from += this.length;
729
+ }
730
+ var ret = new Yallist();
731
+ if (to < from || to < 0) {
732
+ return ret
733
+ }
734
+ if (from < 0) {
735
+ from = 0;
736
+ }
737
+ if (to > this.length) {
738
+ to = this.length;
739
+ }
740
+ for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
741
+ walker = walker.next;
742
+ }
743
+ for (; walker !== null && i < to; i++, walker = walker.next) {
744
+ ret.push(walker.value);
745
+ }
746
+ return ret
747
+ };
748
+
749
+ Yallist.prototype.sliceReverse = function (from, to) {
750
+ to = to || this.length;
751
+ if (to < 0) {
752
+ to += this.length;
753
+ }
754
+ from = from || 0;
755
+ if (from < 0) {
756
+ from += this.length;
757
+ }
758
+ var ret = new Yallist();
759
+ if (to < from || to < 0) {
760
+ return ret
761
+ }
762
+ if (from < 0) {
763
+ from = 0;
764
+ }
765
+ if (to > this.length) {
766
+ to = this.length;
767
+ }
768
+ for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
769
+ walker = walker.prev;
770
+ }
771
+ for (; walker !== null && i > from; i--, walker = walker.prev) {
772
+ ret.push(walker.value);
773
+ }
774
+ return ret
775
+ };
776
+
777
+ Yallist.prototype.splice = function (start, deleteCount, ...nodes) {
778
+ if (start > this.length) {
779
+ start = this.length - 1;
780
+ }
781
+ if (start < 0) {
782
+ start = this.length + start;
783
+ }
784
+
785
+ for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
786
+ walker = walker.next;
787
+ }
788
+
789
+ var ret = [];
790
+ for (var i = 0; walker && i < deleteCount; i++) {
791
+ ret.push(walker.value);
792
+ walker = this.removeNode(walker);
793
+ }
794
+ if (walker === null) {
795
+ walker = this.tail;
796
+ }
797
+
798
+ if (walker !== this.head && walker !== this.tail) {
799
+ walker = walker.prev;
800
+ }
801
+
802
+ for (var i = 0; i < nodes.length; i++) {
803
+ walker = insert(this, walker, nodes[i]);
804
+ }
805
+ return ret;
806
+ };
807
+
808
+ Yallist.prototype.reverse = function () {
809
+ var head = this.head;
810
+ var tail = this.tail;
811
+ for (var walker = head; walker !== null; walker = walker.prev) {
812
+ var p = walker.prev;
813
+ walker.prev = walker.next;
814
+ walker.next = p;
815
+ }
816
+ this.head = tail;
817
+ this.tail = head;
818
+ return this
819
+ };
820
+
821
+ function insert (self, node, value) {
822
+ var inserted = node === self.head ?
823
+ new Node(value, null, node, self) :
824
+ new Node(value, node, node.next, self);
825
+
826
+ if (inserted.next === null) {
827
+ self.tail = inserted;
828
+ }
829
+ if (inserted.prev === null) {
830
+ self.head = inserted;
831
+ }
832
+
833
+ self.length++;
834
+
835
+ return inserted
836
+ }
837
+
838
+ function push (self, item) {
839
+ self.tail = new Node(item, self.tail, null, self);
840
+ if (!self.head) {
841
+ self.head = self.tail;
842
+ }
843
+ self.length++;
844
+ }
845
+
846
+ function unshift (self, item) {
847
+ self.head = new Node(item, null, self.head, self);
848
+ if (!self.tail) {
849
+ self.tail = self.head;
850
+ }
851
+ self.length++;
852
+ }
853
+
854
+ function Node (value, prev, next, list) {
855
+ if (!(this instanceof Node)) {
856
+ return new Node(value, prev, next, list)
857
+ }
858
+
859
+ this.list = list;
860
+ this.value = value;
861
+
862
+ if (prev) {
863
+ prev.next = this;
864
+ this.prev = prev;
865
+ } else {
866
+ this.prev = null;
867
+ }
868
+
869
+ if (next) {
870
+ next.prev = this;
871
+ this.next = next;
872
+ } else {
873
+ this.next = null;
874
+ }
875
+ }
876
+
877
+ try {
878
+ // add if support for Symbol.iterator is present
879
+ iterator(Yallist);
880
+ } catch (er) {}
881
+
882
+ // A linked list to keep track of recently-used-ness
883
+
884
+
885
+ const MAX = Symbol('max');
886
+ const LENGTH = Symbol('length');
887
+ const LENGTH_CALCULATOR = Symbol('lengthCalculator');
888
+ const ALLOW_STALE = Symbol('allowStale');
889
+ const MAX_AGE = Symbol('maxAge');
890
+ const DISPOSE = Symbol('dispose');
891
+ const NO_DISPOSE_ON_SET = Symbol('noDisposeOnSet');
892
+ const LRU_LIST = Symbol('lruList');
893
+ const CACHE = Symbol('cache');
894
+ const UPDATE_AGE_ON_GET = Symbol('updateAgeOnGet');
895
+
896
+ const naiveLength = () => 1;
897
+
898
+ // lruList is a yallist where the head is the youngest
899
+ // item, and the tail is the oldest. the list contains the Hit
900
+ // objects as the entries.
901
+ // Each Hit object has a reference to its Yallist.Node. This
902
+ // never changes.
903
+ //
904
+ // cache is a Map (or PseudoMap) that matches the keys to
905
+ // the Yallist.Node object.
906
+ class LRUCache {
907
+ constructor (options) {
908
+ if (typeof options === 'number')
909
+ options = { max: options };
910
+
911
+ if (!options)
912
+ options = {};
913
+
914
+ if (options.max && (typeof options.max !== 'number' || options.max < 0))
915
+ throw new TypeError('max must be a non-negative number')
916
+ // Kind of weird to have a default max of Infinity, but oh well.
917
+ this[MAX] = options.max || Infinity;
918
+
919
+ const lc = options.length || naiveLength;
920
+ this[LENGTH_CALCULATOR] = (typeof lc !== 'function') ? naiveLength : lc;
921
+ this[ALLOW_STALE] = options.stale || false;
922
+ if (options.maxAge && typeof options.maxAge !== 'number')
923
+ throw new TypeError('maxAge must be a number')
924
+ this[MAX_AGE] = options.maxAge || 0;
925
+ this[DISPOSE] = options.dispose;
926
+ this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false;
927
+ this[UPDATE_AGE_ON_GET] = options.updateAgeOnGet || false;
928
+ this.reset();
929
+ }
930
+
931
+ // resize the cache when the max changes.
932
+ set max (mL) {
933
+ if (typeof mL !== 'number' || mL < 0)
934
+ throw new TypeError('max must be a non-negative number')
935
+
936
+ this[MAX] = mL || Infinity;
937
+ trim(this);
938
+ }
939
+ get max () {
940
+ return this[MAX]
941
+ }
942
+
943
+ set allowStale (allowStale) {
944
+ this[ALLOW_STALE] = !!allowStale;
945
+ }
946
+ get allowStale () {
947
+ return this[ALLOW_STALE]
948
+ }
949
+
950
+ set maxAge (mA) {
951
+ if (typeof mA !== 'number')
952
+ throw new TypeError('maxAge must be a non-negative number')
953
+
954
+ this[MAX_AGE] = mA;
955
+ trim(this);
956
+ }
957
+ get maxAge () {
958
+ return this[MAX_AGE]
959
+ }
960
+
961
+ // resize the cache when the lengthCalculator changes.
962
+ set lengthCalculator (lC) {
963
+ if (typeof lC !== 'function')
964
+ lC = naiveLength;
965
+
966
+ if (lC !== this[LENGTH_CALCULATOR]) {
967
+ this[LENGTH_CALCULATOR] = lC;
968
+ this[LENGTH] = 0;
969
+ this[LRU_LIST].forEach(hit => {
970
+ hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key);
971
+ this[LENGTH] += hit.length;
972
+ });
973
+ }
974
+ trim(this);
975
+ }
976
+ get lengthCalculator () { return this[LENGTH_CALCULATOR] }
977
+
978
+ get length () { return this[LENGTH] }
979
+ get itemCount () { return this[LRU_LIST].length }
980
+
981
+ rforEach (fn, thisp) {
982
+ thisp = thisp || this;
983
+ for (let walker = this[LRU_LIST].tail; walker !== null;) {
984
+ const prev = walker.prev;
985
+ forEachStep(this, fn, walker, thisp);
986
+ walker = prev;
987
+ }
988
+ }
989
+
990
+ forEach (fn, thisp) {
991
+ thisp = thisp || this;
992
+ for (let walker = this[LRU_LIST].head; walker !== null;) {
993
+ const next = walker.next;
994
+ forEachStep(this, fn, walker, thisp);
995
+ walker = next;
996
+ }
997
+ }
998
+
999
+ keys () {
1000
+ return this[LRU_LIST].toArray().map(k => k.key)
1001
+ }
1002
+
1003
+ values () {
1004
+ return this[LRU_LIST].toArray().map(k => k.value)
1005
+ }
1006
+
1007
+ reset () {
1008
+ if (this[DISPOSE] &&
1009
+ this[LRU_LIST] &&
1010
+ this[LRU_LIST].length) {
1011
+ this[LRU_LIST].forEach(hit => this[DISPOSE](hit.key, hit.value));
1012
+ }
1013
+
1014
+ this[CACHE] = new Map(); // hash of items by key
1015
+ this[LRU_LIST] = new yallist(); // list of items in order of use recency
1016
+ this[LENGTH] = 0; // length of items in the list
1017
+ }
1018
+
1019
+ dump () {
1020
+ return this[LRU_LIST].map(hit =>
1021
+ isStale(this, hit) ? false : {
1022
+ k: hit.key,
1023
+ v: hit.value,
1024
+ e: hit.now + (hit.maxAge || 0)
1025
+ }).toArray().filter(h => h)
1026
+ }
1027
+
1028
+ dumpLru () {
1029
+ return this[LRU_LIST]
1030
+ }
1031
+
1032
+ set (key, value, maxAge) {
1033
+ maxAge = maxAge || this[MAX_AGE];
1034
+
1035
+ if (maxAge && typeof maxAge !== 'number')
1036
+ throw new TypeError('maxAge must be a number')
1037
+
1038
+ const now = maxAge ? Date.now() : 0;
1039
+ const len = this[LENGTH_CALCULATOR](value, key);
1040
+
1041
+ if (this[CACHE].has(key)) {
1042
+ if (len > this[MAX]) {
1043
+ del(this, this[CACHE].get(key));
1044
+ return false
1045
+ }
1046
+
1047
+ const node = this[CACHE].get(key);
1048
+ const item = node.value;
1049
+
1050
+ // dispose of the old one before overwriting
1051
+ // split out into 2 ifs for better coverage tracking
1052
+ if (this[DISPOSE]) {
1053
+ if (!this[NO_DISPOSE_ON_SET])
1054
+ this[DISPOSE](key, item.value);
1055
+ }
1056
+
1057
+ item.now = now;
1058
+ item.maxAge = maxAge;
1059
+ item.value = value;
1060
+ this[LENGTH] += len - item.length;
1061
+ item.length = len;
1062
+ this.get(key);
1063
+ trim(this);
1064
+ return true
1065
+ }
1066
+
1067
+ const hit = new Entry(key, value, len, now, maxAge);
1068
+
1069
+ // oversized objects fall out of cache automatically.
1070
+ if (hit.length > this[MAX]) {
1071
+ if (this[DISPOSE])
1072
+ this[DISPOSE](key, value);
1073
+
1074
+ return false
1075
+ }
1076
+
1077
+ this[LENGTH] += hit.length;
1078
+ this[LRU_LIST].unshift(hit);
1079
+ this[CACHE].set(key, this[LRU_LIST].head);
1080
+ trim(this);
1081
+ return true
1082
+ }
1083
+
1084
+ has (key) {
1085
+ if (!this[CACHE].has(key)) return false
1086
+ const hit = this[CACHE].get(key).value;
1087
+ return !isStale(this, hit)
1088
+ }
1089
+
1090
+ get (key) {
1091
+ return get(this, key, true)
1092
+ }
1093
+
1094
+ peek (key) {
1095
+ return get(this, key, false)
1096
+ }
1097
+
1098
+ pop () {
1099
+ const node = this[LRU_LIST].tail;
1100
+ if (!node)
1101
+ return null
1102
+
1103
+ del(this, node);
1104
+ return node.value
1105
+ }
1106
+
1107
+ del (key) {
1108
+ del(this, this[CACHE].get(key));
1109
+ }
1110
+
1111
+ load (arr) {
1112
+ // reset the cache
1113
+ this.reset();
1114
+
1115
+ const now = Date.now();
1116
+ // A previous serialized cache has the most recent items first
1117
+ for (let l = arr.length - 1; l >= 0; l--) {
1118
+ const hit = arr[l];
1119
+ const expiresAt = hit.e || 0;
1120
+ if (expiresAt === 0)
1121
+ // the item was created without expiration in a non aged cache
1122
+ this.set(hit.k, hit.v);
1123
+ else {
1124
+ const maxAge = expiresAt - now;
1125
+ // dont add already expired items
1126
+ if (maxAge > 0) {
1127
+ this.set(hit.k, hit.v, maxAge);
1128
+ }
1129
+ }
1130
+ }
1131
+ }
1132
+
1133
+ prune () {
1134
+ this[CACHE].forEach((value, key) => get(this, key, false));
1135
+ }
1136
+ }
1137
+
1138
+ const get = (self, key, doUse) => {
1139
+ const node = self[CACHE].get(key);
1140
+ if (node) {
1141
+ const hit = node.value;
1142
+ if (isStale(self, hit)) {
1143
+ del(self, node);
1144
+ if (!self[ALLOW_STALE])
1145
+ return undefined
1146
+ } else {
1147
+ if (doUse) {
1148
+ if (self[UPDATE_AGE_ON_GET])
1149
+ node.value.now = Date.now();
1150
+ self[LRU_LIST].unshiftNode(node);
1151
+ }
1152
+ }
1153
+ return hit.value
1154
+ }
1155
+ };
1156
+
1157
+ const isStale = (self, hit) => {
1158
+ if (!hit || (!hit.maxAge && !self[MAX_AGE]))
1159
+ return false
1160
+
1161
+ const diff = Date.now() - hit.now;
1162
+ return hit.maxAge ? diff > hit.maxAge
1163
+ : self[MAX_AGE] && (diff > self[MAX_AGE])
1164
+ };
1165
+
1166
+ const trim = self => {
1167
+ if (self[LENGTH] > self[MAX]) {
1168
+ for (let walker = self[LRU_LIST].tail;
1169
+ self[LENGTH] > self[MAX] && walker !== null;) {
1170
+ // We know that we're about to delete this one, and also
1171
+ // what the next least recently used key will be, so just
1172
+ // go ahead and set it now.
1173
+ const prev = walker.prev;
1174
+ del(self, walker);
1175
+ walker = prev;
1176
+ }
1177
+ }
1178
+ };
1179
+
1180
+ const del = (self, node) => {
1181
+ if (node) {
1182
+ const hit = node.value;
1183
+ if (self[DISPOSE])
1184
+ self[DISPOSE](hit.key, hit.value);
1185
+
1186
+ self[LENGTH] -= hit.length;
1187
+ self[CACHE].delete(hit.key);
1188
+ self[LRU_LIST].removeNode(node);
1189
+ }
1190
+ };
1191
+
1192
+ class Entry {
1193
+ constructor (key, value, length, now, maxAge) {
1194
+ this.key = key;
1195
+ this.value = value;
1196
+ this.length = length;
1197
+ this.now = now;
1198
+ this.maxAge = maxAge || 0;
1199
+ }
1200
+ }
1201
+
1202
+ const forEachStep = (self, fn, node, thisp) => {
1203
+ let hit = node.value;
1204
+ if (isStale(self, hit)) {
1205
+ del(self, node);
1206
+ if (!self[ALLOW_STALE])
1207
+ hit = undefined;
1208
+ }
1209
+ if (hit)
1210
+ fn.call(thisp, hit.value, hit.key, self);
1211
+ };
1212
+
1213
+ var lruCache = LRUCache;
1214
+
1215
+ var cachedTownRegexes = new lruCache({
1216
+ max: currentConfig.townCacheSize,
1217
+ maxAge: 60 * 60 * 24 * 7 * 1000, // 7日間
1218
+ });
1219
+ var cachedPrefecturePatterns = undefined;
1220
+ var cachedCityPatterns = {};
1221
+ var cachedPrefectures = undefined;
1222
+ var cachedTowns = {};
1223
+ var cachedGaikuListItem = {};
1224
+ var cachedResidentials = {};
1225
+ var cachedSameNamedPrefectureCityRegexPatterns = undefined;
1226
+ var getPrefectures = function () { return __awaiter(void 0, void 0, void 0, function () {
1227
+ var prefsResp, data;
1228
+ return __generator(this, function (_a) {
1229
+ switch (_a.label) {
1230
+ case 0:
1231
+ if (typeof cachedPrefectures !== 'undefined') {
1232
+ return [2 /*return*/, cachedPrefectures];
1233
+ }
1234
+ return [4 /*yield*/, __internals.fetch('.json')]; // ja.json
1235
+ case 1:
1236
+ prefsResp = _a.sent() // ja.json
1237
+ ;
1238
+ return [4 /*yield*/, prefsResp.json()];
1239
+ case 2:
1240
+ data = (_a.sent());
1241
+ return [2 /*return*/, cachePrefectures(data)];
1242
+ }
1243
+ });
1244
+ }); };
1245
+ var cachePrefectures = function (data) {
1246
+ return (cachedPrefectures = data);
1247
+ };
1248
+ var getPrefectureRegexPatterns = function (prefs) {
1249
+ if (cachedPrefecturePatterns) {
1250
+ return cachedPrefecturePatterns;
1251
+ }
1252
+ cachedPrefecturePatterns = prefs.map(function (pref) {
1253
+ var _pref = pref.replace(/(都|道|府|県)$/, ''); // `東京` の様に末尾の `都府県` が抜けた住所に対応
1254
+ var pattern = "^" + _pref + "(\u90FD|\u9053|\u5E9C|\u770C)?";
1255
+ return [pref, pattern];
1256
+ });
1257
+ return cachedPrefecturePatterns;
1258
+ };
1259
+ var getCityRegexPatterns = function (pref, cities) {
1260
+ var cachedResult = cachedCityPatterns[pref];
1261
+ if (typeof cachedResult !== 'undefined') {
1262
+ return cachedResult;
1263
+ }
1264
+ // 少ない文字数の地名に対してミスマッチしないように文字の長さ順にソート
1265
+ cities.sort(function (a, b) {
1266
+ return b.length - a.length;
1267
+ });
1268
+ var patterns = cities.map(function (city) {
1269
+ var pattern = "^" + toRegexPattern(city);
1270
+ if (city.match(/(町|村)$/)) {
1271
+ pattern = "^" + toRegexPattern(city).replace(/(.+?)郡/, '($1郡)?'); // 郡が省略されてるかも
1272
+ }
1273
+ return [city, pattern];
1274
+ });
1275
+ cachedCityPatterns[pref] = patterns;
1276
+ return patterns;
1277
+ };
1278
+ var getTowns = function (pref, city) { return __awaiter(void 0, void 0, void 0, function () {
1279
+ var cacheKey, cachedTown, townsResp, towns;
1280
+ return __generator(this, function (_a) {
1281
+ switch (_a.label) {
1282
+ case 0:
1283
+ cacheKey = pref + "-" + city;
1284
+ cachedTown = cachedTowns[cacheKey];
1285
+ if (typeof cachedTown !== 'undefined') {
1286
+ return [2 /*return*/, cachedTown];
1287
+ }
1288
+ return [4 /*yield*/, __internals.fetch(['', encodeURI(pref), encodeURI(city) + '.json'].join('/'))];
1289
+ case 1:
1290
+ townsResp = _a.sent();
1291
+ return [4 /*yield*/, townsResp.json()];
1292
+ case 2:
1293
+ towns = (_a.sent());
1294
+ return [2 /*return*/, (cachedTowns[cacheKey] = towns)];
1295
+ }
1296
+ });
1297
+ }); };
1298
+ var getGaikuList = function (pref, city, town) { return __awaiter(void 0, void 0, void 0, function () {
1299
+ var cacheKey, cache, gaikuResp, gaikuListItem;
1300
+ return __generator(this, function (_b) {
1301
+ switch (_b.label) {
1302
+ case 0:
1303
+ cacheKey = pref + "-" + city + "-" + town;
1304
+ cache = cachedGaikuListItem[cacheKey];
1305
+ if (typeof cache !== 'undefined') {
1306
+ return [2 /*return*/, cache];
1307
+ }
1308
+ return [4 /*yield*/, __internals.fetch(['', encodeURI(pref), encodeURI(city), encodeURI(town + '.json')].join('/'))];
1309
+ case 1:
1310
+ gaikuResp = _b.sent();
1311
+ _b.label = 2;
1312
+ case 2:
1313
+ _b.trys.push([2, 4, , 5]);
1314
+ return [4 /*yield*/, gaikuResp.json()];
1315
+ case 3:
1316
+ gaikuListItem = (_b.sent());
1317
+ return [3 /*break*/, 5];
1318
+ case 4:
1319
+ _b.sent();
1320
+ gaikuListItem = [];
1321
+ return [3 /*break*/, 5];
1322
+ case 5: return [2 /*return*/, (cachedGaikuListItem[cacheKey] = gaikuListItem)];
1323
+ }
1324
+ });
1325
+ }); };
1326
+ var getResidentials = function (pref, city, town) { return __awaiter(void 0, void 0, void 0, function () {
1327
+ var cacheKey, cache, residentialsResp, residentials;
1328
+ return __generator(this, function (_b) {
1329
+ switch (_b.label) {
1330
+ case 0:
1331
+ cacheKey = pref + "-" + city + "-" + town;
1332
+ cache = cachedResidentials[cacheKey];
1333
+ if (typeof cache !== 'undefined') {
1334
+ return [2 /*return*/, cache];
1335
+ }
1336
+ return [4 /*yield*/, __internals.fetch([
1337
+ '',
1338
+ encodeURI(pref),
1339
+ encodeURI(city),
1340
+ encodeURI(town),
1341
+ encodeURI('住居表示.json'),
1342
+ ].join('/'))];
1343
+ case 1:
1344
+ residentialsResp = _b.sent();
1345
+ _b.label = 2;
1346
+ case 2:
1347
+ _b.trys.push([2, 4, , 5]);
1348
+ return [4 /*yield*/, residentialsResp.json()];
1349
+ case 3:
1350
+ residentials = (_b.sent());
1351
+ return [3 /*break*/, 5];
1352
+ case 4:
1353
+ _b.sent();
1354
+ residentials = [];
1355
+ return [3 /*break*/, 5];
1356
+ case 5:
1357
+ residentials.sort(function (res1, res2) {
1358
+ return (res2.gaiku + "-" + res2.jyukyo).length -
1359
+ (res1.gaiku + "-" + res1.jyukyo).length;
1360
+ });
1361
+ return [2 /*return*/, (cachedResidentials[cacheKey] = residentials)];
1362
+ }
1363
+ });
1364
+ }); };
1365
+ // 十六町 のように漢数字と町が連結しているか
1366
+ var isKanjiNumberFollewedByCho = function (targetTownName) {
1367
+ var xCho = targetTownName.match(/.町/g);
1368
+ if (!xCho)
1369
+ return false;
1370
+ var kanjiNumbers = dist.findKanjiNumbers(xCho[0]);
1371
+ return kanjiNumbers.length > 0;
1372
+ };
1373
+ var getTownRegexPatterns = function (pref, city) { return __awaiter(void 0, void 0, void 0, function () {
1374
+ var cachedResult, pre_towns, townSet, towns, isKyoto, _i, pre_towns_1, town, originalTown, townAbbr, patterns, _a, towns_1, town, chomeMatch, chomeNamePart, chomeNum, pattern;
1375
+ return __generator(this, function (_b) {
1376
+ switch (_b.label) {
1377
+ case 0:
1378
+ cachedResult = cachedTownRegexes.get(pref + "-" + city);
1379
+ if (typeof cachedResult !== 'undefined') {
1380
+ return [2 /*return*/, cachedResult];
1381
+ }
1382
+ return [4 /*yield*/, getTowns(pref, city)];
1383
+ case 1:
1384
+ pre_towns = _b.sent();
1385
+ townSet = new Set(pre_towns.map(function (town) { return town.town; }));
1386
+ towns = [];
1387
+ isKyoto = city.match(/^京都市/);
1388
+ // 町丁目に「○○町」が含まれるケースへの対応
1389
+ // 通常は「○○町」のうち「町」の省略を許容し同義語として扱うが、まれに自治体内に「○○町」と「○○」が共存しているケースがある。
1390
+ // この場合は町の省略は許容せず、入力された住所は書き分けられているものとして正規化を行う。
1391
+ // 更に、「愛知県名古屋市瑞穂区十六町1丁目」漢数字を含むケースだと丁目や番地・号の正規化が不可能になる。このようなケースも除外。
1392
+ for (_i = 0, pre_towns_1 = pre_towns; _i < pre_towns_1.length; _i++) {
1393
+ town = pre_towns_1[_i];
1394
+ towns.push(town);
1395
+ originalTown = town.town;
1396
+ if (originalTown.indexOf('町') === -1)
1397
+ continue;
1398
+ townAbbr = originalTown.replace(/(?!^町)町/g, '') // NOTE: 冒頭の「町」は明らかに省略するべきではないので、除外
1399
+ ;
1400
+ if (!isKyoto && // 京都は通り名削除の処理があるため、意図しないマッチになるケースがある。これを除く
1401
+ !townSet.has(townAbbr) &&
1402
+ !townSet.has("\u5927\u5B57" + townAbbr) && // 大字は省略されるため、大字〇〇と〇〇町がコンフリクトする。このケースを除外
1403
+ !isKanjiNumberFollewedByCho(originalTown)) {
1404
+ // エイリアスとして町なしのパターンを登録
1405
+ towns.push(__assign(__assign({}, town), { originalTown: originalTown, town: townAbbr }));
1406
+ }
1407
+ }
1408
+ // 少ない文字数の地名に対してミスマッチしないように文字の長さ順にソート
1409
+ towns.sort(function (a, b) {
1410
+ var aLen = a.town.length;
1411
+ var bLen = b.town.length;
1412
+ // 大字で始まる場合、優先度を低く設定する。
1413
+ // 大字XX と XXYY が存在するケースもあるので、 XXYY を先にマッチしたい
1414
+ if (a.town.startsWith('大字'))
1415
+ aLen -= 2;
1416
+ if (b.town.startsWith('大字'))
1417
+ bLen -= 2;
1418
+ return bLen - aLen;
1419
+ });
1420
+ patterns = towns.map(function (town) {
1421
+ var pattern = toRegexPattern(town.town
1422
+ // 横棒を含む場合(流通センター、など)に対応
1423
+ .replace(/[--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━]/g, '[--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━]')
1424
+ .replace(/大?字/g, '(大?字)?')
1425
+ // 以下住所マスターの町丁目に含まれる数字を正規表現に変換する
1426
+ .replace(/([壱一二三四五六七八九十]+)(丁目?|番(町|丁)|条|軒|線|(の|ノ)町|地割|号)/g, function (match) {
1427
+ var patterns = [];
1428
+ patterns.push(match
1429
+ .toString()
1430
+ .replace(/(丁目?|番(町|丁)|条|軒|線|(の|ノ)町|地割|号)/, '')); // 漢数字
1431
+ if (match.match(/^壱/)) {
1432
+ patterns.push('一');
1433
+ patterns.push('1');
1434
+ patterns.push('1');
1435
+ }
1436
+ else {
1437
+ var num = match
1438
+ .replace(/([一二三四五六七八九十]+)/g, function (match) {
1439
+ return kan2num(match);
1440
+ })
1441
+ .replace(/(丁目?|番(町|丁)|条|軒|線|(の|ノ)町|地割|号)/, '');
1442
+ patterns.push(num.toString()); // 半角アラビア数字
1443
+ }
1444
+ // 以下の正規表現は、上のよく似た正規表現とは違うことに注意!
1445
+ var _pattern = "(" + patterns.join('|') + ")((\u4E01|\u753A)\u76EE?|\u756A(\u753A|\u4E01)|\u6761|\u8ED2|\u7DDA|\u306E\u753A?|\u5730\u5272|\u53F7|[-\uFF0D\uFE63\u2212\u2010\u2043\u2011\u2012\u2013\u2014\uFE58\u2015\u23AF\u23E4\u30FC\uFF70\u2500\u2501])";
1446
+ return _pattern; // デバッグのときにめんどくさいので変数に入れる。
1447
+ }));
1448
+ return [town, pattern];
1449
+ });
1450
+ // X丁目の丁目なしの数字だけ許容するため、最後に数字だけ追加していく
1451
+ for (_a = 0, towns_1 = towns; _a < towns_1.length; _a++) {
1452
+ town = towns_1[_a];
1453
+ chomeMatch = town.town.match(/([^一二三四五六七八九十]+)([一二三四五六七八九十]+)(丁目?)/);
1454
+ if (!chomeMatch) {
1455
+ continue;
1456
+ }
1457
+ chomeNamePart = chomeMatch[1];
1458
+ chomeNum = chomeMatch[2];
1459
+ pattern = toRegexPattern("^" + chomeNamePart + "(" + chomeNum + "|" + kan2num(chomeNum) + ")");
1460
+ patterns.push([town, pattern]);
1461
+ }
1462
+ cachedTownRegexes.set(pref + "-" + city, patterns);
1463
+ return [2 /*return*/, patterns];
1464
+ }
1465
+ });
1466
+ }); };
1467
+ var getSameNamedPrefectureCityRegexPatterns = function (prefs, prefList) {
1468
+ if (typeof cachedSameNamedPrefectureCityRegexPatterns !== 'undefined') {
1469
+ return cachedSameNamedPrefectureCityRegexPatterns;
1470
+ }
1471
+ var _prefs = prefs.map(function (pref) {
1472
+ return pref.replace(/[都|道|府|県]$/, '');
1473
+ });
1474
+ cachedSameNamedPrefectureCityRegexPatterns = [];
1475
+ for (var pref in prefList) {
1476
+ for (var i = 0; i < prefList[pref].length; i++) {
1477
+ var city = prefList[pref][i];
1478
+ // 「福島県石川郡石川町」のように、市の名前が別の都道府県名から始まっているケースも考慮する。
1479
+ for (var j = 0; j < _prefs.length; j++) {
1480
+ if (city.indexOf(_prefs[j]) === 0) {
1481
+ cachedSameNamedPrefectureCityRegexPatterns.push([
1482
+ "" + pref + city,
1483
+ "^" + city,
1484
+ ]);
1485
+ }
1486
+ }
1487
+ }
1488
+ }
1489
+ return cachedSameNamedPrefectureCityRegexPatterns;
1490
+ };
1491
+
1492
+ function unfetch_module(e,n){return n=n||{},new Promise(function(t,r){var s=new XMLHttpRequest,o=[],u=[],i={},a=function(){return {ok:2==(s.status/100|0),statusText:s.statusText,status:s.status,url:s.responseURL,text:function(){return Promise.resolve(s.responseText)},json:function(){return Promise.resolve(s.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([s.response]))},clone:a,headers:{keys:function(){return o},entries:function(){return u},get:function(e){return i[e.toLowerCase()]},has:function(e){return e.toLowerCase()in i}}}};for(var l in s.open(n.method||"get",e,!0),s.onload=function(){s.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(e,n,t){o.push(n=n.toLowerCase()),u.push([n,t]),i[n]=i[n]?i[n]+","+t:t;}),t(a());},s.onerror=r,s.withCredentials="include"==n.credentials,n.headers)s.setRequestHeader(l,n.headers[l]);s.send(n.body||null);})}
1493
+
1494
+ var unfetch_module$1 = /*#__PURE__*/Object.freeze({
1495
+ __proto__: null,
1496
+ 'default': unfetch_module
1497
+ });
1498
+
1499
+ var require$$0 = /*@__PURE__*/getAugmentedNamespace(unfetch_module$1);
1500
+
1501
+ var browser = self.fetch || (self.fetch = require$$0.default || require$$0);
1502
+
1503
+ var config$1 = currentConfig;
1504
+ var defaultOption = {
1505
+ level: 3,
1506
+ };
1507
+ /**
1508
+ * @internal
1509
+ */
1510
+ var __internals = {
1511
+ // default fetch
1512
+ fetch: function (input) {
1513
+ var url = new URL("" + config$1.japaneseAddressesApi + input).toString();
1514
+ if (config$1.geoloniaApiKey) {
1515
+ url += "?geolonia-api-key=" + config$1.geoloniaApiKey;
1516
+ }
1517
+ return browser(url);
1518
+ },
1519
+ };
1520
+ var normalizeTownName = function (addr, pref, city) { return __awaiter(void 0, void 0, void 0, function () {
1521
+ var townPatterns, regexPrefixes, _i, regexPrefixes_1, regexPrefix, _a, townPatterns_1, _b, town, pattern, regex, match;
1522
+ return __generator(this, function (_c) {
1523
+ switch (_c.label) {
1524
+ case 0:
1525
+ addr = addr.trim().replace(/^大字/, '');
1526
+ return [4 /*yield*/, getTownRegexPatterns(pref, city)];
1527
+ case 1:
1528
+ townPatterns = _c.sent();
1529
+ regexPrefixes = ['^'];
1530
+ if (city.match(/^京都市/)) {
1531
+ // 京都は通り名削除のために後方一致を使う
1532
+ regexPrefixes.push('.*');
1533
+ }
1534
+ for (_i = 0, regexPrefixes_1 = regexPrefixes; _i < regexPrefixes_1.length; _i++) {
1535
+ regexPrefix = regexPrefixes_1[_i];
1536
+ for (_a = 0, townPatterns_1 = townPatterns; _a < townPatterns_1.length; _a++) {
1537
+ _b = townPatterns_1[_a], town = _b[0], pattern = _b[1];
1538
+ regex = new RegExp("" + regexPrefix + pattern);
1539
+ match = addr.match(regex);
1540
+ if (match) {
1541
+ return [2 /*return*/, {
1542
+ town: town.originalTown || town.town,
1543
+ addr: addr.substr(match[0].length),
1544
+ lat: town.lat,
1545
+ lng: town.lng,
1546
+ }];
1547
+ }
1548
+ }
1549
+ }
1550
+ return [2 /*return*/];
1551
+ }
1552
+ });
1553
+ }); };
1554
+ var normalizeResidentialPart = function (addr, pref, city, town) { return __awaiter(void 0, void 0, void 0, function () {
1555
+ var _a, gaikuListItem, residentials, match, gaiku_1, jyukyo, jyukyohyoji_1, residential, addr2, gaikuItem, addr2;
1556
+ return __generator(this, function (_b) {
1557
+ switch (_b.label) {
1558
+ case 0: return [4 /*yield*/, Promise.all([
1559
+ getGaikuList(pref, city, town),
1560
+ getResidentials(pref, city, town),
1561
+ ])
1562
+ // 住居表示未整備
1563
+ ];
1564
+ case 1:
1565
+ _a = _b.sent(), gaikuListItem = _a[0], residentials = _a[1];
1566
+ // 住居表示未整備
1567
+ if (gaikuListItem.length === 0) {
1568
+ return [2 /*return*/, null];
1569
+ }
1570
+ match = addr.match(/^([1-9][0-9]*)-([1-9][0-9]*)/);
1571
+ if (match) {
1572
+ gaiku_1 = match[1];
1573
+ jyukyo = match[2];
1574
+ jyukyohyoji_1 = gaiku_1 + "-" + jyukyo;
1575
+ residential = residentials.find(function (res) { return res.gaiku + "-" + res.jyukyo === jyukyohyoji_1; });
1576
+ if (residential) {
1577
+ addr2 = addr.replace(jyukyohyoji_1, '').trim();
1578
+ return [2 /*return*/, {
1579
+ gaiku: gaiku_1,
1580
+ jyukyo: jyukyo,
1581
+ addr: addr2,
1582
+ lat: residential.lat,
1583
+ lng: residential.lng,
1584
+ }];
1585
+ }
1586
+ gaikuItem = gaikuListItem.find(function (item) { return item.gaiku === gaiku_1; });
1587
+ if (gaikuItem) {
1588
+ addr2 = addr.replace(gaikuItem.gaiku, '').trim();
1589
+ return [2 /*return*/, { gaiku: gaiku_1, addr: addr2, lat: gaikuItem.lat, lng: gaikuItem.lng }];
1590
+ }
1591
+ }
1592
+ return [2 /*return*/, null];
1593
+ }
1594
+ });
1595
+ }); };
1596
+ var normalize$1 = function (address, _option) {
1597
+ if (_option === void 0) { _option = defaultOption; }
1598
+ 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;
1600
+ return __generator(this, function (_e) {
1601
+ switch (_e.label) {
1602
+ case 0:
1603
+ option = __assign(__assign({}, defaultOption), _option);
1604
+ if (option.geoloniaApiKey || config$1.geoloniaApiKey) {
1605
+ option.level = 8;
1606
+ option.geoloniaApiKey && (config$1.geoloniaApiKey = option.geoloniaApiKey);
1607
+ // API キーがある場合は、 Geolonia SaaS に切り替え。
1608
+ // ただし、config を書き換えて別のエンドポイントを使うようにカスタマイズしているケースがあるので、その場合は config に既に入っている値を優先
1609
+ if (config$1.japaneseAddressesApi === gh_pages_endpoint) {
1610
+ config$1.japaneseAddressesApi =
1611
+ 'https://japanese-addresses.geolonia.com/next/ja';
1612
+ }
1613
+ }
1614
+ addr = address
1615
+ .normalize('NFC')
1616
+ .replace(/ /g, ' ')
1617
+ .replace(/ +/g, ' ')
1618
+ .replace(/([0-9A-Za-z]+)/g, function (match) {
1619
+ // 全角のアラビア数字は問答無用で半角にする
1620
+ return zen2han(match);
1621
+ })
1622
+ // 数字の後または数字の前にくる横棒はハイフンに統一する
1623
+ .replace(/([0-90-9一二三四五六七八九〇十百千][--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━])|([--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━])[0-90-9一二三四五六七八九〇十]/g, function (match) {
1624
+ return match.replace(/[--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━]/g, '-');
1625
+ })
1626
+ .replace(/(.+)(丁目?|番(町|地|丁)|条|軒|線|(の|ノ)町|地割)/, function (match) {
1627
+ return match.replace(/ /g, ''); // 町丁目名以前のスペースはすべて削除
1628
+ })
1629
+ .replace(/(.+)((郡.+(町|村))|((市|巿).+(区|區)))/, function (match) {
1630
+ return match.replace(/ /g, ''); // 区、郡以前のスペースはすべて削除
1631
+ })
1632
+ .replace(/.+?[0-9一二三四五六七八九〇十百千]-/, function (match) {
1633
+ return match.replace(/ /g, ''); // 1番はじめに出てくるアラビア数字以前のスペースを削除
1634
+ });
1635
+ pref = '';
1636
+ city = '';
1637
+ town = '';
1638
+ lat = null;
1639
+ lng = null;
1640
+ level = 0;
1641
+ normalized = null;
1642
+ return [4 /*yield*/, getPrefectures()];
1643
+ case 1:
1644
+ prefectures = _e.sent();
1645
+ prefs = Object.keys(prefectures);
1646
+ prefPatterns = getPrefectureRegexPatterns(prefs);
1647
+ sameNamedPrefectureCityRegexPatterns = getSameNamedPrefectureCityRegexPatterns(prefs, prefectures);
1648
+ // 県名が省略されており、かつ市の名前がどこかの都道府県名と同じ場合(例.千葉県千葉市)、
1649
+ // あらかじめ県名を補完しておく。
1650
+ for (i = 0; i < sameNamedPrefectureCityRegexPatterns.length; i++) {
1651
+ _a = sameNamedPrefectureCityRegexPatterns[i], prefectureCity = _a[0], reg = _a[1];
1652
+ match = addr.match(reg);
1653
+ if (match) {
1654
+ addr = addr.replace(new RegExp(reg), prefectureCity);
1655
+ break;
1656
+ }
1657
+ }
1658
+ for (i = 0; i < prefPatterns.length; i++) {
1659
+ _b = prefPatterns[i], _pref = _b[0], pattern = _b[1];
1660
+ match = addr.match(pattern);
1661
+ if (match) {
1662
+ pref = _pref;
1663
+ addr = addr.substring(match[0].length); // 都道府県名以降の住所
1664
+ break;
1665
+ }
1666
+ }
1667
+ if (!!pref) return [3 /*break*/, 6];
1668
+ matched = [];
1669
+ for (_pref in prefectures) {
1670
+ cities = prefectures[_pref];
1671
+ cityPatterns = getCityRegexPatterns(_pref, cities);
1672
+ addr = addr.trim();
1673
+ for (i = 0; i < cityPatterns.length; i++) {
1674
+ _c = cityPatterns[i], _city = _c[0], pattern = _c[1];
1675
+ match = addr.match(pattern);
1676
+ if (match) {
1677
+ matched.push({
1678
+ pref: _pref,
1679
+ city: _city,
1680
+ addr: addr.substring(match[0].length),
1681
+ });
1682
+ }
1683
+ }
1684
+ }
1685
+ if (!(1 === matched.length)) return [3 /*break*/, 2];
1686
+ pref = matched[0].pref;
1687
+ return [3 /*break*/, 6];
1688
+ case 2:
1689
+ i = 0;
1690
+ _e.label = 3;
1691
+ case 3:
1692
+ if (!(i < matched.length)) return [3 /*break*/, 6];
1693
+ return [4 /*yield*/, normalizeTownName(matched[i].addr, matched[i].pref, matched[i].city)];
1694
+ case 4:
1695
+ normalized_1 = _e.sent();
1696
+ if (normalized_1) {
1697
+ pref = matched[i].pref;
1698
+ }
1699
+ _e.label = 5;
1700
+ case 5:
1701
+ i++;
1702
+ return [3 /*break*/, 3];
1703
+ case 6:
1704
+ if (pref && option.level >= 2) {
1705
+ cities = prefectures[pref];
1706
+ cityPatterns = getCityRegexPatterns(pref, cities);
1707
+ addr = addr.trim();
1708
+ for (i = 0; i < cityPatterns.length; i++) {
1709
+ _d = cityPatterns[i], _city = _d[0], pattern = _d[1];
1710
+ match = addr.match(pattern);
1711
+ if (match) {
1712
+ city = _city;
1713
+ addr = addr.substring(match[0].length); // 市区町村名以降の住所
1714
+ break;
1715
+ }
1716
+ }
1717
+ }
1718
+ if (!(city && option.level >= 3)) return [3 /*break*/, 8];
1719
+ return [4 /*yield*/, normalizeTownName(addr, pref, city)];
1720
+ case 7:
1721
+ normalized = _e.sent();
1722
+ if (normalized) {
1723
+ town = normalized.town;
1724
+ addr = normalized.addr;
1725
+ lat = parseFloat(normalized.lat);
1726
+ lng = parseFloat(normalized.lng);
1727
+ if (Number.isNaN(lat) || Number.isNaN(lng)) {
1728
+ lat = null;
1729
+ lng = null;
1730
+ }
1731
+ }
1732
+ // townが取得できた場合にのみ、addrに対する各種の変換処理を行う。
1733
+ if (town) {
1734
+ addr = addr
1735
+ .replace(/^-/, '')
1736
+ .replace(/([0-9]+)(丁目)/g, function (match) {
1737
+ return match.replace(/([0-9]+)/g, function (num) {
1738
+ return dist.number2kanji(Number(num));
1739
+ });
1740
+ })
1741
+ .replace(/(([0-9〇一二三四五六七八九十百千]+)(番地?)([0-9〇一二三四五六七八九十百千]+)号)\s*(.+)/, '$1 $5')
1742
+ .replace(/([0-9〇一二三四五六七八九十百千]+)\s*(番地?)\s*([0-9〇一二三四五六七八九十百千]+)\s*号?/, '$1-$3')
1743
+ .replace(/([0-9〇一二三四五六七八九十百千]+)番地?/, '$1')
1744
+ .replace(/([0-9〇一二三四五六七八九十百千]+)の/g, '$1-')
1745
+ .replace(/([0-9〇一二三四五六七八九十百千]+)[--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━]/g, function (match) {
1746
+ return kan2num(match).replace(/[--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━]/g, '-');
1747
+ })
1748
+ .replace(/[--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━]([0-9〇一二三四五六七八九十百千]+)/g, function (match) {
1749
+ return kan2num(match).replace(/[--﹣−‐⁃‑‒–—﹘―⎯⏤ーー─━]/g, '-');
1750
+ })
1751
+ .replace(/([0-9〇一二三四五六七八九十百千]+)-/, function (s) {
1752
+ // `1-` のようなケース
1753
+ return kan2num(s);
1754
+ })
1755
+ .replace(/-([0-9〇一二三四五六七八九十百千]+)/, function (s) {
1756
+ // `-1` のようなケース
1757
+ return kan2num(s);
1758
+ })
1759
+ .replace(/-[^0-9]+([0-9〇一二三四五六七八九十百千]+)/, function (s) {
1760
+ // `-あ1` のようなケース
1761
+ return kan2num(zen2han(s));
1762
+ })
1763
+ .replace(/([0-9〇一二三四五六七八九十百千]+)$/, function (s) {
1764
+ // `串本町串本1234` のようなケース
1765
+ return kan2num(s);
1766
+ })
1767
+ .trim();
1768
+ }
1769
+ _e.label = 8;
1770
+ case 8:
1771
+ 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)];
1774
+ case 9:
1775
+ normalized = _e.sent();
1776
+ _e.label = 10;
1777
+ case 10:
1778
+ if (normalized) {
1779
+ lat = parseFloat(normalized.lat);
1780
+ lng = parseFloat(normalized.lng);
1781
+ }
1782
+ if (Number.isNaN(lat) || Number.isNaN(lng)) {
1783
+ lat = null;
1784
+ lng = null;
1785
+ }
1786
+ if (pref)
1787
+ level = level + 1;
1788
+ if (city)
1789
+ level = level + 1;
1790
+ if (town)
1791
+ level = level + 1;
1792
+ result = {
1793
+ pref: pref,
1794
+ city: city,
1795
+ town: town,
1796
+ addr: addr,
1797
+ lat: lat,
1798
+ lng: lng,
1799
+ level: level,
1800
+ };
1801
+ if (normalized && 'gaiku' in normalized) {
1802
+ result.addr = normalized.addr;
1803
+ result.gaiku = normalized.gaiku;
1804
+ result.level = 7;
1805
+ }
1806
+ if (normalized && 'jyukyo' in normalized) {
1807
+ result.jyukyo = normalized.jyukyo;
1808
+ result.level = 8;
1809
+ }
1810
+ return [2 /*return*/, result];
1811
+ }
1812
+ });
1813
+ });
1814
+ };
1815
+
1816
+ var config = config$1;
1817
+ var normalize = normalize$1;
1818
+
1819
+ export { config, normalize };