JSPM

normalize-defaults

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q24732F
  • License MIT

Normalize missing options in an options/config object using a default object as reference

Package Exports

  • normalize-defaults

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (normalize-defaults) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

normalize-defaults

Normalize missing first-level keys/values in an options/config object using a default object as reference.

npm ver travis ci license

Examples

  • Example 1
var normalize = require('normalize-defaults');

var obj = { 
    'rhinos': null, 
    'wolves': 15,
    'tigers': 42
};

var defaults = { 
    'rhinos': 8,
    'lions': 0,
    'wolves': 14
};

normalize(obj, def);

console.log(obj); 
// -> { 'rhinos': 8, 'lions': 0, 'wolves': 15, 'tigers': 42 };
  • Example 2
var normalize = require('normalize-defaults');

var obj = {};
var defaults = {
    arr: []
};

normalize(obj, defaults);

console.log(obj.arr); // []
obj.arr.push(5);
console.log(obj.arr); // []
console.log(def.arr); // [] - the defaults objects remains unaffected

License

MIT