@intlayer/chokidar
Version:
Uses chokidar to scan and build Intlayer declaration files into dictionaries based on Intlayer configuration.
35 lines (33 loc) • 1.57 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_utils_splitTextByLine = require('./splitTextByLine.cjs');
//#region src/utils/getChunk.ts
const getChunk = (text, options = {}) => {
const { lineStart, lineLength, charStart, charLength } = options;
if (lineStart === void 0 && lineLength === void 0 && charStart === void 0 && charLength === void 0) return text;
const lines = require_utils_splitTextByLine.splitTextByLines(text);
const getCharIndexOfLineStart = (lineNumber) => {
if (lineNumber <= 0) return 0;
let idx = 0;
for (let i = 0; i < Math.min(lineNumber, lines.length); i++) idx += lines[i].length;
return idx;
};
const getCharIndexOfLineEnd = (lineNumber) => {
if (lineNumber >= lines.length) return text.length;
const line = lines[lineNumber];
return getCharIndexOfLineStart(lineNumber) + line.length;
};
let effectiveStart = 0;
let effectiveEnd = text.length;
if (lineStart !== void 0) effectiveStart = Math.max(effectiveStart, getCharIndexOfLineStart(lineStart));
if (charStart !== void 0) effectiveStart = Math.max(effectiveStart, charStart);
if (lineLength !== void 0) {
const endLine = (lineStart ?? 0) + lineLength - 1;
effectiveEnd = Math.min(effectiveEnd, getCharIndexOfLineEnd(endLine));
}
if (charLength !== void 0) effectiveEnd = Math.min(effectiveEnd, (charStart ?? effectiveStart) + charLength);
if (effectiveStart >= effectiveEnd) return "";
return text.slice(effectiveStart, effectiveEnd);
};
//#endregion
exports.getChunk = getChunk;
//# sourceMappingURL=getChunk.cjs.map