normalize-defaults
Normalize missing first-level keys/values in an object with those from defaults.
Examples
- Example 1
var normalize = ; var obj = rhinos: null wolves: 15 tigers: 42; var defaults = rhinos: 8 lions: 0 wolves: 14; obj = ; console; // { rhinos: 8, wolves: 15, tigers: 42, lions: 0 }
- Example 2
var normalize = ; var obj = {};var defaults = arr: ; obj = ; objarr; console; // [5]console; // [] - defaults' objects remains unaffected
- Example 3
var normalize = ; var obj = null;var defaults = a: 42; obj = ; console; // 42
Changelog
v0.1.4
- If the object to normalize is
null
, use the default object entirely - The previous change now requires that the return value be used, since the
null
first argument cannot be modified.