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

28 lines
562 B
JavaScript
Vendored

'use strict';
var _require = require('../helpers/is'),
isFunction = _require.isFunction;
module.exports = function last(fn, defaultValue) {
var items = this.items;
if (isFunction(fn)) {
items = this.filter(fn).all();
}
if (Array.isArray(items) && !items.length || !Object.keys(items).length) {
if (isFunction(defaultValue)) {
return defaultValue();
}
return defaultValue;
}
if (Array.isArray(items)) {
return items[items.length - 1];
}
var keys = Object.keys(items);
return items[keys[keys.length - 1]];
};