Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
underscore-deep-extend
Advanced tools
A deep extend implementation for underscore, lodash and their (AFAIK non-existent) friends.
Based conceptually on the _.extend() function in underscore.js.
Copyright (C) 2012 Kurt Milam - http://xioup.com
Licensed under the GPL V3+.
Original source: https://gist.github.com/1868955
npm install underscore-deep-extend
One of
_.each
and _.is(Array|Date|Null|Object|String|Undefined)
.Load it, either as is (in the browser), as an AMD module, or as a CommonJS/Node.js module), then mix it in with the parent library (which must be explicitly injected):
_.mixin({deepExtend: underscoreDeepExtend(_)});
Call it like this:
var myObj = _.deepExtend(grandparent, child, grandchild, greatgrandchild)
This function is especially useful if you're working with JSON config documents. It allows you to create a default config document with the most common settings, then override those settings for specific cases. It accepts any number of objects as arguments, giving you fine-grained control over your config document hierarchy.
parentRE allows you to concatenate strings. example:
var obj = _.deepExtend({url: "www.example.com"}, {url: "http://#{_}/path/to/file.html"});
console.log(obj.url);
output: http://www.example.com/path/to/file.html
parentRE also acts as a placeholder, which can be useful when you need to change one value in an array, while leaving the others untouched. example:
var arr = _.deepExtend([100, {id: 1234}, true, "foo", [250, 500]],
["#{_}", "#{_}", false, "#{_}", "#{_}"]);
console.log(arr);
output: [100, {id: 1234}, false, "foo", [250, 500]]
The previous example can also be written like this:
var arr = _.deepExtend([100, {id:1234}, true, "foo", [250, 500]],
["#{_}", {}, false, "#{_}", []]);
console.log(arr);
output: [100, {id: 1234}, false, "foo", [250, 500]]
And also like this:
var arr = _.deepExtend([100, {id:1234}, true, "foo", [250, 500]],
["#{_}", {}, false]);
console.log(arr);
output: [100, {id: 1234}, false, "foo", [250, 500]]
Array order is important. example:
var arr = _.deepExtend([1, 2, 3, 4], [1, 4, 3, 2]);
console.log(arr);
output: [1, 4, 3, 2]
You can remove an array element set in a parent object by setting the same index value to null in a child object. Example:
var obj = _.deepExtend({arr: [1, 2, 3, 4]}, {arr: ["#{_}", null]});
console.log(obj.arr);
output: [1, 3, 4]
FAQs
A deepExtend implementation for underscore, lodash and friends.
The npm package underscore-deep-extend receives a total of 0 weekly downloads. As such, underscore-deep-extend popularity was classified as not popular.
We found that underscore-deep-extend demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.