@marp-team/marpit
Version:
The skinny framework for creating slide deck from Markdown
41 lines (35 loc) • 893 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
/** @module */
/**
* Split array into multiple arrays by specified condition.
*
* @alias module:helpers/split
* @param {Array} arr Target array.
* @param {splitCallback} func Callback to split array.
* @param {boolean} [keepSplitedValue=false] Keep splited value. The split
* point is before the matched value.
* @returns {Array[]} Splited array.
*/
function split(arr, func, keepSplitedValue = false) {
const ret = [[]];
for (const value of arr) {
/**
* Return true at the split point.
*
* @callback splitCallback
* @param {*} value
*/
if (func(value)) {
ret.push(keepSplitedValue ? [value] : []);
} else {
ret[ret.length - 1].push(value);
}
}
return ret;
}
var _default = split;
exports.default = _default;