feat(listings): 실매물 tier/금액 순수 헬퍼 + 테스트

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UHXzpsZQxKG9hQmNRfZjRS
This commit is contained in:
2026-07-09 14:32:52 +09:00
parent a087c3d1e5
commit a5e33b70df
2 changed files with 84 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
/* 실매물 판정 tier / 금액 포맷 순수 헬퍼 */
const C = { green: '#34d399', yellow: '#f59e0b', red: '#f87171', gray: '#94a3b8' };
export const SAFETY_TIER_META = Object.freeze({
'안전': { emoji: '🟢', color: C.green },
'주의': { emoji: '🟡', color: C.yellow },
'위험': { emoji: '🔴', color: C.red },
'보류': { emoji: '⚪', color: C.gray },
});
export const VALUATION_TIER_META = Object.freeze({
'저평가': { emoji: '🟢', color: C.green },
'시세': { emoji: '🟡', color: C.yellow },
'고가': { emoji: '🔴', color: C.red },
'보류': { emoji: '⚪', color: C.gray },
});
export const tierMeta = (kind, tier) => {
const map = kind === 'valuation' ? VALUATION_TIER_META : SAFETY_TIER_META;
if (Object.hasOwn(map, tier)) return { ...map[tier], label: tier };
return { emoji: '⚪', color: C.gray, label: tier ?? '' };
};
export const formatMoney = (manwon) => {
if (manwon == null || manwon === '') return '-';
const n = Number(manwon);
if (Number.isNaN(n)) return '-';
const eok = Math.floor(n / 10000);
const rest = n % 10000;
if (eok > 0 && rest > 0) return `${eok}${rest.toLocaleString('ko-KR')}`;
if (eok > 0) return `${eok}`;
return `${n.toLocaleString('ko-KR')}`;
};
export const formatRatio = (ratio) => {
if (ratio == null) return '-';
const n = Number(ratio);
if (Number.isNaN(n)) return '-';
return `${(n * 100).toFixed(1)}%`;
};