Skip to content

Commit

Permalink
漢数字の小字でクラッシュする問題に対応 (#221)
Browse files Browse the repository at this point in the history
* Add test case with 愛知県豊田市西丹波町三五十 (#215)  and 広島県府中市栗柄町名字八五十2459 (#214)

* issue #215 fix

---------

Co-authored-by: miyabe <[email protected]>
  • Loading branch information
Kamata, Ryo and miyabe committed Sep 7, 2023
1 parent 6196f3f commit ab76322
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/kan2num.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import { kanji2number, findKanjiNumbers } from '@geolonia/japanese-numeral'
export const kan2num = (string: string) => {
const kanjiNumbers = findKanjiNumbers(string)
for (let i = 0; i < kanjiNumbers.length; i++) {
// @ts-ignore
string = string.replace(kanjiNumbers[i], kanji2number(kanjiNumbers[i]))
try {
// @ts-ignore
string = string.replace(kanjiNumbers[i], kanji2number(kanjiNumbers[i]));
} catch (error) {
// ignore
}
}

return string
Expand Down
18 changes: 18 additions & 0 deletions test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,5 +1118,23 @@ for (const [runtime, normalize] of cases) {
expect(res.town).toEqual('柿さき町')
expect(res.level).toEqual(3)
})

describe('漢数字の小字のケース', () => {
test('愛知県豊田市西丹波町三五十', async () => {
const address = '愛知県豊田市西丹波町三五十'
const res = await normalize(address)
expect(res.town).toEqual('西丹波町')
expect(res.addr).toEqual("三五十")
expect(res.level).toEqual(3)
})

test('広島県府中市栗柄町名字八五十2459 小字以降は現在のところ無視される', async () => {
const address = '広島県府中市栗柄町名字八五十2459'
const res = await normalize(address)
expect(res.town).toEqual('栗柄町')
expect(res.addr).toEqual("名字八五十2459")
expect(res.level).toEqual(3)
})
})
})
}

0 comments on commit ab76322

Please sign in to comment.