feat(M02-흐름도): 공용 단위 고르기 UnitPick · 끝수 줄 · 함수 판 단위 고르기로 바꿈

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01D2nUMUMTsqm93PbQtipo6c
This commit is contained in:
2026-10-01 19:42:27 +09:00
co-authored by Claude Sonnet 5.5
parent 4cd2930ff3
commit 348003cf5a
6 changed files with 411 additions and 25 deletions
@@ -0,0 +1,33 @@
/* =============================================================================
* M02_DF_Round.ts
* 끝수 — 출력 칸 수식을 ROUND 계열로 감쌈 · 감싼 것을 읽음 · DOM 없음
* 소수자리 제안은 단위 표준(M02_DF_UnitPick.suggestPlaces) · 주 ① 반올림 · ② 항목 값 우선
* ========================================================================== */
export type RoundMode = "반올림" | "올림" | "버림";
export const ROUND_FN: Record<RoundMode, string> = {
반올림: "ROUND",
올림: "ROUNDUP",
버림: "ROUNDDOWN",
};
export interface RoundSpec {
places: number;
mode: RoundMode;
}
const WRAPPED = /^(ROUND|ROUNDUP|ROUNDDOWN)\((.*),\s*(-?\d+)\s*\)$/s;
/** 칸 수식(앞 = 뺀 글) → 끝수 · 안 감싸였으면 null */
export function parseRound(formula: string): { spec: RoundSpec; inner: string } | null {
const m = WRAPPED.exec(formula.trim());
if (!m) return null;
const mode = (Object.keys(ROUND_FN) as RoundMode[]).find((k) => ROUND_FN[k] === m[1]);
return mode ? { spec: { places: Number(m[3]), mode }, inner: m[2] } : null;
}
/** 안쪽 글에 끝수를 씌움 — spec 이 null 이면 벗김 */
export function wrapRound(inner: string, spec: RoundSpec | null): string {
return spec ? `${ROUND_FN[spec.mode]}(${inner}, ${spec.places})` : inner;
}