Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 10 days ago
JSON representation

Copies deep missing properties to the target object

Awesome Lists containing this project

README

        


defaulty


Copies deep missing properties to the target object.







## 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