Skip to content

Commit

Permalink
Fix #48 #52
Browse files Browse the repository at this point in the history
  • Loading branch information
naogify committed Mar 23, 2021
1 parent 59484e3 commit 0fc1479
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 34 deletions.
71 changes: 38 additions & 33 deletions src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,169 +2,174 @@ import { normalize } from './main'

test('大阪府堺市北区新金岡町4丁1−8', async () => {
const res = await normalize('大阪府堺市北区新金岡町4丁1−8')
expect(res).toStrictEqual({"pref": "大阪府", "city": "堺市北区", "town": "新金岡町4丁", "addr": "1-8"})
expect(res).toStrictEqual({"pref": "大阪府", "city": "堺市北区", "town": "新金岡町4丁", "addr": "1-8", "building": ""})
})

test('大阪府堺市北区新金岡町4丁1ー8', async () => {
const res = await normalize('大阪府堺市北区新金岡町4丁1ー8')
expect(res).toStrictEqual({"pref": "大阪府", "city": "堺市北区", "town": "新金岡町4丁", "addr": "1-8"})
expect(res).toStrictEqual({"pref": "大阪府", "city": "堺市北区", "town": "新金岡町4丁", "addr": "1-8", "building": ""})
})

test('和歌山県串本町串本1234', async () => {
const res = await normalize('和歌山県串本町串本1234')
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": "1234"})
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": "1234", "building": ""})
})

test('和歌山県東牟婁郡串本町串本1234', async () => {
const res = await normalize('和歌山県東牟婁郡串本町串本1234')
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": "1234"})
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": "1234", "building": ""})
})

test('和歌山県東牟婁郡串本町串本一二三四', async () => {
const res = await normalize('和歌山県東牟婁郡串本町串本一二三四')
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": "1234"})
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": "1234", "building": ""})
})

test('京都府京都市中京区寺町通御池上る上本能寺前町488番地', async () => {
const res = await normalize(
'京都府京都市中京区寺町通御池上る上本能寺前町488番地',
)
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市中京区", "town": "上本能寺前町", "addr": "488"})
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市中京区", "town": "上本能寺前町", "addr": "488", "building": ""})
})

test('京都府京都市中京区上本能寺前町488', async () => {
const res = await normalize('京都府京都市中京区上本能寺前町488')
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市中京区", "town": "上本能寺前町", "addr": "488"})
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市中京区", "town": "上本能寺前町", "addr": "488", "building": ""})
})

test('大阪府大阪市中央区大手前2-1', async () => {
const res = await normalize('大阪府大阪市中央区大手前2-1')
expect(res).toStrictEqual({"pref": "大阪府", "city": "大阪市中央区", "town": "大手前2丁目", "addr": "1"})
expect(res).toStrictEqual({"pref": "大阪府", "city": "大阪市中央区", "town": "大手前2丁目", "addr": "1", "building": ""})
})

test('北海道札幌市西区二十四軒二条2丁目3番3号', async () => {
const res = await normalize('北海道札幌市西区24-2-2-3-3')
expect(res).toStrictEqual({"pref": "北海道", "city": "札幌市西区", "town": "24軒2条2丁目", "addr": "3-3"})
expect(res).toStrictEqual({"pref": "北海道", "city": "札幌市西区", "town": "24軒2条2丁目", "addr": "3-3", "building": ""})
})

test('京都府京都市東山区大和大路2-537-1', async () => {
const res = await normalize('京都府京都市東山区大和大路2-537-1')
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市東山区", "town": "大和大路2丁目", "addr": "537-1"})
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市東山区", "town": "大和大路2丁目", "addr": "537-1", "building": ""})
})

test('京都府京都市東山区大和大路2丁目五百三十七-1', async () => {
const res = await normalize('京都府京都市東山区大和大路2丁目五百三十七の1')
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市東山区", "town": "大和大路2丁目", "addr": "537-1"})
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市東山区", "town": "大和大路2丁目", "addr": "537-1", "building": ""})
})

test('愛知県蒲郡市旭町17番1号', async () => {
const res = await normalize('愛知県蒲郡市旭町17番1号')
expect(res).toStrictEqual({"pref": "愛知県", "city": "蒲郡市", "town": "旭町", "addr": "17-1"})
expect(res).toStrictEqual({"pref": "愛知県", "city": "蒲郡市", "town": "旭町", "addr": "17-1", "building": ""})
})

test('北海道岩見沢市栗沢町万字寿町1−2', async () => {
const res = await normalize('北海道岩見沢市栗沢町万字寿町1−2')
expect(res).toStrictEqual({"pref": "北海道", "city": "岩見沢市", "town": "栗沢町万字寿町", "addr": "1-2"})
expect(res).toStrictEqual({"pref": "北海道", "city": "岩見沢市", "town": "栗沢町万字寿町", "addr": "1-2", "building": ""})
})

