@hpbyte/h-codex-core
Version:
Core indexing and search functionality for h-codex
46 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChunkRange = void 0;
class ChunkRange {
constructor(start, end, nodeType) {
this.start = start;
this.end = end;
this.nodeType = nodeType;
}
add(other) {
if (typeof other === 'number') {
return new ChunkRange(this.start + other, this.end + other, this.nodeType);
}
else if (other instanceof ChunkRange) {
return new ChunkRange(Math.min(this.start, other.start), Math.max(this.end, other.end), this.chooseNodeType(other.nodeType));
}
else {
throw new Error('Invalid argument type');
}
}
extract(s) {
const lines = s.split(/\r?\n/);
let start = this.start;
let end = this.end;
while (start < end && lines[start]?.trim() === '') {
start++;
}
while (end > start && lines[end]?.trim() === '') {
end--;
}
this.start = start;
this.end = end;
return lines.slice(start, end + 1).join('\n');
}
chooseNodeType(nodeType) {
if (['{', '}'].includes(nodeType)) {
return this.nodeType;
}
return nodeType;
}
get isEmpty() {
return this.end - this.start === 0;
}
}
exports.ChunkRange = ChunkRange;
//# sourceMappingURL=chunk-range.js.map