Skip to content

Commit

Permalink
inline utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschlinkert committed Jul 11, 2018
1 parent 209ed07 commit d04f06c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 36 deletions.
20 changes: 13 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@

'use strict';

var utils = require('./utils');
var union = require('arr-union');
var clone = require('clone-deep');
var typeOf = require('kind-of');

module.exports = function mergeDeep(orig, objects) {
if (!utils.isObject(orig) && !Array.isArray(orig)) {
if (!isObject(orig) && !Array.isArray(orig)) {
orig = {};
}

var target = utils.clone(orig);
var target = clone(orig);
var len = arguments.length;
var idx = 0;

while (++idx < len) {
var val = arguments[idx];

if (utils.isObject(val) || Array.isArray(val)) {
if (isObject(val) || Array.isArray(val)) {
merge(target, val);
}
}
Expand All @@ -37,12 +39,12 @@ function merge(target, obj) {
var oldVal = obj[key];
var newVal = target[key];

if (utils.isObject(newVal) && utils.isObject(oldVal)) {
if (isObject(newVal) && isObject(oldVal)) {
target[key] = merge(newVal, oldVal);
} else if (Array.isArray(newVal)) {
target[key] = utils.union([], newVal, oldVal);
target[key] = union([], newVal, oldVal);
} else {
target[key] = utils.clone(oldVal);
target[key] = clone(oldVal);
}
}
return target;
Expand All @@ -51,3 +53,7 @@ function merge(target, obj) {
function hasOwn(obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key);
}

function isObject(val) {
return typeOf(val) === 'object' || typeOf(val) === 'function';
}
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
},
"license": "MIT",
"files": [
"index.js",
"utils.js"
"index.js"
],
"main": "index.js",
"engines": {
Expand All @@ -23,8 +22,7 @@
"dependencies": {
"arr-union": "^3.1.0",
"clone-deep": "^0.2.4",
"kind-of": "^3.0.2",
"lazy-cache": "^1.0.3"
"kind-of": "^3.0.2"
},
"devDependencies": {
"gulp-format-md": "^0.1.7",
Expand Down
25 changes: 0 additions & 25 deletions utils.js

This file was deleted.

0 comments on commit d04f06c

Please sign in to comment.