my-idlers/node_modules/collect.js/dist/methods/pad.js
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

35 lines
678 B
JavaScript
Vendored

'use strict';
var clone = require('../helpers/clone');
module.exports = function pad(size, value) {
var abs = Math.abs(size);
var count = this.count();
if (abs <= count) {
return this;
}
var diff = abs - count;
var items = clone(this.items);
var isArray = Array.isArray(this.items);
var prepend = size < 0;
for (var iterator = 0; iterator < diff;) {
if (!isArray) {
if (items[iterator] !== undefined) {
diff += 1;
} else {
items[iterator] = value;
}
} else if (prepend) {
items.unshift(value);
} else {
items.push(value);
}
iterator += 1;
}
return new this.constructor(items);
};