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

lite-merge

v1.0.6

Published

A lightweight deep merging object handler, useful if you need to combine an object or group of objects into one single object overwriting/creating keys and values.

Downloads

11

Readme

lite-merge

A lightweight (624B) deep merging handler, useful if you need to combine an object or group of objects into one single object overwriting/creating keys and values.


Getting Started

Install the npm package

npm install lite-merge

Require it into your code.

var merge = require('lite-merge');

Merge objects

let object = { facts: { strawberry_is_berry: false } },
    target = { facts: { banana_is_berry: true } };

merge(object, target); // target = { facts: { strawberry_is_berry: false, banana_is_berry: true } }

Merge Function

The merge function is the default module export of the package, below I have detailed some use cases of the function.

| param | type | optional | description | | :---------- | :------------------------------------------ | :------- | :---------- | | merging | Object | false | The objects to merge together seperated by commas.

Note: The last provided object is the object all previous objects are merged into.. if you'd like a fresh object without overwritting all others just provide a blank object as the last parameter.


Basic Merging

This will be the most common use of the function, this merges multiple objects together setting/overwriting values.

let object = { stuff: { letters: ['d', 'e', 'f'], numbers: { 4: 'four', 5: 'five', 6: 'six' }, settings: { favourite: 'e' } } },
    target = { stuff: { letters: ['a', 'b', 'c'], numbers: { 1: 'one', 2: 'two', 3: 'three' } } };

merge(object, target);

If you were to console log the merge function you'd be presented with something like this.

{ 
    stuff: { 
        letters: [ 'a', 'b', 'c', 'd', 'e', 'f' ], 
        numbers: { 
            '1': 'one',
            '2': 'two',
            '3': 'three',
            '4': 'four',
            '5': 'five',
            '6': 'six'
        } 
    },
    settings: { 
        favourite: 'e' 
    }
}

This is the newly retured object created,

  • The letters array has been combined,
  • The numbers objects have been combined,
  • and the settings object has been added along with it's keys and values.

Merging Multiple Objects

The merge function lets you merge multiple objects into another without needing to call it for each object individually. To do this just put the objects you desire to merge one after the other seperating them by commas.

merge(object, target, ...etc)