This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@mdxvac/deep-merge
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

@mdxvac/deep-merge

DEPRECATED: Please consider using the plugin astro-m2dx, which bundles all features from the @mdxvac plugins in one plugin (completely opt-in).

Simple algorithm to merge configuration objects with arbitrary depths.

Content

What is this?

This package is a simple algorithm, that allows to merge configuration objects with arbitrary depths.

When should I use this?

If you have configuration objects with a defined precedence order, you can merge them with this algorithm (the last one merged takes the highest precedence).

The algorithm will create new objects for merged objects, so the input objects are never changed. In the merged object, simple values are overwritten by later source values, object values will be merged.

Note: Date and Array are NOT considered objects and will be overwritten instead of merged.

You must pass at least two objects.

I use it e.g. in a Static Site Generator to merge configuration files with default values specified on directory level.

Install

This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:

npm install -D @mdxvac/deep-merge

Use

const a = {
  address: {
    city: 'Berlin',
  },
  self: 'Icke',
};
const b = {
  familyName: 'Poor',
  address: {
    street: 'Unter den Linden',
  },
  rich: false,
  vehicles: ['bicycle'],
};
const c = {
  firstName: 'Joe',
  address: {
    number: '100',
  },
  self: 'Me',
  rich: true,
  vehicles: ['sports car', 'private jet', 'e-bike'],
};
deepMerge(a, b, c);

Will result in the following merged object:

{
  firstName: 'Joe',
  familyName: 'Poor',
  address: {
    number: '100',
    street: 'Unter den Linden',
    city: 'Berlin',
  },
  self: 'Me',
  rich: true,
  vehicles: ['sports car', 'private jet', 'e-bike'],
}

Package Sidebar

Install

npm i @mdxvac/deep-merge

Weekly Downloads

0

Version

0.0.4

License

MIT

Unpacked Size

4.9 kB

Total Files

4

Last publish

Collaborators

  • shackhacker-christian