my-idlers/node_modules/collect.js/dist/methods/forPage.js

17 lines
421 B
JavaScript
Raw Normal View History

'use strict';
module.exports = function forPage(page, chunk) {
var _this = this;
var collection = {};
if (Array.isArray(this.items)) {
collection = this.items.slice(page * chunk - chunk, page * chunk);
} else {
Object.keys(this.items).slice(page * chunk - chunk, page * chunk).forEach(function (key) {
collection[key] = _this.items[key];
});
}
return new this.constructor(collection);
};