test('北海道久遠郡せたな町北檜山区北檜山193', async () => {
const res = await normalize('北海道久遠郡せたな町北檜山区北檜山193')
expect(res).toStrictEqual({"pref": "北海道", "city": "久遠郡せたな町", "town": "北檜山区北檜山", "addr": "193"})
expect(res).toStrictEqual({"pref": "北海道", "city": "久遠郡せたな町", "town": "北檜山区北檜山", "addr": "193", "building": ""})
})

test('京都府京都市中京区錦小路通大宮東入七軒町466', async () => {
const res = await normalize('京都府京都市中京区錦小路通大宮東入七軒町466')
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市中京区", "town": "七軒町", "addr": "466"})
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市中京区", "town": "七軒町", "addr": "466", "building": ""})
})

test('栃木県佐野市七軒町2201', async () => {
const res = await normalize('栃木県佐野市七軒町2201')
expect(res).toStrictEqual({"pref": "栃木県", "city": "佐野市", "town": "七軒町", "addr": "2201"})
expect(res).toStrictEqual({"pref": "栃木県", "city": "佐野市", "town": "七軒町", "addr": "2201", "building": ""})
})

test('京都府京都市東山区大和大路通三条下る東入若松町393', async () => {
const res = await normalize(
'京都府京都市東山区大和大路通三条下る東入若松町393',
)
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市東山区", "town": "若松町", "addr": "393"})
expect(res).toStrictEqual({"pref": "京都府", "city": "京都市東山区", "town": "若松町", "addr": "393", "building": ""})
})

test('長野県長野市長野東之門町2462', async () => {
const res = await normalize('長野県長野市長野東之門町2462')
expect(res).toStrictEqual({"pref": "長野県", "city": "長野市", "town": "長野", "addr": "東之門町2462"})
expect(res).toStrictEqual({"pref": "長野県", "city": "長野市", "town": "長野", "addr": "東之門町2462", "building": ""})
})

test('岩手県下閉伊郡普代村第1地割上村43−25', async () => {
const res = await normalize('岩手県下閉伊郡普代村第1地割上村43−25')
expect(res).toStrictEqual({"pref": "岩手県", "city": "下閉伊郡普代村", "town": "第1地割字上村", "addr": "43-25"})
expect(res).toStrictEqual({"pref": "岩手県", "city": "下閉伊郡普代村", "town": "第1地割字上村", "addr": "43-25", "building": ""})
})

test('岩手県花巻市下北万丁目174−1', async () => {
const res = await normalize('岩手県花巻市下北万丁目174−1')
expect(res).toStrictEqual({"pref": "岩手県", "city": "花巻市", "town": "下北万丁目", "addr": "174-1"})
expect(res).toStrictEqual({"pref": "岩手県", "city": "花巻市", "town": "下北万丁目", "addr": "174-1", "building": ""})
})

test('岩手県花巻市十二丁目1192', async () => {
const res = await normalize('岩手県花巻市十二丁目1192')
expect(res).toStrictEqual({"pref": "岩手県", "city": "花巻市", "town": "12丁目", "addr": "1192"})
expect(res).toStrictEqual({"pref": "岩手県", "city": "花巻市", "town": "12丁目", "addr": "1192", "building": ""})
})

test('岩手県滝沢市後268−566', async () => {
const res = await normalize('岩手県滝沢市後268−566')
expect(res).toStrictEqual({"pref": "岩手県", "city": "滝沢市", "town": "後", "addr": "268-566"})
expect(res).toStrictEqual({"pref": "岩手県", "city": "滝沢市", "town": "後", "addr": "268-566", "building": ""})
})

test('青森県五所川原市金木町喜良市千苅62−8', async () => {
const res = await normalize('青森県五所川原市金木町喜良市千苅62−8')
expect(res).toStrictEqual({"pref": "青森県", "city": "五所川原市", "town": "金木町喜良市", "addr": "千苅62-8"})
expect(res).toStrictEqual({"pref": "青森県", "city": "五所川原市", "town": "金木町喜良市", "addr": "千苅62-8", "building": ""})
})

test('岩手県盛岡市盛岡駅西通2丁目9番地1号', async () => {
const res = await normalize('岩手県盛岡市盛岡駅西通2丁目9番地1号')
expect(res).toStrictEqual({"pref": "岩手県", "city": "盛岡市", "town": "盛岡駅西通2丁目", "addr": "9-1"})
expect(res).toStrictEqual({"pref": "岩手県", "city": "盛岡市", "town": "盛岡駅西通2丁目", "addr": "9-1", "building": ""})
})

test('岩手県盛岡市盛岡駅西通2丁目9の1', async () => {
const res = await normalize('岩手県盛岡市盛岡駅西通2丁目9の1')
expect(res).toStrictEqual({"pref": "岩手県", "city": "盛岡市", "town": "盛岡駅西通2丁目", "addr": "9-1"})
expect(res).toStrictEqual({"pref": "岩手県", "city": "盛岡市", "town": "盛岡駅西通2丁目", "addr": "9-1", "building": ""})
})

