Socket
Socket
Sign inDemoInstall

defaults

Package Overview
Dependencies
0
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.4 to 2.0.0

index.d.ts

58

index.js

@@ -1,13 +0,51 @@

var clone = require('clone');
// From: https://github.com/sindresorhus/is-plain-obj
const isPlainObject = value => {
if (typeof value !== 'object' || value === null) {
return false;
}
module.exports = function(options, defaults) {
options = options || {};
const prototype = Object.getPrototypeOf(value);
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value);
};
Object.keys(defaults).forEach(function(key) {
if (typeof options[key] === 'undefined') {
options[key] = clone(defaults[key]);
}
});
const disallowedKeys = new Set([
'__proto__',
'prototype',
'constructor',
]);
return options;
};
const merge = (destination, source) => {
if (!isPlainObject(source)) {
return destination;
}
if (!destination) {
destination = {};
}
for (const [sourceKey, sourceValue] of Object.entries(source)) {
if (disallowedKeys.has(sourceKey)) {
continue;
}
const destinationValue = destination[sourceKey];
if (isPlainObject(destinationValue) && isPlainObject(sourceValue)) {
destination[sourceKey] = merge(destinationValue, sourceValue); // Merge plain objects recursively
} else if (sourceValue === undefined) {
continue; // Skip undefined values in source
} else if (isPlainObject(sourceValue)) {
destination[sourceKey] = merge({}, sourceValue); // Clone plain objects
} else if (Array.isArray(sourceValue)) {
destination[sourceKey] = [...sourceValue]; // Clone arrays
} else {
destination[sourceKey] = sourceValue; // Assign other types
}
}
return destination;
};
export default function defaults(options = {}, defaultOptions = {}) {
return merge({...defaultOptions}, {...options});
}

35

package.json
{
"name": "defaults",
"version": "1.0.4",
"description": "merge single level defaults over a config object",
"main": "index.js",
"version": "2.0.0",
"description": "Easily handle defaults for your options",
"license": "MIT",
"repository": "sindresorhus/defaults",
"funding": "https://github.com/sponsors/sindresorhus",
"type": "module",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"engines": {
"node": ">=16"
},
"scripts": {
"test": "node test.js"
"test": "xo && ava && tsd"
},
"repository": {
"type": "git",
"url": "git://github.com/sindresorhus/node-defaults.git"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [

@@ -24,11 +33,7 @@ "config",

],
"author": "Elijah Insua <tmpvar@gmail.com>",
"license": "MIT",
"readmeFilename": "README.md",
"dependencies": {
"clone": "^1.0.2"
},
"devDependencies": {
"tap": "^2.0.0"
"ava": "^5.2.0",
"tsd": "^0.28.1",
"xo": "^0.54.0"
}
}
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc