shift()
shift()
on an empty collection returns null in all casessortKeysDesc()
min()
max()
sortBy()
null
and undefined
will be sorted last, like normal .sort()
values()
4.13.0
. Values method are no longer recursive.where()
values()
collect()
collect('')
// Before 4.12.0
collect('').isEmpty();
//=> true
// After 4.12.0
collect('').isEmpty();
//=> false
concat()
random()
random()
and random(1)
would return an array, while passing an integer >1 would return a collection object.random(1)
now returns a collection objectrandom()
according to https://github.com/ecrmnn/collect.js/issues/202whenEmpty()
methodwhenNotEmpty()
methodunlessEmpty()
methodunlessNotEmpty()
methodflatMap()
flatMap()
according to https://github.com/ecrmnn/collect.js/issues/195chunk()
count()
dump()
flatMap()
has()
keys()
groupBy()
partition()
pluck()
split()
toArray()
toJson()
wrap()
Skipped Node 4 support
chunk()
collect.js
should give the same result as Laravel Collections.combine()
count()
dump()
this
) instead of only the items (this.items
).const collection = collect([
{ product: 'Desk', manufacturer: 'IKEA' },
{ product: 'Chair', manufacturer: 'Herman Miller' },
{ product: 'Bookcase', manufacturer: 'IKEA' },
{ product: 'Door' },
]);
collection.pluck('product', 'manufacturer').dump();
// Prior to 4.0.0
//=> {
//=> IKEA: 'Bookcase',
//=> 'Herman Miller': 'Chair',
//=> '': 'Door'
//=> }
// After 4.0.0
//=> Collection {
//=> items: {
//=> IKEA: 'Bookcase',
//=> 'Herman Miller': 'Chair',
//=> '': 'Door'
//=> }
//=> }
except()
first()
const collection = collect({
name: 'Sadio Mané',
club: 'Liverpool FC',
});
collection.first();
//=> Sadio Mané
flatMap()
flip()
forget()
forPage()
groupBy()
undefined
.collect.js
should give the same result as Laravel Collections.
has()
collect.js
should give the same result as Laravel Collections.// Previously this would return true. It now returns false.
const collection = collect([{
animal: 'unicorn',
ability: 'magical'
}, {
animal: 'pig',
ability: 'filthy'
}]);
collection.has('ability');
//=> true (Prior to 4.0.0)
//=> false (After 4.0.0)
keyBy()
undefined
when passed an invalid keykeys()
Number
.const collection = collect([{
name: 'Sadio Mané',
}, {
name: 'Roberto Firmino',
}]);
const keys = collection.keys();
// Prior to 4.0.0
//=> ['name', 'name']
// After 4.0.0
//=> [0, 1]
last()
const collection = collect({
name: 'Sadio Mané',
club: 'Liverpool FC',
});
collection.last();
//=> Liverpool FC
merge()
only()
partition()
pluck()
null
as the value instead of undefined
null
when an item does not contain the specified key.const collection = collect([
{ product: 'Desk', manufacturer: 'IKEA' },
{ product: 'Chair', manufacturer: 'Herman Miller' },
{ product: 'Bookcase', manufacturer: 'IKEA' },
{ product: 'Door' },
]);
const pluck = collection.pluck('non-existing-key');
pluck.all();
//=> [null, null, null, null]
const manufacturers = collection.pluck('manufacturer');
manufacturers.all();
//=> ['IKEA', 'Herman Miller', 'IKEA', null]
undefined
.const collection = collect([
{ product: 'Desk', manufacturer: 'IKEA' },
{ product: 'Chair', manufacturer: 'Herman Miller' },
{ product: 'Bookcase', manufacturer: 'IKEA' },
{ product: 'Door' },
]);
const pluck = collection.pluck('product', 'manufacturer');
pluck.all();
//=> {
//=> IKEA: 'Bookcase',
//=> 'Herman Miller': 'Chair',
//=> '': 'Door',
//=> }
pop()
push()
collection.push(...values)
random()
shift()
shuffle()
split()
const collection = collect([1, 2, 3, 4, 5]);
collection.split(2).dump();
// Prior to 4.0.0
//=> [
//=> [1, 2, 3],
//=> [4, 5],
//=> ]
// After 4.0.0
//=> Collection {
//=> items: {
//=> Collection {
//=> items: [1, 2, 3]
//=> },
//=> Collection {
//=> items: [4, 5]
//=> },
//=> }
//=> }
take()
toArray()
toArray()
methodtoJson()
toArray()
methodwrap()
CHANGELOG.md