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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@blackcater/merge

v1.0.1

Published

对象合并

Readme

A util for merge object.

CircleCI Coverage Status FOSSA Status

$ yarn add @blackcater/merge
import { merge } from '@blackcater/merge'

merge(1, 2) // 2

merge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }

merge([1, 2], [3, 4]) // [3, 4]

merge([1, 2], [3, 4], { type: 'merge' }) // [3, 4]

merge([1, { a: 2 }], [3, { b: 4 }], { type: 'merge' }) // [3, { a: 2, b: 4 }]

new Merge(options)

Project export a Merge class. You can pass an options to control the merge category.

The default option is bellow:

{
  // options for merge array
  array: {
    // strategy for merging array. You can choose push/unshift/merge/replace
    type: 'replace',
    // target parameter must be an array
    array: true,
    // whether or not to filter the same element in source parameter
    filter: false,
    // whether or not to merge element, it works when `type` equals 'merge'
    merge: false,
    // whether null value is important, it works when `type` equals 'merge' and `merge` equals 'true'
    nullable: true,
    // whether undefined value is important, it works when `type` equals 'merge' and `merge` equals 'true'
    undefinable: true,
  },
  // options for merge object
  object: {
    // target parameter must be an object
    object: true,
    // whether null value is important
    nullable: true,
    // whether undefined value is important
    undefinable: true,
  },
}

merge.merge(source, target, options)

The structure of options parameter is the same as Class Merge.

This is a wrapper of merge.mergeArray and merge.mergeOject function.

import Merge from '@blackcater/merge'

const merge = new Merge()

merge.merge(1, 2) // 2

merge.merge([1], [2]) // [2]

merge.merge({ a: 1 }, { b: 2 }) // { a: 1, b: 2 }

merge.mergeArray(source, target, options)

You can pass an options. Below is the default value of options

{
  // strategy for merging array. You can choose push/unshift/merge/replace
  type: 'replace',
  // target parameter must be an array
  array: true,
  // whether or not to filter the same element in source parameter
  filter: false,
  // whether or not to merge element, it works when `type` equals 'merge'
  merge: false,
  // whether null value is important, it works when `type` equals 'merge' and `merge` equals 'true'
  nullable: true,
  // whether undefined value is important, it works when `type` equals 'merge' and `merge` equals 'true'
  undefinable: true,
}
import Merge from '@blackcater/merge'

const merge = new Merge()

merge.mergeArray([1, 2], 3) // 3
merge.mergeArray([1, 2], 3, { type: 'push' }) // [1, 2, 3]
merge.mergeArray([1, 2], 1, { type: 'push', filter: true }) // [2, 1]
merge.mergeArray([1, 2], [null, undefined], { type: 'merge' }) // [null, undefined]
merge.mergeArray([1, 2], [null, undefined], { type: 'merge', nullable: false }) // [1, undefined]
merge.mergeArray([1, 2], [null, undefined], { type: 'merge', nullable: false, undefinable: false }) // [1, 2]

merge.mergeObject(source, target, options)

You can pass an options. Below is the default value of options

{
  // target parameter must be an object
  object: true,
  // whether null value is important
  nullable: true,
  // whether undefined value is important
  undefinable: true,
}
import Merge from '@blackcater/merge'

const merge = new Merge()

merge.mergeObject({ a: 1 }, 3) // 3
merge.mergeObject({ a: 1 }, '1') // { 0: '1', a: 1 }
merge.mergeObject({ a: 1, b: 2 }, { a: 3, c: 4 }) // { a: 3, b: 2, c: 4 }
merge.mergeObject({ a: 1, b: 2 }, { a: null, b: undefined }) // { a: null, b: undefined }
merge.mergeObject({ a: 1, b: 2 }, { a: null, b: undefined }, { nullable: false }) // { a: 1, b: undefined }
merge.mergeObject({ a: 1, b: 2 }, { a: null, b: undefined }, { nullable: false, undefinable: false }) // { a: 1, b: 2 }

Others

For convenience, project exports an instance of Merge.

import { merge, mergeArray, mergeObject } from '@blackctaer/merge'

MIT@blackcater

License

FOSSA Status