UNPKG

rhombic

Version:

SQL parsing, lineage extraction and manipulation

41 lines 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.replaceText = void 0; const insertText_1 = require("./insertText"); /** * Replace a piece of text in a multine sql statement. * @param sql intial sql * @param input text to insert * @param location */ const replaceText = (sql, input, location) => { const lines = sql .split("\n") .map((line, lineNumber) => { let nextLine; if (lineNumber === location.startLine - 1 && location.startLine === location.endLine) { nextLine = line.slice(0, location.startColumn - 1) + line.slice(location.endColumn); } else if (location.startLine - 1 === lineNumber) { nextLine = line.slice(0, location.startColumn - 1); } else if (location.endLine - 1 === lineNumber) { nextLine = line.slice(location.endColumn); } else if (lineNumber > location.startLine - 1 && lineNumber < location.endLine - 1) { nextLine = ""; } if (nextLine === undefined) { return line; } // Filter empty modified lines return nextLine === "" ? false : nextLine; }) .filter(line => line !== false); return insertText_1.insertText(lines.join("\n"), input, { line: location.startLine, column: location.startColumn - 1 }); }; exports.replaceText = replaceText; //# sourceMappingURL=replaceText.js.map