Travis build: 1304
This commit is contained in:
78
README.md
78
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);
|
||||
|
||||
</details>
|
||||
|
||||
### _Uncategorized_
|
||||
|
||||
<details>
|
||||
<summary>View contents</summary>
|
||||
|
||||
* [`get`](#get)
|
||||
|
||||
</details>
|
||||
|
||||
---
|
||||
## 🔌 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);
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
</details>
|
||||
@ -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
@ -5,15 +5,15 @@ 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);
|
||||
```
|
||||
|
||||
```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
|
||||
```
|
||||
|
||||
@ -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']
|
||||
```
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user