diff --git a/README.md b/README.md
index dc1bd4f18..be766e7a6 100644
--- a/README.md
+++ b/README.md
@@ -283,7 +283,6 @@ average(1, 2, 3);
* [`objectFromPairs`](#objectfrompairs)
* [`objectToPairs`](#objecttopairs)
* [`orderBy`](#orderby)
-* [`select`](#select)
* [`shallowClone`](#shallowclone)
* [`size`](#size)
* [`transform`](#transform)
@@ -372,6 +371,15 @@ average(1, 2, 3);
+### _Uncategorized_
+
+
+View contents
+
+* [`get`](#get)
+
+
+
---
## 🔌 Adapter
@@ -436,20 +444,20 @@ Flip takes a function as an argument, then makes the first argument the last.
Return a closure that takes variadic inputs, and splices the last argument to make it the first argument before applying the rest.
```js
-const flip = fn => (first, ...rest) => fn(...rest, first);
+const flip = fn => (first, ...rest) => fn(...rest, first);
```
Examples
```js
-let a = { name: 'John Smith' };
-let b = {};
-const mergeFrom = flip(Object.assign);
-let mergePerson = mergeFrom.bind(null, a);
-mergePerson(b); // == b
-b = {};
-Object.assign(b, a); // == b
+let a = { name: 'John Smith' };
+let b = {};
+const mergeFrom = flip(Object.assign);
+let mergePerson = mergeFrom.bind(null, a);
+mergePerson(b); // == b
+b = {};
+Object.assign(b, a); // == b
```
@@ -4485,31 +4493,6 @@ orderBy(users, ['name', 'age']); // [{name: 'barney', age: 36}, {name: 'fred', a
[⬆ Back to top](#table-of-contents)
-### select
-
-Retrieve a set of properties indicated by the given selectors from an object.
-
-Use `Array.map()` for each selector, `String.split('.')` to split each selector and `Array.reduce()` to get the value indicated by it.
-
-```js
-const select = (from, ...selectors) =>
- [...selectors].map(s => s.split('.').reduce((prev, cur) => prev && prev[cur], from));
-```
-
-
-Examples
-
-```js
-const obj = { selector: { to: { val: 'val to select' } } };
-select(obj, 'selector.to.val'); // ['val to select']
-select(obj, 'selector.to.val', 'selector.to'); // ['val to select', { val: 'val to select' }]
-```
-
-
-
- [⬆ Back to top](#table-of-contents)
-
-
### shallowClone
Creates a shallow clone of an object.
@@ -6200,6 +6183,33 @@ yesNo('Foo', true); // true
[⬆ Back to top](#table-of-contents)
+---
+ ## _Uncategorized_
+
+### get
+
+Retrieve a set of properties indicated by the given selectors from an object.
+
+Use `Array.map()` for each selector, `String.replace()` to replace square brackets with dots, `String.split('.')` to split each selector, `Array.filter()` to remove empty values and `Array.reduce()` to get the value indicated by it.
+
+```js
+const get = (from, ...selectors) =>
+ [...selectors].map(s =>
+ s
+ .replace(/\[([^\[\]]*)\]/g, '.$1.')
+ .split('.')
+ .filter(t => t !== '')
+ .reduce((prev, cur) => prev && prev[cur], from)
+ );
+```
+
+```js
+const obj = { selector: { to: { val: 'val to select' } }, target: [1, 2, { a: 'test' }] };
+get(obj, 'selector.to.val', 'target[0]', 'target[2].a'); // ['val to select', 1, 'test']
+```
+
+ [⬆ back to top](#table-of-contents)
+
## Collaborators
diff --git a/docs/index.html b/docs/index.html
index 89cf4a175..6e3b2d4bc 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -50,7 +50,7 @@
scrollToTop();
}
}, false);
- }
30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.
Adapter
call
Given a key and a set of arguments, call them when given a context. Primarily useful in composition.
Use a closure to call a stored key with stored arguments.