minimal adjustments
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / dist / wrapString.js.flow
1 import slice from 'slice-ansi';
2 import stringWidth from 'string-width';
3
4 /**
5  * Creates an array of strings split into groups the length of size.
6  * This function works with strings that contain ASCII characters.
7  *
8  * wrapText is different from would-be "chunk" implementation
9  * in that whitespace characters that occur on a chunk size limit are trimmed.
10  *
11  * @param {string} subject
12  * @param {number} size
13  * @returns {Array}
14  */
15 export default (subject, size) => {
16   let subjectSlice;
17
18   subjectSlice = subject;
19
20   const chunks = [];
21
22   do {
23     chunks.push(slice(subjectSlice, 0, size));
24
25     subjectSlice = slice(subjectSlice, size).trim();
26   } while (stringWidth(subjectSlice));
27
28   return chunks;
29 };