From a6cced8f05be680b5f18d5c46de6049cdbd286bb Mon Sep 17 00:00:00 2001
From: 30secondsofcode <30secondsofcode@gmail.com>
Date: Thu, 18 Jan 2018 15:42:28 +0000
Subject: [PATCH] Travis build: 1304
---
README.md | 78 +++++++++++++++++++++++++++---------------------
docs/index.html | 19 +++++++-----
snippets/flip.md | 16 +++++-----
snippets/get.md | 2 +-
tag_database | 2 +-
5 files changed, 66 insertions(+), 51 deletions(-)
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.
const call = (key, ...args) => context => context[key](...args);
+ }
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.
const call = (key, ...args) => context => context[key](...args);
Promise.resolve([1, 2, 3])
.then(call('map', x => 2 * x))
.then(console.log);
@@ -1016,11 +1016,6 @@ Foo.prototypeShow examplesconst users = [{ name: 'fred', age: 48 }, { name: 'barney', age: 36 }, { name: 'fred', age: 40 }];
orderBy(users, ['name', 'age'], ['asc', 'desc']);
orderBy(users, ['name', 'age']);
-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.
const select = (from, ...selectors) =>
- [...selectors].map(s => s.split('.').reduce((prev, cur) => prev && prev[cur], from));
-const obj = { selector: { to: { val: 'val to select' } } };
-select(obj, 'selector.to.val');
-select(obj, 'selector.to.val', 'selector.to');
shallowClone
Creates a shallow clone of an object.
Use Object.assign() and an empty object ({}) to create a shallow clone of the original.
const shallowClone = obj => Object.assign({}, obj);
const a = { x: true, y: 1 };
const b = shallowClone(a);
@@ -1443,4 +1438,14 @@ Logs: {
yesNo('yes');
yesNo('No');
yesNo('Foo', true);
-