Travis build: 1319
This commit is contained in:
23
README.md
23
README.md
@ -271,6 +271,7 @@ average(1, 2, 3);
|
|||||||
<details>
|
<details>
|
||||||
<summary>View contents</summary>
|
<summary>View contents</summary>
|
||||||
|
|
||||||
|
* [`defaults`](#defaults)
|
||||||
* [`equals`](#equals-)
|
* [`equals`](#equals-)
|
||||||
* [`forOwn`](#forown)
|
* [`forOwn`](#forown)
|
||||||
* [`forOwnRight`](#forownright)
|
* [`forOwnRight`](#forownright)
|
||||||
@ -4135,6 +4136,28 @@ UUIDGeneratorNode(); // '79c7c136-60ee-40a2-beb2-856f1feabefc'
|
|||||||
---
|
---
|
||||||
## 🗃️ Object
|
## 🗃️ Object
|
||||||
|
|
||||||
|
### defaults
|
||||||
|
|
||||||
|
Assigns default values for all properties in an object that are `undefined`.
|
||||||
|
|
||||||
|
Use `Object.assign()` to create a new empty object and copy the original one to maintain key order, use `Array.reverse()` and the spread operator `...` to combine the default values from left to right, finally use `obj` again to overwrite properties that originally had a value.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj);
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }); // { a: 1, b: 2 }
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### equals 
|
### equals 
|
||||||
|
|
||||||
Performs a deep comparison between two values to determine if they are equivalent.
|
Performs a deep comparison between two values to determine if they are equivalent.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -9,5 +9,5 @@ const defaults = (obj, ...defs) => Object.assign({}, obj, ...defs.reverse(), obj
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
defaults({ 'a': 1 }, { 'b': 2 }, { 'b': 6 }, { 'a': 3 }); // { a: 1, b: 2 }
|
defaults({ a: 1 }, { b: 2 }, { b: 6 }, { a: 3 }); // { a: 1, b: 2 }
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user