test('岩手県盛岡市盛岡駅西通2の9の1', async () => {
const res = await normalize('岩手県盛岡市盛岡駅西通2の9の1')
expect(res).toStrictEqual({"pref": "岩手県", "city": "盛岡市", "town": "盛岡駅西通2丁目", "addr": "9-1"})
expect(res).toStrictEqual({"pref": "岩手県", "city": "盛岡市", "town": "盛岡駅西通2丁目", "addr": "9-1", "building": ""})
})

test(' 東京都文京区千石4丁目15-7YNビル4階', async () => {
const res = await normalize(' 東京都文京区千石4丁目15-7YNビル4階')
expect(res).toStrictEqual({"pref": "東京都", "city": "文京区", "town": "千石4丁目", "addr": "15-7YNビル4階"})
expect(res).toStrictEqual({"pref": "東京都", "city": "文京区", "town": "千石4丁目", "addr": "15-7", "building": "YNビル4階"})
})

test('東京都 文京区千石4丁目15-7YNビル4階', async () => {
const res = await normalize('東京都 文京区千石4丁目15-7YNビル4階')
expect(res).toStrictEqual({"pref": "東京都", "city": "文京区", "town": "千石4丁目", "addr": "15-7YNビル4階"})
expect(res).toStrictEqual({"pref": "東京都", "city": "文京区", "town": "千石4丁目", "addr": "15-7", "building": "YNビル4階"})
})

test('東京都文京区 千石4丁目15-7YNビル4階', async () => {
const res = await normalize('東京都文京区 千石4丁目15-7YNビル4階')
expect(res).toStrictEqual({"pref": "東京都", "city": "文京区", "town": "千石4丁目", "addr": "15-7YNビル4階"})
expect(res).toStrictEqual({"pref": "東京都", "city": "文京区", "town": "千石4丁目", "addr": "15-7", "building": "YNビル4階"})
})

test('東京都文京区千石4丁目15-7 YNビル4階', async () => {
const res = await normalize('東京都文京区千石4丁目15-7 YNビル4階')
expect(res).toStrictEqual({"pref": "東京都", "city": "文京区", "town": "千石4丁目", "addr": "15-7 YNビル4階"})
expect(res).toStrictEqual({"pref": "東京都", "city": "文京区", "town": "千石4丁目", "addr": "15-7", "building": "YNビル4階"})
})

test('和歌山県東牟婁郡串本町串本 833', async () => {
const res = await normalize('和歌山県東牟婁郡串本町串本 833')
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": " 833"})
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": " 833", "building": ""})
})

test('和歌山県東牟婁郡串本町串本 833', async () => {
const res = await normalize('和歌山県東牟婁郡串本町串本 833')
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": " 833"})
expect(res).toStrictEqual({"pref": "和歌山県", "city": "東牟婁郡串本町", "town": "串本", "addr": " 833", "building": ""})
})

test('東京都世田谷区上北沢4の9の2', async () => {
const res = await normalize('東京都世田谷区上北沢4の9の2')
expect(res).toStrictEqual({"pref": "東京都", "city": "世田谷区", "town": "上北沢4丁目", "addr": "9-2"})
expect(res).toStrictEqual({"pref": "東京都", "city": "世田谷区", "town": "上北沢4丁目", "addr": "9-2", "building": ""})
})

test('大阪府堺市堺区向陵西町2丁1-26 Northグランドメゾン三国ヶ丘', async () => {
const res = await normalize('大阪府堺市堺区向陵西町2丁1-26 Northグランドメゾン三国ヶ丘')
expect(res).toStrictEqual({"pref": "大阪府", "city": "堺市堺区", "town": "向陵西町2丁", "addr": "1-26", "building": "Northグランドメゾン三国ヶ丘"})
})
14 changes: 13 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,22 @@ export const normalize = async (address: string) => {
.replace(/([(0-9]+)(|)([0-9]+)/, '$1-$3')
.replace(/([0-9]+)/, '$1')

let building = "";
const regexBuilding = new RegExp(/-[0-9]*/, 'g')
const matchBuilding = addr.match(regexBuilding)

if( matchBuilding && matchBuilding.length ){
building = addr.substring(addr.lastIndexOf(matchBuilding[matchBuilding.length -1]) + matchBuilding[matchBuilding.length -1].length)
addr = addr.replace(building,'') // 町丁目以降の住所からビル名を削除
building = address.substring(kan2num(address).lastIndexOf(building))
building = building.replace(/\s+/g,'')
}

return {
pref: pref,
city: city,
town: town,
addr: addr
addr: addr,
building:building
}
}

0 comments on commit 0fc1479

Please sign in to comment.