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

merge-professor

v1.0.6

Published

Advanced recursive merge utility for JavaScript objects and arrays.

Downloads

4

Readme

merge-professor

NPM Version Build Status Coverage Status Greenkeeper badge

Advanced recursive merge utility for JavaScript objects and arrays.

Features

  • Supports multiple objects or arrays to merge in single function call.
  • Merges objects recursively.
  • Allows to merge object items of arrays by specified identifier fields.
  • Has an option to merge properties existing only in first object.
  • Free to use. :)

Installation

npm install merge-professor --save

Usage

  • require with Node.js:

    var merge = require('merge-professor');
  • in browser include dist/merge.js or dist/merge.min.js script:

    var merge = window.mergeProfessor;

and then

var o = merge({ a: 1 }, { b: 2 });                        // { a: 1, b: 2 }
var a = merge([1, 2, 3], ['one', 'two', 'three']);        // [1, 2, 3, 'one', 'two', 'three']

Examples

  • merge plain objects and arrays:

    var o = merge({ a: 1 }, { b: 2 });                    // { a: 1, b: 2 }
    var a = merge([1, 2, 3], ['one', 'two', 'three']);    // [1, 2, 3, 'one', 'two', 'three']
  • merge objects recursively:

    var o1 = {
        language: {
            en: 'English',
            ru: 'Русский'
        },
        sidebarPanelId: 'satellite'
    };
    
    var o2 = {
        language: {
            ru: 'Russian',
            de: 'German'
        },
        sidebarPanelId: 'geocoding'
    };
    
    var o = merge(o1, o2);    // {
                              //     language: {
                              //         en: 'English',
                              //         ru: 'Russian',
                              //         de: 'German'
                              //     },
                              //     sidebarPanelId: 'geocoding'
                              // }
  • merge arrays uniting their object items by specified identifier field:

    var a1 = [
        { id: 25994, name: 'Terra', visible: true },
        { id: 27424, name: 'Aqua', visible: false }
    ];
    
    var a2 = [
        { id: 27424, name: 'AQUA' },
        { id: 25994, visible: false }
    ];
    
    var a = merge(a1, a2, 'id');    // [
                                    //     { id: 25994, name: 'Terra', visible: false },
                                    //     { id: 27424, name: 'AQUA', visible: false }
                                    // ]

    or even objects with nested arrays uniting their object items by more than single identifier field:

    var o1 = {
        satellites: [
            { id: 25994, name: 'Terra', visible: true },
            { id: 27424, name: 'Aqua', visible: false }
        ]
    };
    
    var o2 = {
        satellites: [
            { id: 27424, name: 'AQUA', visible: true },
            { id: 40069, name: 'Terra' }
        ]
    };
      
    var o = merge(o1, o2, 'id', 'name');    // {
                                            //     satellites: [
                                            //         { id: 40069, name: 'Terra', visible: true },
                                            //         { id: 27424, name: 'AQUA', visible: true }
                                            //     ]
                                            // }
  • merge properties existing only in first object:

    var o1 = { id: 25994, name: 'Terra', visible: false };
    var o2 = { sidebarPanelId: 'satellite', visible: true };
    
    var o = merge(o1, o2, true);    // { id: 25994, name: 'Terra', visible: true });
  • merge with all available options:

    var o1 = {
        satellites: [
            { id: 25994, name: 'Terra', visible: true },
            { id: 27424, name: 'Aqua', visible: false }
        ]
    };
    
    var o2 = {
        satellites: [
            { id: 25994, visible: false },
            { id: 40069, name: 'Meteor-M №2', visible: true }
        ]
    };
    
    var o = merge(o1, o2, 'id', true);    // {
                                          //     satellites: [
                                          //         { id: 25994, name: 'Terra', visible: false },
                                          //         { id: 27424, name: 'Aqua', visible: false }
                                          //     ]
                                          // }

Building

In order to build library run:

npm run build

Testing

Run unit tests:

npm test

In order to run tests with Coveralls locally you have to provide COVERALLS_REPO_TOKEN:

COVERALLS_REPO_TOKEN=<token> npm run test:coverage

Contribution

Before making a pull request, please, be sure that your changes are rebased to dev branch.

License

MIT