Comparing version 0.17.0 to 0.18.0
@@ -5,2 +5,6 @@ # Change Log | ||
## [0.18.0] - 2015-05-09 | ||
### Added | ||
- [`indexBy`](https://github.com/tjmehta/101#indexBy) module | ||
## [0.17.0] - 2015-05-07 | ||
@@ -7,0 +11,0 @@ ### Added |
{ | ||
"name": "101", | ||
"version": "0.17.0", | ||
"version": "0.18.0", | ||
"description": "common javascript utils that can be required selectively that assume es5+", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -338,6 +338,18 @@ ![101](http://i.imgur.com/MFrmMt6.png) | ||
hasKeypaths(obj, ['foo.bar'], false); // true, uses [hasOwnProperty vs in](http://stackoverflow.com/questions/13632999/if-key-in-object-or-ifobject-hasownpropertykey) | ||
// use it with find, findIndex, or filter! | ||
var arr = [obj, { b: 1 }, { c: 1 }]; | ||
find(arr, hasProps({ 'foo.bar.qux':1 })); // { foo: { bar: { qux: 1 } } } | ||
find(arr, hasProps(['foo.bar.qux'])); // { foo: { bar: { qux: 1 } } } | ||
find(arr, hasKeypaths({ 'foo.bar.qux':1 })); // { foo: { bar: { qux: 1 } } } | ||
find(arr, hasKeypaths(['foo.bar.qux'])); // { foo: { bar: { qux: 1 } } } | ||
// use it to verify options object has required properties | ||
var opts = { | ||
host: 'localhost', | ||
port: '3333', | ||
user: { | ||
id: 5 | ||
} | ||
}; | ||
hasKeypaths(opts, ['host', 'port', 'user.id']); // true | ||
``` | ||
@@ -373,2 +385,17 @@ | ||
## indexBy | ||
Hashes an array of objects based on the value of a provided common key. | ||
Works nicely with `pluck` and `reduce`. | ||
```js | ||
var arr = [ | ||
{foo: 'bar'}, | ||
{foo: 'qux'} | ||
]; | ||
indexBy(arr, 'foo') // {bar: {foo: 'bar'}, qux: {foo: 'qux'}} | ||
// always provide initial value when using with reduce! | ||
arr.reduce(indexBy(pluck('foo')), {}) // {bar: {foo: 'bar'}, qux: {foo: 'qux'}} | ||
``` | ||
## instanceOf | ||
@@ -375,0 +402,0 @@ |
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
51889
48
1089
742