rhombic
Version:
SQL parsing, lineage extraction and manipulation
47 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Cursor = void 0;
/**
* Utility class to work with a string cursor.
*/
class Cursor {
constructor(value) {
this.value = value;
}
insertAt(str, pos) {
let line = pos.lineNumber;
let idx = 0;
for (; idx < str.length && line > 1; idx++) {
if (str.charAt(idx) === "\n") {
line--;
}
}
idx += pos.column - 1;
const prefix = str.slice(0, idx);
const suffix = str.slice(idx);
return `${prefix}${this.value}${suffix}`;
}
isSuffixOf(str) {
return str.endsWith(this.value);
}
isIn(str) {
return str.includes(str);
}
removeFrom(str) {
if (typeof str === "object") {
return {
catalogName: str.catalogName ? this.removeFrom(str.catalogName) : undefined,
schemaName: str.schemaName ? this.removeFrom(str.schemaName) : undefined,
tableName: this.removeFrom(str.tableName),
alias: str.alias ? this.removeFrom(str.alias) : undefined,
range: str.range
};
}
return str.replace(this.value, "");
}
isEqualTo(str) {
return str === this.value;
}
}
exports.Cursor = Cursor;
//# sourceMappingURL=Cursor.js.map