UNPKG

1.06 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6exports.wrapString = void 0;
7const slice_ansi_1 = __importDefault(require("slice-ansi"));
8const string_width_1 = __importDefault(require("string-width"));
9/**
10 * Creates an array of strings split into groups the length of size.
11 * This function works with strings that contain ASCII characters.
12 *
13 * wrapText is different from would-be "chunk" implementation
14 * in that whitespace characters that occur on a chunk size limit are trimmed.
15 *
16 */
17const wrapString = (subject, size) => {
18 let subjectSlice = subject;
19 const chunks = [];
20 do {
21 chunks.push((0, slice_ansi_1.default)(subjectSlice, 0, size));
22 subjectSlice = (0, slice_ansi_1.default)(subjectSlice, size).trim();
23 } while ((0, string_width_1.default)(subjectSlice));
24 return chunks;
25};
26exports.wrapString = wrapString;
27//# sourceMappingURL=wrapString.js.map
\No newline at end of file