index-array-by
Advanced tools
Comparing version 1.2.0 to 1.2.1
{ | ||
"name": "index-array-by", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A utility function to index arrays by any criteria", | ||
@@ -5,0 +5,0 @@ "main": "dist/index-array-by.min.js", |
@@ -35,5 +35,5 @@ # index-array-by | ||
Use `indexBy` to index it by a given attribute (string type `keyAccessor`) or any other custom criteria (function type `keyAccessor`). You can also pass an array of `keyAccessors` to retrieve a nested object recursively indexed by the multiple keys. | ||
Use the third parameter (`multiItem`) to indicate whether each key should point to a single item (unadvised if the keys are not unique) or an array of multiple items (default behavior). This parameter also accepts a transformation function with the method to reduce multiple items into a single one. | ||
A fourth optional parameter (`flattenKeys`) (default: `false`) allows you to receive a flat array structure instead of the default nested format, with each item formatted as `{ keys: [<ordered unique keys for the item>], vals: <single or multiple item> }`. | ||
Use the third parameter (`multiItem`) to indicate whether each key should point to a single item (unadvised if the keys are not unique) or an array of multiple items (default behavior). | ||
``` | ||
@@ -97,2 +97,5 @@ indexBy(people, 'surname', false); | ||
The `multiItem` parameter also accepts a transformation function with the method to reduce multiple items into a single one. In this case, it's keeping only the max age. | ||
``` | ||
@@ -109,2 +112,5 @@ indexBy(people, 'name', items => Math.max(...items.map(item => item.age))); | ||
A fourth optional parameter (`flattenKeys`) (default: `false`) allows you to receive a flat array structure instead of the default nested format, with each item formatted as `{ keys: [<ordered unique keys for the item>], vals: <single or multiple item> }`. | ||
``` | ||
@@ -111,0 +117,0 @@ indexBy(people, ['name', 'surname'], true, true)); |
Sorry, the diff of this file is not supported yet
134388
123