https://github.com/fabioricali/defaulty
Copies deep missing properties to the target object
https://github.com/fabioricali/defaulty
configuration defaults extend javascript merge-object options
Last synced: about 1 year ago
JSON representation
Copies deep missing properties to the target object
- Host: GitHub
- URL: https://github.com/fabioricali/defaulty
- Owner: fabioricali
- Created: 2017-08-11T21:10:53.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-24T16:11:52.000Z (over 8 years ago)
- Last Synced: 2024-12-14T11:42:47.392Z (over 1 year ago)
- Topics: configuration, defaults, extend, javascript, merge-object, options
- Language: JavaScript
- Size: 49.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
## Installation
### Node.js
```
npm install defaulty --save
```
## Example
```javascript
const defaulty = require('defaulty');
const defaultObj = {a: 1, b: 2, c: 3, d: {a: 5, b: 2}};
let targetObj = {a: 4, b: 5, d: {a: 1}};
defaulty(targetObj, defaultObj);
console.log(targetObj); //=> {a: 4, b: 5, c: 3, d: {a: 1, b: 2}};
```
### Exclude default properties
```javascript
const defaultObj = {a: 1, b: 2, c: 3, d: {a: 5, b: 2}, x: 1, y: 2};
let targetObj = {a: 4, b: 5, d: {a: 1}};
defaulty(targetObj, defaultObj, ['x', 'y']);
console.log(targetObj); //=> {a: 4, b: 5, c: 3, d: {a: 1, b: 2}};
```
### Copy target object
```javascript
const defaultObj = {a: 1, b: 2, c: 3, d: {a: 5, b: 2}};
const targetObj = {a: 4, b: 5, d: {a: 1}};
const newTargetObject = defaulty.copy(targetObj, defaultObj);
console.log(newTargetObject); //=> {a: 4, b: 5, c: 3, d: {a: 1, b: 2}};
console.log(targetObj); //=> {a: 4, b: 5, d: {a: 1}};
```
## Changelog
You can view the changelog here
## License
Defaulty is open-sourced software licensed under the MIT license
## Author
Fabio Ricali