Source

string/parseLinesToChunks.js

"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Parse lines of text to chunks of messages according to the max length of each chunk
 * @category string
 * @module parseLinesToChunks
 */
var parseLinesToChunks = function (lines, maxLength) { return lines.reduce(function (chunks, line) {
    var _a;
    var rest = __spreadArray([], chunks, true);
    var chunk = (_a = rest.pop()) !== null && _a !== void 0 ? _a : '';
    var testChunk = [chunk, line].join('\n');
    if (testChunk.length > maxLength)
        return __spreadArray(__spreadArray([], rest, true), [chunk, line], false);
    return __spreadArray(__spreadArray([], rest, true), [testChunk], false);
}, []); };
exports.default = parseLinesToChunks;