2 var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
5 Object.defineProperty(exports, "__esModule", { value: true });
6 exports.wrapWord = void 0;
7 const slice_ansi_1 = __importDefault(require("slice-ansi"));
8 const strip_ansi_1 = __importDefault(require("strip-ansi"));
9 const calculateStringLengths = (input, size) => {
10 let subject = (0, strip_ansi_1.default)(input);
12 // https://regex101.com/r/gY5kZ1/1
13 const re = new RegExp('(^.{1,' + String(Math.max(size, 1)) + '}(\\s+|$))|(^.{1,' + String(Math.max(2, size - 1) - 1) + '}(\\\\|/|_|\\.|,|;|-))');
16 const match = re.exec(subject);
19 subject = subject.slice(chunk.length);
20 const trimmedLength = chunk.trim().length;
21 const offset = chunk.length - trimmedLength;
22 chunks.push([trimmedLength, offset]);
25 chunk = subject.slice(0, size);
26 subject = subject.slice(size);
27 chunks.push([chunk.length, 0]);
29 } while (subject.length);
32 const wrapWord = (input, size) => {
35 calculateStringLengths(input, Math.max(size, 1)).forEach(([length, offset]) => {
36 result.push((0, slice_ansi_1.default)(input, startIndex, startIndex + length));
37 startIndex += length + offset;
41 exports.wrapWord = wrapWord;
42 //# sourceMappingURL=wrapWord.js.map