Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

番地の前までの住所が漢数字で終わっているケースに対応 #145

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,14 @@ const normalize: (
// `-あ1` のようなケース
return kan2num(zen2han(s))
})
.replace(/([0-9〇一二三四五六七八九十百千]+)$/, (s) => {
// `串本町串本1234` のようなケース
return kan2num(s)
})
.replace(
/(([〇一二三四五六七八九十百千]+)([0-9]+)|([0-9〇一二三四五六七八九十百千]+))$/,
(s, ...args) => {
return args[1] && args[2]
? args[1] + kan2num(args[2]) // `一二三456` のような番地を除いた部分が漢数字で終わるケース。書き分けられているものとみなす
: kan2num(s) // `串本町串本1234` のようなケース
},
)
.trim()
}

Expand Down
5 changes: 5 additions & 0 deletions test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,3 +839,8 @@ test('北海道上川郡東神楽町十四号北1番地', async () => {
const res = await normalize('北海道上川郡東神楽町十四号北1番地')
expect(res).toStrictEqual({"pref": "北海道", "city": "上川郡東神楽町", "town": "十四号", "addr": "北1", "level": 3, "lat": 43.693918, "lng": 142.463511})
})

test('広島県府中市栗柄町名字八五十2459', async () => {
const res = await normalize('広島県府中市栗柄町名字八五十2459')
expect(res).toStrictEqual({pref: '広島県', city: '府中市', town: '栗柄町', addr: '名字八五十2459', lat: 34.542852, lng: 133.23166, level: 3})
})