Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// https://regex101.com/r/gY5kZ1/1
const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
do {
let chunk;
chunk = subject.match(re);
if (chunk) {
chunk = chunk[0];
subject = slice(subject, stringWidth(chunk));
chunk = chunk.trim();
} else {
chunk = slice(subject, 0, size);
subject = slice(subject, size);
}
chunks.push(chunk);
} while (stringWidth(subject));
return chunks;
};
for (let line of lines) {
const currentLine = output[y + offsetY];
// Line can be missing if `text` is taller than height of pre-initialized `this.output`
if (!currentLine) {
continue;
}
const length = stringLength(line);
for (const transformer of transformers) {
line = transformer(line);
}
output[y + offsetY] = sliceAnsi(currentLine, 0, x) + line + sliceAnsi(currentLine, x + length);
offsetY++;
}
}
const generatedOutput = output
.map(line => line.trimRight())
.join('\n');
return {
output: generatedOutput,
height: output.length
};
}
}
let offsetY = 0;
for (let line of lines) {
const length = stringLength(line);
const currentLine = this.output[y + offsetY];
// Line can be missing if `text` is taller than height of pre-initialized `this.output`
if (!currentLine) {
continue;
}
for (const transformer of transformers) {
line = transformer(line);
}
this.output[y + offsetY] = sliceAnsi(currentLine, 0, x) + line + sliceAnsi(currentLine, x + length);
offsetY++;
}
}
function truncate(message) {
return sliceANSI(message, 0, windowSize.width - 3);
}
}
export default (subject, size) => {
let subjectSlice;
subjectSlice = subject;
const chunks = [];
do {
chunks.push(slice(subjectSlice, 0, size));
subjectSlice = slice(subjectSlice, size).trim();
} while (stringWidth(subjectSlice));
return chunks;
};
const slice = (start: number, end?: number) =>
sliceAnsi(highlightedLine, start, end)
const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))');
do {
let chunk;
chunk = subject.match(re);
if (chunk) {
chunk = chunk[0];
subject = slice(subject, stringWidth(chunk));
chunk = chunk.trim();
} else {
chunk = slice(subject, 0, size);
subject = slice(subject, size);
}
chunks.push(chunk);
} while (stringWidth(subject));
return chunks;
};