Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jalik/deep-extend

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jalik/deep-extend - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

3

CHANGELOG.md
# Changelog
## v1.0.1
- Fixes recursive merging of arrays
## v1.0.0
- First public release

60

dist/index.js

@@ -8,8 +8,28 @@ "use strict";

var _extend = _interopRequireDefault(require("@jalik/extend"));
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
* The MIT License (MIT)
*
* Copyright (c) 2018 Karl STEIN
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
/**

@@ -29,13 +49,27 @@ * Merge deep objects

if (_typeof(b) === 'object' && b !== null && _typeof(a) === 'object' && a !== null) {
var keys = Object.keys(b);
if (a !== null && b !== null && typeof a !== 'undefined' && typeof b !== 'undefined') {
// Merge objects
if (_typeof(a) === 'object' && _typeof(b) === 'object') {
// Merge arrays
if (a instanceof Array && b instanceof Array) {
for (var index = 0; index < b.length; index += 1) {
if (typeof b[index] !== 'undefined') {
if (b[index] !== null && _typeof(b[index]) === 'object') {
a[index] = deepExtend(a[index], b[index]);
} else {
a[index] = b[index];
}
}
}
} else {
var keys = Object.keys(b);
for (var j = 0; j < keys.length; j += 1) {
var key = keys[j];
for (var j = 0; j < keys.length; j += 1) {
var key = keys[j];
if (typeof b[key] !== 'undefined') {
if (_typeof(b[key]) === 'object' && b[key] !== null) {
a[key] = (0, _extend.default)(a[key], b[key]);
} else {
a[key] = b[key];
if (_typeof(b[key]) === 'object' && b[key] !== null) {
a[key] = deepExtend(a[key], b[key]);
} else if (typeof b[key] !== 'undefined') {
a[key] = b[key];
}
}

@@ -42,0 +76,0 @@ }

{
"name": "@jalik/deep-extend",
"version": "1.0.0",
"version": "1.0.1",
"description": "A utility to merge deep objects.",

@@ -33,5 +33,3 @@ "license": "MIT",

},
"dependencies": {
"@jalik/extend": "^2.0.0"
},
"dependencies": {},
"devDependencies": {

@@ -43,3 +41,3 @@ "@babel/core": "^7.1.2",

"del": "^3.0.0",
"eslint": "^5.6.1",
"eslint": "^5.7.0",
"eslint-config-airbnb": "^17.1.0",

@@ -46,0 +44,0 @@ "eslint-plugin-import": "^2.14.0",

@@ -44,2 +44,16 @@ # @jalik/deep-extend

## Merging arrays
See below how it is easy to merge arrays recursively.
```js
import deepExtend from "@jalik/deep-extend";
const a = [1, [2, [3]]];
const b = [undefined, [4, [undefined, 5], 6], 7];
const c = deepExtend([], a, b);
// c would result to [1, [4, [3, 5], 6], 7]
```
## Changelog

@@ -46,0 +60,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc