1.2.2 • Published 1 year ago

@jalik/deep-extend v1.2.2

Weekly downloads
37
License
MIT
Repository
github
Last release
1 year ago

@jalik/deep-extend

GitHub package.json version Build Status GitHub last commit GitHub issues GitHub npm

A utility to merge deep objects.

Introduction

Use it when you need to merge nested objects.

Merging deep objects

The following code shows how to merge objects without losing values that are not defined in objects to merge.

import deepExtend from "@jalik/deep-extend";

const defaultColors = {
  cold: {
    blue: '#0000FF',
    green: '#00FF00',
  },
  hot: {
    red: '#FF0000',
    yellow: '#FFFF00',
  },
};

const customColors = {
  cold: {
    blue: '#48C2ED',
  },
  hot: {
    yellow: '#E6CB5F',
  },
};

// Merge all colors into a new object.
// The final colors will have custom blue and yellow colors,
// but the other colors will be the default ones.
const result = deepExtend({}, defaultColors, customColors);

The result:

{
  "cold": {
    "blue": "#48C2ED",
    "green": "#00FF00"
  },
  "hot": {
    "red": "#FF0000",
    "yellow": "#E6CB5F"
  }
}

Merging arrays

See below how it is easy to merge arrays recursively.

import deepExtend from "@jalik/deep-extend";

const a = [1, [2, [3]]];
const b = [undefined, [4, [undefined, 5], 6], 7];

const result = deepExtend([], a, b);

The result:

[
  1,
  [
    4,
    [
      3,
      5
    ],
    6
  ],
  7
]

Changelog

History of releases is in the changelog.

License

The code is released under the MIT License.

1.2.2

1 year ago

1.2.0

1 year ago

1.2.1

1 year ago

1.1.14

3 years ago

1.1.13

3 years ago

1.1.12

3 years ago

1.1.11

3 years ago

1.1.9

4 years ago

1.1.10

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago