260202_01_ENH: route 구조 초창기 기획으로 다시 변경 및 Category 별 하위 페이지에 샘플 데이터 모두 적용
This commit is contained in:
@@ -99,4 +99,47 @@ export const formatKst = (
|
||||
return `${yyyy}-${MM}-${dd} ${HH}:${mm}:${ss}`;
|
||||
};
|
||||
|
||||
export const isBlank = (v?: string | null) => !v || v.trim().length === 0;
|
||||
export const isBlank = (v?: string | null) => !v || v.trim().length === 0;
|
||||
|
||||
export const norm = (s: string) => s.replace(/\s+/g, "").toLowerCase();
|
||||
export const asNum = (v: unknown): number | null => typeof v === "number" && Number.isFinite(v) ? v : null;
|
||||
|
||||
export const formatNumber = (v: number) =>
|
||||
Number.isInteger(v) ? v.toLocaleString() : v.toLocaleString(undefined, { maximumFractionDigits: 1 });
|
||||
/**
|
||||
* 다양한 형식의 값을 숫자로 파싱합니다.
|
||||
* - 쉼표, 퍼센트, 유니코드 마이너스 자동 처리
|
||||
* - null/undefined/빈문자열/"−" 등은 null 반환
|
||||
* - 유한하지 않은 숫자는 null 반환
|
||||
*/
|
||||
export function parseNumber(
|
||||
value: unknown,
|
||||
options?: {
|
||||
allowComma?: boolean; // 기본값: true
|
||||
allowPercent?: boolean; // 기본값: true
|
||||
allowMinus?: boolean; // 기본값: true (유니코드 마이너스 포함)
|
||||
}
|
||||
): number | null {
|
||||
const { allowComma = true, allowPercent = true, allowMinus = true } = options ?? {};
|
||||
|
||||
if (value === null || value === undefined) return null;
|
||||
|
||||
if (typeof value === "number") {
|
||||
return Number.isFinite(value) ? value : null;
|
||||
}
|
||||
|
||||
if (typeof value === "string") {
|
||||
let s = value.trim();
|
||||
|
||||
if (s === "" || s === "-" || s === "−") return null;
|
||||
|
||||
if (allowComma) s = s.replaceAll(",", "");
|
||||
if (allowPercent) s = s.replaceAll("%", "");
|
||||
if (allowMinus) s = s.replaceAll("−", "-"); // 유니코드 마이너스 -> ASCII 마이너스
|
||||
|
||||
const n = Number(s);
|
||||
return Number.isFinite(n) ? n : null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user