UNPKG

1.12 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = void 0;
7
8var _sliceAnsi = _interopRequireDefault(require("slice-ansi"));
9
10var _stringWidth = _interopRequireDefault(require("string-width"));
11
12function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
14/**
15 * Creates an array of strings split into groups the length of size.
16 * This function works with strings that contain ASCII characters.
17 *
18 * wrapText is different from would-be "chunk" implementation
19 * in that whitespace characters that occur on a chunk size limit are trimmed.
20 *
21 * @param {string} subject
22 * @param {number} size
23 * @returns {Array}
24 */
25const wrapString = (subject, size) => {
26 let subjectSlice;
27 subjectSlice = subject;
28 const chunks = [];
29
30 do {
31 chunks.push((0, _sliceAnsi.default)(subjectSlice, 0, size));
32 subjectSlice = (0, _sliceAnsi.default)(subjectSlice, size).trim();
33 } while ((0, _stringWidth.default)(subjectSlice));
34
35 return chunks;
36};
37
38var _default = wrapString;
39exports.default = _default;
40//# sourceMappingURL=wrapString.js.map
\No newline at end of file