collect.js
Advanced tools
Comparing version 4.0.13 to 4.0.14
{ | ||
"name": "collect.js", | ||
"version": "4.0.13", | ||
"version": "4.0.14", | ||
"description": "Convenient and dependency free wrapper for working with arrays and objects.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
219
README.md
@@ -535,3 +535,3 @@ # <img src="https://raw.githubusercontent.com/ecrmnn/collect.js/master/collectjs.jpg" alt="collect.js"> | ||
//=> nickname: 'THE GOD', | ||
//=> position: 'STRIKER' | ||
//=> position: 'STRIKER', | ||
//=> } | ||
@@ -573,3 +573,3 @@ ``` | ||
//=> { name: 'iPhone 6S', brand: 'Apple' }, | ||
//=> { name: 'Galaxy S7', brand: 'Samsung' } | ||
//=> { name: 'Galaxy S7', brand: 'Samsung' }, | ||
//=> ] | ||
@@ -836,5 +836,5 @@ ``` | ||
const collection = collect({ | ||
serial: 'UX301', | ||
type: 'screen', | ||
year: 2009, | ||
serial: 'UX301', | ||
type: 'screen', | ||
year: 2009, | ||
}); | ||
@@ -850,3 +850,3 @@ | ||
// ['type' => 'screen', 'year' => 2009] | ||
// { type: 'screen', year: 2009 } | ||
``` | ||
@@ -1084,7 +1084,7 @@ | ||
'department': 'Sales', | ||
'email': 'john@example.com' | ||
'email': 'john@example.com', | ||
}, { | ||
'name': 'Jane', | ||
'department': 'Marketing', | ||
'email': 'jane@example.com' | ||
'email': 'jane@example.com', | ||
}]); | ||
@@ -1108,9 +1108,9 @@ | ||
const collection = collect([{ | ||
value: 10 | ||
value: 10, | ||
}, { | ||
value: -13 | ||
value: -13, | ||
}, { | ||
value: 12 | ||
value: 12, | ||
}, { | ||
unicorn: false | ||
unicorn: false, | ||
}]); | ||
@@ -1138,9 +1138,9 @@ | ||
collect([{ | ||
foo: 1 | ||
foo: 1, | ||
}, { | ||
foo: 1 | ||
foo: 1, | ||
}, { | ||
foo: 2 | ||
foo: 2, | ||
}, { | ||
foo: 4 | ||
foo: 4, | ||
}]).median('foo'); | ||
@@ -1156,3 +1156,3 @@ | ||
id: 1, | ||
price: 29 | ||
price: 29, | ||
}); | ||
@@ -1162,3 +1162,3 @@ | ||
price: 400, | ||
discount: false | ||
discount: false, | ||
}); | ||
@@ -1168,3 +1168,3 @@ | ||
//=> {id: 1, price: 400, discount: false} | ||
//=> { id: 1, price: 400, discount: false } | ||
``` | ||
@@ -1185,8 +1185,8 @@ If our collection is an array, the values will be appended to the end of the collection: | ||
```js | ||
const collection = collect[{ | ||
worth: 100 | ||
const collection = collect([{ | ||
worth: 100, | ||
}, { | ||
worth: 900 | ||
worth: 900, | ||
}, { | ||
worth: 79 | ||
worth: 79, | ||
}]); | ||
@@ -1214,9 +1214,9 @@ | ||
collect([{ | ||
foo: 1 | ||
foo: 1, | ||
}, { | ||
foo: 1 | ||
foo: 1, | ||
}, { | ||
foo: 2 | ||
foo: 2, | ||
}, { | ||
foo: 4 | ||
foo: 4, | ||
}]).mode('foo'); | ||
@@ -1253,3 +1253,3 @@ | ||
//=> {name: 'John Doe', email: 'john@doe.com'} | ||
//=> { name: 'John Doe', email: 'john@doe.com' } | ||
``` | ||
@@ -1312,6 +1312,6 @@ | ||
id: 78, | ||
name: 'Aeron' | ||
name: 'Aeron', | ||
}, { | ||
id: 79, | ||
name: 'Embody' | ||
name: 'Embody', | ||
}]); | ||
@@ -1330,6 +1330,6 @@ | ||
id: 78, | ||
name: 'Aeron' | ||
name: 'Aeron', | ||
}, { | ||
id: 79, | ||
name: 'Embody' | ||
name: 'Embody', | ||
}]); | ||
@@ -1343,3 +1343,3 @@ | ||
//=> 78: 'Aeron', | ||
//=> 79: 'Embody' | ||
//=> 79: 'Embody', | ||
//=> } | ||
@@ -1380,3 +1380,3 @@ ``` | ||
const collection = collect({ | ||
product: 'iPhone 6s' | ||
product: 'iPhone 6s', | ||
}); | ||
@@ -1390,3 +1390,3 @@ | ||
//=> brand: 'Apple', | ||
//=> product: 'iPhone 6s' | ||
//=> product: 'iPhone 6s', | ||
//=> } | ||
@@ -1400,3 +1400,3 @@ ``` | ||
firstname: 'Michael', | ||
lastname: 'Cera' | ||
lastname: 'Cera', | ||
}); | ||
@@ -1410,3 +1410,3 @@ | ||
//=> {firstname: 'Michael'} | ||
//=> { firstname: 'Michael' } | ||
``` | ||
@@ -1608,5 +1608,5 @@ | ||
const collection = collect([ | ||
{name: 'Desk', price: 200}, | ||
{name: 'Chair', price: 100}, | ||
{name: 'Bookcase', price: 150}, | ||
{ name: 'Desk', price: 200 }, | ||
{ name: 'Chair', price: 100 }, | ||
{ name: 'Bookcase', price: 150 }, | ||
]); | ||
@@ -1619,5 +1619,5 @@ | ||
//=> [ | ||
//=> {name: 'Chair', price: 100}, | ||
//=> {name: 'Bookcase', price: 150}, | ||
//=> {name: 'Desk', price: 200}, | ||
//=> { name: 'Chair', price: 100 }, | ||
//=> { name: 'Bookcase', price: 150 }, | ||
//=> { name: 'Desk', price: 200 }, | ||
//=> ] | ||
@@ -1629,5 +1629,5 @@ ``` | ||
const collection = collect([ | ||
{name: 'Desk', colors: ['Black', 'Mahogany']}, | ||
{name: 'Chair', colors: ['Black']}, | ||
{name: 'Bookcase', colors: ['Red', 'Beige', 'Brown']}, | ||
{ name: 'Desk', colors: ['Black', 'Mahogany'] }, | ||
{ name: 'Chair', colors: ['Black'] }, | ||
{ name: 'Bookcase', colors: ['Red', 'Beige', 'Brown'] }, | ||
]); | ||
@@ -1642,5 +1642,5 @@ | ||
//=> [ | ||
//=> {name: 'Chair', colors: ['Black']}, | ||
//=> {name: 'Desk', colors: ['Black', 'Mahogany']}, | ||
//=> {name: 'Bookcase', colors: ['Red', 'Beige', 'Brown']}, | ||
//=> { name: 'Chair', colors: ['Black'] }, | ||
//=> { name: 'Desk', colors: ['Black', 'Mahogany'] }, | ||
//=> { name: 'Bookcase', colors: ['Red', 'Beige', 'Brown'] }, | ||
//=> ] | ||
@@ -1718,4 +1718,4 @@ ``` | ||
const collection = collect([ | ||
{name: 'JavaScript: The Good Parts', pages: 176}, | ||
{name: 'JavaScript: The Definitive Guide', pages: 1096}, | ||
{ name: 'JavaScript: The Good Parts', pages: 176 }, | ||
{ name: 'JavaScript: The Definitive Guide', pages: 1096 }, | ||
]); | ||
@@ -1759,3 +1759,3 @@ | ||
```js | ||
const collect([2, 4, 3, 1, 5]) | ||
collect([2, 4, 3, 1, 5]) | ||
.sort() | ||
@@ -1801,4 +1801,4 @@ .tap(function (collection) { | ||
'Space X', | ||
'SolarCity' | ||
] | ||
'SolarCity', | ||
], | ||
}); | ||
@@ -1817,3 +1817,3 @@ | ||
name: 'Rayquaza', | ||
gender: 'NA' | ||
gender: 'NA', | ||
}); | ||
@@ -1847,3 +1847,3 @@ | ||
a: 'A', | ||
b: 'B' | ||
b: 'B', | ||
}); | ||
@@ -1854,3 +1854,3 @@ | ||
c: 'CCC', | ||
b: 'BBB' | ||
b: 'BBB', | ||
}); | ||
@@ -1863,3 +1863,3 @@ | ||
//=> b: 'B', | ||
//=> c: 'CCC' | ||
//=> c: 'CCC', | ||
//=> } | ||
@@ -1883,7 +1883,7 @@ ``` | ||
const collection = collect([ | ||
{name: 'iPhone 6', brand: 'Apple', type: 'phone'}, | ||
{name: 'iPhone 5', brand: 'Apple', type: 'phone'}, | ||
{name: 'Apple Watch', brand: 'Apple', type: 'watch'}, | ||
{name: 'Galaxy S6', brand: 'Samsung', type: 'phone'}, | ||
{name: 'Galaxy Gear', brand: 'Samsung', type: 'watch'} | ||
{ name: 'iPhone 6', brand: 'Apple', type: 'phone' }, | ||
{ name: 'iPhone 5', brand: 'Apple', type: 'phone' }, | ||
{ name: 'Apple Watch', brand: 'Apple', type: 'watch' }, | ||
{ name: 'Galaxy S6', brand: 'Samsung', type: 'phone' }, | ||
{ name: 'Galaxy Gear', brand: 'Samsung', type: 'watch' }, | ||
]); | ||
@@ -1896,4 +1896,4 @@ | ||
//=> [ | ||
//=> {name: 'iPhone 6', brand: 'Apple', type: 'phone'}, | ||
//=> {name: 'Galaxy S6', brand: 'Samsung', type: 'phone'}, | ||
//=> { name: 'iPhone 6', brand: 'Apple', type: 'phone' }, | ||
//=> { name: 'Galaxy S6', brand: 'Samsung', type: 'phone' }, | ||
//=> ] | ||
@@ -1905,7 +1905,7 @@ ``` | ||
const collection = collect([ | ||
{name: 'iPhone 6', brand: 'Apple', type: 'phone'}, | ||
{name: 'iPhone 5', brand: 'Apple', type: 'phone'}, | ||
{name: 'Apple Watch', brand: 'Apple', type: 'watch'}, | ||
{name: 'Galaxy S6', brand: 'Samsung', type: 'phone'}, | ||
{name: 'Galaxy Gear', brand: 'Samsung', type: 'watch'} | ||
{ name: 'iPhone 6', brand: 'Apple', type: 'phone' }, | ||
{ name: 'iPhone 5', brand: 'Apple', type: 'phone' }, | ||
{ name: 'Apple Watch', brand: 'Apple', type: 'watch' }, | ||
{ name: 'Galaxy S6', brand: 'Samsung', type: 'phone' }, | ||
{ name: 'Galaxy Gear', brand: 'Samsung', type: 'watch' }, | ||
]); | ||
@@ -1920,6 +1920,6 @@ | ||
//=> [ | ||
//=> {name: 'iPhone 6', brand: 'Apple', type: 'phone'}, | ||
//=> {name: 'Apple Watch', brand: 'Apple', type: 'watch'}, | ||
//=> {name: 'Galaxy S6', brand: 'Samsung', type: 'phone'}, | ||
//=> {name: 'Galaxy Gear', brand: 'Samsung', type: 'watch'}, | ||
//=> { name: 'iPhone 6', brand: 'Apple', type: 'phone' }, | ||
//=> { name: 'Apple Watch', brand: 'Apple', type: 'watch' }, | ||
//=> { name: 'Galaxy S6', brand: 'Samsung', type: 'phone' }, | ||
//=> { name: 'Galaxy Gear', brand: 'Samsung', type: 'watch' }, | ||
//=> ] | ||
@@ -1933,5 +1933,3 @@ ``` | ||
collection.unless(false, function (collection) { | ||
return collection.push(4); | ||
}); | ||
collection.unless(false, collection => collection.push(4)); | ||
@@ -1956,3 +1954,8 @@ collection.all(); | ||
```js | ||
const collection = collect({a: 'xoxo', b: 'abab', 'c': '1337', 1337: 12}); | ||
const collection = collect({ | ||
a: 'xoxo', | ||
b: 'abab', | ||
'c': '1337', | ||
1337: 12, | ||
}); | ||
@@ -1971,5 +1974,3 @@ const values = collection.values(); | ||
collection.when(true, function (collection) { | ||
return collection.push(4); | ||
}); | ||
collection.when(true, collection => collection.push(4)); | ||
@@ -1985,6 +1986,6 @@ collection.all(); | ||
const collection = collect([ | ||
{product: 'Desk', price: 200}, | ||
{product: 'Chair', price: 100}, | ||
{product: 'Bookcase', price: 150}, | ||
{product: 'Door', price: 100}, | ||
{ product: 'Desk', price: 200 }, | ||
{ product: 'Chair', price: 100 }, | ||
{ product: 'Bookcase', price: 150 }, | ||
{ product: 'Door', price: 100 }, | ||
]); | ||
@@ -1997,8 +1998,10 @@ | ||
//=> [ | ||
//=> {product: 'Chair', price: 100}, | ||
//=> {product: 'Door', price: 100} | ||
//=> { product: 'Chair', price: 100 }, | ||
//=> { product: 'Door', price: 100 }, | ||
//=> ] | ||
``` | ||
> When working with nested objects ``where()`` method allows dot notated keys. E.g. ``where('product.category', 'office-supplies')`` | ||
The where method also allows for custom comparisons: | ||
**Non-identity / strict inequality ``(!==)``** | ||
@@ -2011,4 +2014,4 @@ ```js | ||
//=> [ | ||
//=> {product: 'Desk', price: 200}, | ||
//=> {product: 'Bookcase', price: 150} | ||
//=> { product: 'Desk', price: 200 }, | ||
//=> { product: 'Bookcase', price: 150 }, | ||
//=> ] | ||
@@ -2031,4 +2034,4 @@ ``` | ||
//=> [ | ||
//=> {product: 'Chair', price: 100}, | ||
//=> {product: 'Door', price: 100} | ||
//=> { product: 'Chair', price: 100 }, | ||
//=> { product: 'Door', price: 100 }, | ||
//=> ] | ||
@@ -2044,4 +2047,4 @@ ``` | ||
//=> [ | ||
//=> {product: 'Desk', price: 200}, | ||
//=> {product: 'Bookcase', price: 150} | ||
//=> { product: 'Desk', price: 200} , | ||
//=> { product: 'Bookcase', price: 150 }, | ||
//=> ] | ||
@@ -2056,4 +2059,4 @@ ``` | ||
//=> [ | ||
//=> {product: 'Desk', price: 200}, | ||
//=> {product: 'Bookcase', price: 150} | ||
//=> { product: 'Desk', price: 200} , | ||
//=> { product: 'Bookcase', price: 150 }, | ||
//=> ] | ||
@@ -2066,6 +2069,6 @@ ``` | ||
const collection = collect([ | ||
{product: 'Desk', price: 200}, | ||
{product: 'Chair', price: 100}, | ||
{product: 'Bookcase', price: 150}, | ||
{product: 'Door', price: 100}, | ||
{ product: 'Desk', price: 200 }, | ||
{ product: 'Chair', price: 100 }, | ||
{ product: 'Bookcase', price: 150 }, | ||
{ product: 'Door', price: 100 }, | ||
]); | ||
@@ -2078,8 +2081,11 @@ | ||
//=> [ | ||
//=> {product: 'Chair', price: 100}, | ||
//=> {product: 'Bookcase', price: 150}, | ||
//=> {product: 'Door', price: 100}, | ||
//=> { product: 'Chair', price: 100 }, | ||
//=> { product: 'Bookcase', price: 150 }, | ||
//=> { product: 'Door', price: 100 }, | ||
//=> ] | ||
``` | ||
> When working with nested objects ``whereIn()`` method allows dot notated keys. E.g. ``whereIn('product.categories', | ||
['office-supplies', 'furniture'])`` | ||
#### ``whereNotIn()`` | ||
@@ -2092,3 +2098,3 @@ The whereNotIn method filters the collection by a given key / value not contained within the given array: | ||
{ product: 'Bookcase', price: 150 }, | ||
{ product: 'Door', price: 100 } | ||
{ product: 'Door', price: 100 }, | ||
]); | ||
@@ -2098,10 +2104,13 @@ | ||
filtered.all(); | ||
filtered.all( ); | ||
//=> [ | ||
//=> { product: 'Chair', price: 100 }, | ||
//=> { product: 'Door', price: 100 } | ||
//=> { product: 'Door', price: 100 }, | ||
//=> ] | ||
``` | ||
> When working with nested objects ``whereNotIn()`` method allows dot notated keys. E.g. ``whereNotIn('product | ||
.categories', ['office-supplies', 'furniture'])`` | ||
#### ``wrap()`` | ||
@@ -2108,0 +2117,0 @@ The wrap method will wrap the given value in a collection: |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
371074
2095