proc finder

const fs = require('fs/promises'); const path = require('path'); async function main() { const appDir = __dirname; const procedurePath = path.join(appDir, 'allprocedure.txt'); const targetsPath = path.join(appDir, 'crypto-targets.json'); const outputPath = path.join(appDir, 'outproc.txt'); const [procedureText, targets] = await Promise.all([ fs.readFile(procedurePath, 'utf8'), readCryptoTargets(targetsPath), ]); const procedures = parseProcedures(procedureText); const matchedNames = []; const seen = new Set(); for (const procedure of procedures) { if (!hasCryptoTarget(procedure.body, targets)) continue; const key = procedure.name.toUpperCase(); if (seen.has(key)) continue; seen.add(key); matchedNames.push(procedure.name); } await fs.writeFile(outputPath, `${matchedNames.join('\n')}${matchedNames.length ? '\n' : ''}`, 'utf8'); console.log(`Done. procedures: ${procedures.length}, matched: ${matchedNames.length}, output: ${outputPath}`); } function parseProcedures(text) { const procedures = []; const headerPattern = /^\s*프로시져명\s*:\s*(.+?)\s*$/gmi; const headers = [...text.matchAll(headerPattern)]; for (let index = 0; index < headers.length; index += 1) { const header = headers[index]; const nextHeader = headers[index + 1]; const name = header[1].trim(); const bodyStart = header.index + header[0].length; const bodyEnd = nextHeader ? nextHeader.index : text.length; const body = text.slice(bodyStart, bodyEnd); if (name) procedures.push({ name, body }); } return procedures; } function hasCryptoTarget(text, targets) { return targets.some((target) => ( hasBoundaryToken(text, target.tableName) || hasBoundaryToken(text, target.plainColumn) )); } async function readCryptoTargets(filePath) { const text = await fs.readFile(filePath, 'utf8'); const parsed = JSON.parse(text); if (!Array.isArray(parsed)) { throw new Error(`crypto-targets.json must be an array: ${filePath}`); } return parsed .map((target) => ({ tableName: normalizeRequired(target.tableName), plainColumn: normalizeRequired(target.plainColumn), })) .filter((target) => target.tableName && target.plainColumn); } function hasBoundaryToken(text, token) { return token ? boundaryPattern(token).test(text) : false; } function boundaryPattern(token) { return new RegExp(`(^|[^A-Za-z0-9_])${escapeRegExp(token)}(?=$|[^A-Za-z0-9_])`, 'i'); } function normalizeRequired(value) { return String(value ?? '').trim(); } function escapeRegExp(value) { return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); } main().catch((error) => { console.error(error instanceof Error ? error.message : error); process.exitCode = 1; });

댓글

이 블로그의 인기 게시물

food eff privacy

판다 스픽 , 개인정보 처리방침 , Panda Speak Privacy Term

판다 수학 개인정보 처리방침 , Privacy , Panda Math