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

漢数字の小字でクラッシュする問題に対応 #221

Merged
merged 9 commits into from
Sep 7, 2023
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)
})
})
})
}