Files
tasteby/frontend/src/lib/region.ts
joungmin 4760b5a284 [Developer] #532 지역 표시 계층화 formatRegion (한국|서울 → 한국 › 서울)
- lib/region.ts formatRegion() 신설: 파이프 분리 + 빈토큰/null/나라 더미 제거 + ' › ' 조인
- RestaurantDetail/RestaurantList 지역 표기에 적용
- buildSearchQuery(검색용 공백조인) 유지
- 설계서 docs/design/532-region-display/README.md

Refs #532

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 16:15:53 +09:00

23 lines
869 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 지역 표시 유틸 — #532
// region 은 "나라|시도|구군" 파이프 구분 문자열. 사용자에게는 계층(breadcrumb)으로 보여준다.
/** 표시에서 제외할 더미/무의미 토큰. */
const DUMMY_TOKENS = new Set(["", "null", "나라"]);
/**
* 파이프 구분 region 을 "나라 시도 구군" 계층 문자열로 변환한다.
* 빈 토큰·"null"·더미("나라")는 제거한다. 유효 토큰이 없으면 "".
*
* 예) "한국|서울|강남구" → "한국 서울 강남구"
* "일본|null" → "일본"
* "한국||관악구" → "한국 관악구"
*/
export function formatRegion(region: string | null | undefined): string {
if (!region) return "";
return region
.split("|")
.map((t) => t.trim())
.filter((t) => !DUMMY_TOKENS.has(t.toLowerCase()))
.join(" ");
}