fix: 지역 단위를 시군구 256곳으로 되돌림 (일반구 포함)
This commit is contained in:
1 parent
8e40242c22
commit
a7a6dd49d0
7 files changed
+49
-36
No files matched your search
@@ -8,22 +8,13 @@ const KEY = 'nalssigak.b.region'
|
||||
function readStored(): RegionData | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(KEY)
|
||||
return raw ? toCity(JSON.parse(raw) as RegionData) : null
|
||||
return raw ? (JSON.parse(raw) as RegionData) : null
|
||||
} catch {
|
||||
// 사파리 프라이빗 모드 등에서는 저장소를 못 쓴다 → 기본 구로 시작
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/** 일반구가 있던 시. 예전에 저장한 '수원시 장안구'는 '수원시'로 바꿔 읽는다 */
|
||||
const MERGED_CITIES = new Set(['4111', '4113', '4117', '4119', '4127', '4128', '4146', '4159', '4311', '4413', '4711', '4812', '5211'])
|
||||
|
||||
function toCity(r: RegionData): RegionData {
|
||||
if (!MERGED_CITIES.has(r.code.slice(0, 4)) || r.code.endsWith('000000')) return r
|
||||
const [sido, city] = r.name.split(' ')
|
||||
return { ...r, code: `${r.code.slice(0, 4)}000000`, name: `${sido} ${city}`, short_name: city }
|
||||
}
|
||||
|
||||
function writeStored(r: RegionData) {
|
||||
try {
|
||||
localStorage.setItem(KEY, JSON.stringify(r))
|
||||
|
||||
Reference in new issue
Block a user