Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ndhoule/defaults
Copies owned, enumerable properties from a source object(s) to a target object when the value of that property on the source object is undefined.
https://github.com/ndhoule/defaults
Last synced: 13 days ago
JSON representation
Copies owned, enumerable properties from a source object(s) to a target object when the value of that property on the source object is undefined.
- Host: GitHub
- URL: https://github.com/ndhoule/defaults
- Owner: ndhoule
- License: mit
- Created: 2015-03-18T18:53:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-05-02T20:32:45.000Z (over 8 years ago)
- Last Synced: 2024-04-10T13:55:26.994Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE.md
Awesome Lists containing this project
README
# defaults [![CI][ci-badge]][ci-link]
Copies owned, enumerable properties from a source object(s) to a target object when the value of that property on the source object is `undefined`.
## Installation
```sh
$ component install ndhoule/defaults
$ npm install @ndhoule/defaults
```## API
### `defaults(target : Object, sources : ...Object)` => Object
Copies owned, enumerable properties from a source object(s) to a target object when the value of that property on the source object is `undefined`.
```javascript
var a = { a: 1 };
var b = { a: 2, b: 2 };defaults(a, b);
console.log(a); //=> { a: 1, b: 2 }
```### `defaults.deep(target : Object, sources : ...Object)` => Object
Deeply copies owned, enumerable properties from a source object(s), recursing on object properties, to a target object when the value of that property on the source object is `undefined`.
```javascript
var a = { a: 1, b: { c: 3 } };
var b = { a: 2, b: { d: 4 } };defaults(a, b);
console.log(a); //=> { a: 1, b: { c: 3, d: 4} }
```## License
Released under the [MIT license](LICENSE.md).
[ci-link]: https://travis-ci.org/ndhoule/defaults
[ci-badge]: https://travis-ci.org/ndhoule/defaults.svg?branch=master