Travis build: 1304

This commit is contained in:
30secondsofcode
2018-01-18 15:42:28 +00:00
parent a39d7c88f4
commit a6cced8f05
5 changed files with 66 additions and 51 deletions

View File

@ -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);
</details>
### _Uncategorized_
<details>
<summary>View contents</summary>
* [`get`](#get)
</details>
---
## 🔌 Adapter
@ -4485,31 +4493,6 @@ orderBy(users, ['name', 'age']); // [{name: 'barney', age: 36}, {name: 'fred', a
<br>[⬆ 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));
```
<details>
<summary>Examples</summary>
```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' }]
```
</details>
<br>[⬆ Back to top](#table-of-contents)
### shallowClone
Creates a shallow clone of an object.
@ -6200,6 +6183,33 @@ yesNo('Foo', true); // true
<br>[⬆ 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']
```
<br>[⬆ back to top](#table-of-contents)
## Collaborators

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,6 @@ const get = (from, ...selectors) =>
```
```js
const obj = { selector: { to: { val: 'val to select' } }, target: [1, 2, {a: 'test'}] };
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']
```

View File

@ -57,6 +57,7 @@ functionName:function,utility
functions:object,function
gcd:math,recursion
geometricProgression:math
get:uncategorized
getDaysDiffBetweenDates:date
getScrollPosition:browser
getStyle:browser,css
@ -164,7 +165,6 @@ sample:array,random
sampleSize:array,random
scrollToTop:browser
sdbm:math,utility
select:object
serializeCookie:utility,string
setStyle:browser
shallowClone:object