/* 802-4b-2 꺼진 줄 헬퍼 — common_util_formula_doc_view.ts 를 그 자리에서 트랜스파일해 Node 로 돌림. * stdin = [{문서, 값}] · stdout = [{새: [꺼진 금액 줄 차례], 옛: [만약 끝 0 만]}] */ const fs = require("fs"); const path = require("path"); const ts = require(path.join(__dirname, "..", "..", "config", "node_modules", "typescript")); const cache = new Map(); function load(at) { if (cache.has(at)) return cache.get(at); const js = ts.transpileModule(fs.readFileSync(at, "utf8"), { compilerOptions: { module: ts.ModuleKind.CommonJS, target: ts.ScriptTarget.ES2020 }, }).outputText; const box = { exports: {} }; cache.set(at, box.exports); const need = (p) => p.startsWith(".") ? load(path.resolve(path.dirname(at), `${p}.ts`)) : require(p); new Function("exports", "module", "require", js)(box.exports, box, need); return box.exports; } const view = load( path.join(__dirname, "..", "..", "common_util", "common_util_formula_doc_view.ts"), ); const input = JSON.parse(fs.readFileSync(0, "utf8")); const out = input.map(({ 문서, 값 }) => { const steps = view.lineMap(문서); const lines = 문서.금액 || []; const pick = (f) => lines.flatMap((l, i) => (f(l) ? [i] : [])); return { 새: pick((l) => view.offLine(l, 값, steps)), 옛: pick((l) => [l.수량, l.단가].some((t) => { const n = view.tryParse(t); return !!n && view.leafNum(n, 값) === 0; }), ), }; }); process.stdout.write(JSON.stringify(out));