npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

underscore-deep-extend

v1.1.5

Published

A deepExtend implementation for underscore, lodash and friends.

Downloads

14,352

Readme

_.deepExtend

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

License: MIT

Original source: https://gist.github.com/1868955

Installation:

npm install underscore-deep-extend

Dependency:

One of

Usage:

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)

Notes:

Keep it DRY.

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.

Special Features and Considerations:

  • 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]