New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

defaulty

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defaulty - npm Package Compare versions

Comparing version 1.1.0 to 1.2.1

3

CHANGELOG.md

@@ -7,2 +7,5 @@ # Change Log

## [1.2.1] - 2017-08-26
- Added new API `copy`, now you can set default properties into new target object
## [1.1.0] - 2017-08-20

@@ -9,0 +12,0 @@ - Added `exclude` param, now you can exclude any default parameters

4

package.json
{
"name": "defaulty",
"version": "1.1.0",
"version": "1.2.1",
"description": "Copies missing properties to the target object.",

@@ -10,2 +10,3 @@ "main": "index.js",

"version:patch": "npm version patch",
"postversion": "npm publish && git push && git push --tags",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage",

@@ -16,2 +17,3 @@ "mocha.test": "mocha"

"copy",
"clone",
"object",

@@ -18,0 +20,0 @@ "deep",

@@ -23,8 +23,8 @@ <div align="center">

let defaultObj = {a: 1, b: 2, c: 3, d: {a: 5, b: 2}};
const defaultObj = {a: 1, b: 2, c: 3, d: {a: 5, b: 2}};
let targetObj = {a: 4, b: 5, d: {a: 1}};
let result = defaulty(targetObj, defaultObj);
defaulty(targetObj, defaultObj);
console.log(result); //=> {a: 4, b: 5, c: 3, d: {a: 1, b: 2}};
console.log(targetObj); //=> {a: 4, b: 5, c: 3, d: {a: 1, b: 2}};
```

@@ -34,10 +34,21 @@

```javascript
let defaultObj = {a: 1, b: 2, c: 3, d: {a: 5, b: 2}, x: 1, y: 2};
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}};
let result = defaulty(targetObj, defaultObj, ['x', 'y']);
defaulty(targetObj, defaultObj, ['x', 'y']);
console.log(result); //=> {a: 4, b: 5, c: 3, d: {a: 1, b: 2}};
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

@@ -44,0 +55,0 @@ You can view the changelog <a target="_blank" href="https://github.com/fabioricali/defaulty/blob/master/CHANGELOG.md">here</a>

@@ -23,2 +23,15 @@ /**

module.exports = defaulty;
/**
* Creates new target object and copies deep missing properties to the target object
* @param args[0] {Object} target object
* @param args[1] {Object} default object
* @param args[2] {Array} exclude properties from copy
* @returns {*}
*/
const copy = (...args) => {
args[0] = Object.assign({}, args[0]);
return defaulty.apply(this, args);
};
module.exports = defaulty;
module.exports.copy = copy;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc