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

defaultable

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

defaultable - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

test/merge.js

50

defaultable.js

@@ -18,2 +18,3 @@ // Defaultable APIs

module.exports = defaultable;
module.exports.merge = merge_obj;

@@ -45,15 +46,10 @@ function defaultable(initial_defs, definer) {

function defaulter(new_defs) {
new_defs = new_defs || {};
for (var key in old_defs)
if(! (key in new_defs))
new_defs[key] = old_defs[key];
var faux_exports = {};
var faux_module = {"exports":faux_exports};
var final_defs = merge_obj(new_defs || {}, old_defs);
definer(faux_module, faux_exports, new_defs);
definer(faux_module, faux_exports, final_defs);
var api = faux_module.exports;
api.defaults = make_defaulter(new_defs);
api.defaults = make_defaulter(final_defs);

@@ -64,1 +60,39 @@ return api;

}
function is_obj(val) {
return val && !Array.isArray(val) && (typeof val === 'object')
}
// Recursively merge higher-priority values into previously-set lower-priority ones.
function merge_obj(high, low) {
if(!is_obj(high))
throw new Error('Bad merge high-priority');
if(!is_obj(low))
throw new Error('Bad merge low-priority');
var keys = [];
function add_key(k) {
if(!~ keys.indexOf(k))
keys.push(k);
}
Object.keys(high).forEach(add_key);
Object.keys(low).forEach(add_key);
var result = {};
keys.forEach(function(key) {
var high_val = high[key];
var low_val = low[key];
if(is_obj(high_val) && is_obj(low_val))
result[key] = merge_obj(high_val, low_val);
else if (key in high)
result[key] = high[key];
else if (key in low)
result[key] = low[key];
else
throw new Error('Unknown key type: ' + key);
})
return result;
}

4

package.json
{ "name": "defaultable"
, "version": "0.4.0"
, "version": "0.5.0"
, "author": { "name": "Jason Smith"

@@ -19,3 +19,3 @@ , "email": "jhs@iriscouch.com"

, "devDependencies": { "tap": "0.0.9"
, "devDependencies": { "tap": "0.0.10"
}

@@ -22,0 +22,0 @@

@@ -5,2 +5,6 @@ # Default options for NodeJS, NPM, and CommonJS modules

Defaultable is pure CommonJS Javascript, and is also available as an NPM module.
$ npm install defaultable
## Is it any good?

@@ -7,0 +11,0 @@

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