UNPKG

@tidyjs/tidy

Version:

Tidy up your data with JavaScript, inspired by dplyr and the tidyverse

23 lines (19 loc) 747 B
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function roll(width, rollFn, options) { const {partial = false, align = "right"} = options != null ? options : {}; const halfWidth = Math.floor(width / 2); return (items) => { return items.map((_, i) => { const endIndex = align === "right" ? i : align === "center" ? i + halfWidth : i + width - 1; if (!partial && (endIndex - width + 1 < 0 || endIndex >= items.length)) { return void 0; } const startIndex = Math.max(0, endIndex - width + 1); const itemsInWindow = items.slice(startIndex, endIndex + 1); return rollFn(itemsInWindow, endIndex); }); }; } exports.roll = roll; //# sourceMappingURL=roll.js.map