{"_id":"merge-dictionaries","_rev":"4-5d52c09413cf70aaa94386bc67fa98e7","name":"merge-dictionaries","description":"Recursively merge two dictionaries together","dist-tags":{"latest":"1.0.0"},"versions":{"0.0.1":{"name":"merge-dictionaries","version":"0.0.1","description":"Recursively merge two dictionaries together","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"author":{"name":"sgress454"},"license":"MIT","dependencies":{"@sailshq/lodash":"^3.10.2"},"gitHead":"9bf6c4c7e6366e9464fd780549eae14247959cb8","_id":"merge-dictionaries@0.0.1","_shasum":"fdb6c8f719a02d237dd9759202c7af263c9b6d40","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"sgress454","email":"sgress454@treeline.io"},"dist":{"shasum":"fdb6c8f719a02d237dd9759202c7af263c9b6d40","tarball":"https://registry.npmjs.org/merge-dictionaries/-/merge-dictionaries-0.0.1.tgz","integrity":"sha512-8OHEti/GpZi+5BDvIInv0rSWPphfh3TYLKjQDpgn/yyvilen7RlIb5Sovu7/lny8aNz16bGnCzxarkSnH+bBwA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCx+H2xfUNK7YJ2QgL+ppVkQQ85NGBnY2QIC54vOXlVMwIhAKmFe8nRYLPdXgJ9hdH3qM+mjOGGQueJWvmFzCEszp0T"}]},"maintainers":[{"name":"sgress454","email":"sgress454@treeline.io"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/merge-dictionaries-0.0.1.tgz_1485545193963_0.7075550081208348"}},"0.0.3":{"name":"merge-dictionaries","version":"0.0.3","description":"Recursively merge two dictionaries together","main":"index.js","scripts":{"test":"mocha"},"author":{"name":"sgress454"},"license":"MIT","dependencies":{"@sailshq/lodash":"^3.10.2"},"devDependencies":{"mocha":"3.2.0"},"bugs":{"url":"http://sailsjs.com/bugs"},"gitHead":"4e54be038d7542c862c368b0f195137f67e396db","_id":"merge-dictionaries@0.0.3","_shasum":"c4de4d58dbb25e4c2823aa30cb8e1539069eb757","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"sgress454","email":"sgress454@treeline.io"},"dist":{"shasum":"c4de4d58dbb25e4c2823aa30cb8e1539069eb757","tarball":"https://registry.npmjs.org/merge-dictionaries/-/merge-dictionaries-0.0.3.tgz","integrity":"sha512-7KnOdGPqHF7ZeBqNtOskSmAJKVlgwla5km2ToavXP7ZJ761JvcSf15cjkrSD+FNuhAvKUGsFKkL9ynBvnCRTZA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDyIhVqOJELvZa6aYe0ZOvfFFDyAIjr6vRfngRkhz4X7QIhAJIKq5gicsDTi4/PzYwNDeoe3ucU8CrYyUNouJu0pu6J"}]},"maintainers":[{"name":"sgress454","email":"sgress454@treeline.io"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/merge-dictionaries-0.0.3.tgz_1486536331894_0.7605917456094176"}},"1.0.0":{"name":"merge-dictionaries","version":"1.0.0","description":"Recursively merge two dictionaries together","main":"index.js","scripts":{"test":"mocha"},"author":{"name":"sgress454"},"license":"MIT","dependencies":{"@sailshq/lodash":"^3.10.2"},"devDependencies":{"mocha":"3.2.0"},"bugs":{"url":"http://sailsjs.com/bugs"},"gitHead":"ee9bc7859d4155ede771badb41f108a85c70236f","_id":"merge-dictionaries@1.0.0","_shasum":"7896ee1ab1a1550d3287a0311b7db7804b691931","_from":".","_npmVersion":"2.15.8","_nodeVersion":"4.4.7","_npmUser":{"name":"sgress454","email":"sgress454@treeline.io"},"dist":{"shasum":"7896ee1ab1a1550d3287a0311b7db7804b691931","tarball":"https://registry.npmjs.org/merge-dictionaries/-/merge-dictionaries-1.0.0.tgz","integrity":"sha512-5MpJgYdi5Loor97U3ixSBZhUjaDGIOa9tmvQYT9iYKXTeSJFuE4aVcwpBJdNRa76sJyHGqEh7LH3wbtmhpIg0A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGzONtQ94hwnq9YA6G47WDPVrpBi/YpPHXGg86l8KJZbAiEAnpl5iU3fLNkvQDw7lTOPw8q9qjp1BF5exk7k3HTZ3pE="}]},"maintainers":[{"name":"sgress454","email":"sgress454@treeline.io"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/merge-dictionaries-1.0.0.tgz_1488389779231_0.3316247316543013"}}},"readme":"# merge-dictionaries\n\nA wrapper around the Lodash 3 `.merge()` function that addresses some issues with arrays and object references.  Intended for merging configuration files together.\n\n### Usage\n\n```\nnpm install merge-dictionaries\n```\n\n```\nvar mergeDictionaries = require('merge-dictionaries');\nmergeDictionaries(dictA, dictB);\n```\n\n### What&rsquo;s the problem that this solves?\n\nThe `.merge()` function works great in most cases, but the default behavior has two problems:\n\nFirst, array values in the second argument are merged weirdly with values in the first argument.  Examples:\n\n```\n// Two arrays are \"merged\" together by replacing values in the first array with values from\n// the second, by index:\nvar dictA = { foo: ['owl', 'snake', 'fish'] };\nvar dictB = { foo: ['cat', 'dog']};\n_.merge(dictA, dictB);\n\n// Results in:\n// { foo: ['cat', 'dog', 'fish'] }\n\n\n// Merging an array into a string causes the string to be busted up into an array of characters,\n// which is then merged on-top-of as above:\nvar dictA = { foo: 'abcde' };\nvar dictB = { foo: ['cat', 'dog']};\n_.merge(dictA, dictB);\n\n// Results in:\n// { foo: ['cat', 'dog', 'c', 'd', 'e'] }\n```\n\nSecond, dictionaries in the second argument that do not have corresponding dictionary values in the first argument (or whose corresponding values are `{}`) are copied over by _value_ instead of by _reference_:\n\n```\nvar dictA = { foo: 'bar' };\nvar dictB = { nested: { owl: 'hoot' } };\nvar owl = dictB.nested; // <-- owl is { owl: 'hoot' }\nvar merged = _.merge(dictA, dictB);\n\n// Results in:\n// { foo: 'bar', nested: { owl: 'hoot' } }\n\nconsole.log(owl === merged.nested);\n// Results in:\n// false\n```\n\nThis might not seem like a big issue, but it can be a real problem when merging dictionaries that contain references to objects created by another module.  For example imagine:\n\n```\nvar configA = { someConfigValue: 'some default value' };\nvar configB = { someConfigValue: 'a custom value',  someModule: require('my-module') };\nvar mergedObj = _.merge(configA, configB);\n```\n\nwhere `my-module` looks like:\n\n```\nmodule.exports = ( function() {\n  // Declare the public data dictionary exposed by this module.\n  var publicData = {};\n  return {\n    // Expose the public data to the outside world.\n    somePublicData: publicData\n    // Declare a function for initializing the module.\n    init: function() {\n      publicData.foo = 'bar';\n    }\n  }\n} )()\n```\n\nIf you call `mergedObj.someModule.init()` later, you might expect `mergedObj.someModule.somePublicData` to be set to `{foo: 'bar'}`, but it&rsquo;ll still just be an empty dictionary, because a _different `somePublicData` dictionary_ was copied into the merged object.\n\n### What&rsquo;s the solution?\n\nThe solution is very simple, because the `_.merge()` function can take a third argument that allows you to customize the merge behavior.  We can use this to tell `_.merge()` to _only_ do its regular thing when the left-hand value is a non-empty plain dictionary.  In all other cases, `a` is replaced by `b`.\n\n> Keep in mind that this means that if `a` _looks_ like a dictionary, but was created by a custom constructor (i.e. it is not a &ldquo;plain&rdquo; dictionary, it will be replaced by `b`!  For example:\n>\n> ```\n> var myClass = function() {this.foo = 'bar'};\n> var obj1 = { abc: new myClass() };\n> // Result:\n> // { abc: { foo: 'bar' } }\n>\n> var obj2 = { abc: { owl: 'hoot' } };\n> var merged = mergeDictionaries(obj1, obj2);\n>\n> // Result:\n> // { abc: { owl: 'hoot' } }\n> ```\n\n\n## Help\n\nIf you have questions or are having trouble, click [here](http://sailsjs.com/support).\n\n\n## Bugs &nbsp; [![NPM version](https://badge.fury.io/js/merge-dictionaries.svg)](http://npmjs.com/package/merge-dictionaries)\n\nTo report a bug, [click here](http://sailsjs.com/bugs).\n\n\n## Contributing\n\nPlease observe the guidelines and conventions laid out in the [Sails project contribution guide](http://sailsjs.com/documentation/contributing) when opening issues or submitting pull requests.\n\n[![NPM](https://nodei.co/npm/merge-dictionaries.png?downloads=true)](http://npmjs.com/package/merge-dictionaries)\n\n## License\n\nLike the [Sails framework](http://sailsjs.com), this package is free and open-source under the [MIT License](http://sailsjs.com/license).\n","maintainers":[{"name":"sgress454","email":"sgress454@treeline.io"}],"time":{"modified":"2022-06-19T17:52:35.120Z","created":"2017-01-27T19:26:35.856Z","0.0.1":"2017-01-27T19:26:35.856Z","0.0.3":"2017-02-08T06:45:33.596Z","1.0.0":"2017-03-01T17:36:19.927Z"},"author":{"name":"sgress454"},"license":"MIT","readmeFilename":"README.md","bugs":{"url":"http://sailsjs.com/bugs"}}