Skip to content

Commit

Permalink
Enable to normalize kanji-number address part
Browse files Browse the repository at this point in the history
close #144
  • Loading branch information
kamataryo committed Jan 21, 2022
1 parent c7ca4ad commit ce5a0ad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
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
2 changes: 1 addition & 1 deletion test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ test('北海道上川郡東神楽町十四号北1番地', async () => {
expect(res).toStrictEqual({"pref": "北海道", "city": "上川郡東神楽町", "town": "十四号", "addr": "北1", "level": 3, "lat": 43.693918, "lng": 142.463511})
})

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

0 comments on commit ce5a0ad

Please sign in to comment.