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

unchanged

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unchanged - npm Package Compare versions

Comparing version 1.4.2 to 1.5.0

4

CHANGELOG.md

@@ -5,2 +5,6 @@ # unchanged CHANGELOG

## 1.5.0
- Add [`assign](README.md#assign) method
## 1.4.2

@@ -7,0 +11,0 @@

@@ -468,3 +468,3 @@ (function (global, factory) {

/**
* @function getDeeplyMergedObject
* @function getMergedObject
*

@@ -476,9 +476,10 @@ * @description

* @param {Array<*>|Object} object2 the object to merge
* @param {boolean} isDeep is the object deeply merged
* @returns {Array<*>|Object} the merged object
*/
var getDeeplyMergedObject = function getDeeplyMergedObject(object1, object2) {
var getMergedObject = function getMergedObject(object1, object2, isDeep) {
var isObject1Array = isArray(object1);
return isObject1Array !== isArray(object2) || !isCloneable(object1) ? cloneIfPossible(object2) : isObject1Array ? object1.concat(object2.map(cloneIfPossible)) : reduce(keys(object2), function (clone, key) {
clone[key] = isCloneable(object2[key]) ? getDeeplyMergedObject(object1[key], object2[key]) : object2[key];
clone[key] = isDeep && isCloneable(object2[key]) ? getMergedObject(object1[key], object2[key], isDeep) : object2[key];
return clone;

@@ -620,2 +621,23 @@ }, reduce(keys(object1), function (clone, key) {

/**
* @function assign
*
* @description
* get the shallowly-merged object at path
*
* @param {Array<number|string>|null|number|string} path the path to match on the object
* @param {Array<*>|Object} objectToAssign the object to merge
* @param {Array<*>|Object} object the object to merge with
* @returns {Array<*>|Object} the new merged object
*/
var assign$1 = curry(function (path, objectToAssign, object) {
if (!isCloneable(object)) {
return objectToAssign;
}
return isEmptyPath(path) ? getMergedObject(object, objectToAssign, false) : getDeepClone(path, object, function (ref, key) {
ref[key] = getMergedObject(ref[key], objectToAssign, false);
});
});
/**
* @function call

@@ -695,3 +717,3 @@ *

* @param {Array<number|string>|null|number|string} path the path to match on the object
* @param {Array<*>|Object} object the object to merge
* @param {Array<*>|Object} objectToMerge the object to merge
* @param {Array<*>|Object} object the object to merge with

@@ -706,4 +728,4 @@ * @returns {Array<*>|Object} the new merged object

return isEmptyPath(path) ? getDeeplyMergedObject(object, objectToMerge) : getDeepClone(path, object, function (ref, key) {
ref[key] = getDeeplyMergedObject(ref[key], objectToMerge);
return isEmptyPath(path) ? getMergedObject(object, objectToMerge, true) : getDeepClone(path, object, function (ref, key) {
ref[key] = getMergedObject(ref[key], objectToMerge, true);
});

@@ -795,2 +817,3 @@ });

exports.__ = __;
exports.assign = assign$1;
exports.call = call;

@@ -797,0 +820,0 @@ exports.get = get;

2

dist/unchanged.min.js

@@ -1,1 +0,1 @@

!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.unchanged={})}(this,function(n){"use strict";var u="function"==typeof Symbol?Symbol("curriable placeholder"):60881;function t(t){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:t.length;function e(){var n=arguments;return n.length>=r&&!function(n,t){for(var r=0;r<t;r++)if(n[r]===u)return!0;return!1}(n,r)?t.apply(this,n):function(){return e.apply(this,function(n,t){for(var r=new Array(n.length),e=0,o=0;o<n.length;o++)r[o]=n[o]===u&&e<t.length?t[e++]:n[o];if(e<t.length)for(;e<t.length;e++)r.push(t[e]);return r}(n,arguments))}}return e.arity=r,e.fn=t,e}t.__=u,t.uncurry=function(n){return n.fn};var r={clear:function(){r.results={},r.size=0},results:{},size:0},e=/"[^"]+"|`[^`]+`|'[^']+'|[^.[\]]+/g,o=/^\d+$/i,i=/^"[^"]+"|`[^`]+`|'[^']+'$/,f=function(n){var t,r,e=(t=n,i.test(t)?n.substring(1,n.length-1):n);return(r=e).length&&o.test(r)?+e:e},c=function(n){return"string"==typeof n?(t=n,r.results[t]||(500<r.size&&r.clear(),r.results[t]=t?t.match(e).map(f):[t],r.size++),r.results[t]):Array.isArray(n)?n.map(f):["number"==typeof n?n:""+n];var t},a=Object,l=a.create,s=a.getPrototypeOf,p=a.keys,g="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103,y=/^\s*function\s*([^\(]*)/i,h=Array.isArray,v=function(n,t,r){for(var e=r,o=0;o<n.length;o++)e=t(e,n[o]);return e},d=function(n){return!!n&&"object"==typeof n&&!(n instanceof Date||n instanceof RegExp)&&n.$$typeof!==g},m=function(n,t,r){return"function"==typeof n?n.apply(t,r):void 0},b=function(r){return r.constructor===a?function(n){for(var t=arguments.length,r=new Array(1<t?t-1:0),e=1;e<t;e++)r[e-1]=arguments[e];return v(r,function(n,r){return r?v(p(r),function(n,t){return n[t]=r[t],n},n):n},n)}({},r):h(r)?function(n){for(var t=new n.constructor,r=0;r<n.length;r++)t[r]=n[r];return t}(r):"function"==typeof(n=r.constructor)&&global[n.name||Function.prototype.toString.call(n).split(y)[1]]===n?{}:v(p(r),function(n,t){return n[t]=r[t],n},l(s(r)));var n},A=function(n){return"number"==typeof n?[]:{}},S=function(n){return d(n)?b(n):n},_=function(n,t){return void 0===n?t:n},j=function n(t,r,e,o,u,i){void 0===i&&(i=0);var f,c,a=t[i],l=i+1;if(l!==t.length)return o?(r[a]=n(t,(f=r[a],c=t[l],d(f)?b(f):A(c)),e,o,u,l),r):r&&r[a]?n(t,r[a],e,o,u,l):u;var s=r||o?e(r,a):u;return o?r:s},w=function r(e,o){var n=h(e);return n===h(o)&&d(e)?n?e.concat(o.map(S)):v(p(o),function(n,t){return n[t]=d(o[t])?r(e[t],o[t]):o[t],n},v(p(e),function(n,t){return n[t]=S(e[t]),n},e.constructor===a?{}:l(s(e)))):S(o)},x=function(n){return h(n)?n:c(n)},z=function(n,t,r){var e=x(n);return 1===e.length?t?_(t[e[0]],r):r:j(e,t,function(n,t){return _(n[t],r)},!1,r)},O=function(n,t,r){var e=x(n),o=d(t)?b(t):A(e[0]);return 1===e.length?(r(o,e[0]),o):j(e,o,r,!0)},$=function(n,t){return void 0!==z(n,t)},P=function(n){return null==n||h(n)&&!n.length},k=t(function(n,t,r,e){return void 0===e&&(e=r),P(n)?m(r,e,t):(o=e,u=t,i=r,1===(f=x(n)).length?i?m(i[f[0]],o,u):void 0:j(f,i,function(n,t){return m(n[t],o,u)}));var o,u,i,f},3),D=t(function(n,t){return P(n)?t:z(n,t)}),E=t(function(n,t,r){return P(t)?r:z(t,r,n)}),F=t(function(n,t){return P(n)?null!=t:$(n,t)}),M=t(function(n,r,t){return d(t)?P(n)?w(t,r):O(n,t,function(n,t){n[t]=w(n[t],r)}):r}),R=t(function(n,t){return P(n)?h(t)?[]:{}:$(n,t)?O(n,t,function(n,t){h(n)?function(n,t){if(n.length){for(var r=n.length,e=t;e<r;)n[e]=n[e+1],e++;n.length--}}(n,t):delete n[t]}):t}),q=t(function(n,r,t){return P(n)?r:O(n,t,function(n,t){n[t]=r})}),B=t(function(n,r,t){for(var e=arguments.length,o=new Array(3<e?e-3:0),u=3;u<e;u++)o[u-3]=arguments[u];return P(n)?r.apply(void 0,[t].concat(o)):O(n,t,function(n,t){return n[t]=r.apply(void 0,[n[t]].concat(o))})},3),C=t(function(n,t,r){var e=D(n,r),o=h(e)?h(n)?n.concat([e.length]):(P(n)?"":n)+"["+e.length+"]":n;return q(o,t,r)});n.__=u,n.call=k,n.get=D,n.getOr=E,n.has=F,n.merge=M,n.remove=R,n.set=q,n.transform=B,n.add=C,Object.defineProperty(n,"__esModule",{value:!0})});
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(n.unchanged={})}(this,function(n){"use strict";var o="function"==typeof Symbol?Symbol("curriable placeholder"):60881;function t(t){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:t.length;function e(){var n=arguments;return n.length>=r&&!function(n,t){for(var r=0;r<t;r++)if(n[r]===o)return!0;return!1}(n,r)?t.apply(this,n):function(){return e.apply(this,function(n,t){for(var r=new Array(n.length),e=0,u=0;u<n.length;u++)r[u]=n[u]===o&&e<t.length?t[e++]:n[u];if(e<t.length)for(;e<t.length;e++)r.push(t[e]);return r}(n,arguments))}}return e.arity=r,e.fn=t,e}t.__=o,t.uncurry=function(n){return n.fn};var r={clear:function(){r.results={},r.size=0},results:{},size:0},e=/"[^"]+"|`[^`]+`|'[^']+'|[^.[\]]+/g,u=/^\d+$/i,i=/^"[^"]+"|`[^`]+`|'[^']+'$/,f=function(n){var t,r,e=(t=n,i.test(t)?n.substring(1,n.length-1):n);return(r=e).length&&u.test(r)?+e:e},c=function(n){return"string"==typeof n?(t=n,r.results[t]||(500<r.size&&r.clear(),r.results[t]=t?t.match(e).map(f):[t],r.size++),r.results[t]):Array.isArray(n)?n.map(f):["number"==typeof n?n:""+n];var t},a=Object,l=a.create,s=a.getPrototypeOf,g=a.keys,p="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103,y=/^\s*function\s*([^\(]*)/i,h=Array.isArray,v=function(n,t,r){for(var e=r,u=0;u<n.length;u++)e=t(e,n[u]);return e},d=function(n){return!!n&&"object"==typeof n&&!(n instanceof Date||n instanceof RegExp)&&n.$$typeof!==p},m=function(n,t,r){return"function"==typeof n?n.apply(t,r):void 0},b=function(r){return r.constructor===a?function(n){for(var t=arguments.length,r=new Array(1<t?t-1:0),e=1;e<t;e++)r[e-1]=arguments[e];return v(r,function(n,r){return r?v(g(r),function(n,t){return n[t]=r[t],n},n):n},n)}({},r):h(r)?function(n){for(var t=new n.constructor,r=0;r<n.length;r++)t[r]=n[r];return t}(r):"function"==typeof(n=r.constructor)&&global[n.name||Function.prototype.toString.call(n).split(y)[1]]===n?{}:v(g(r),function(n,t){return n[t]=r[t],n},l(s(r)));var n},A=function(n){return"number"==typeof n?[]:{}},S=function(n){return d(n)?b(n):n},_=function(n,t){return void 0===n?t:n},j=function n(t,r,e,u,o,i){void 0===i&&(i=0);var f,c,a=t[i],l=i+1;if(l!==t.length)return u?(r[a]=n(t,(f=r[a],c=t[l],d(f)?b(f):A(c)),e,u,o,l),r):r&&r[a]?n(t,r[a],e,u,o,l):o;var s=r||u?e(r,a):o;return u?r:s},w=function r(e,u,o){var n=h(e);return n===h(u)&&d(e)?n?e.concat(u.map(S)):v(g(u),function(n,t){return n[t]=o&&d(u[t])?r(e[t],u[t],o):u[t],n},v(g(e),function(n,t){return n[t]=S(e[t]),n},e.constructor===a?{}:l(s(e)))):S(u)},x=function(n){return h(n)?n:c(n)},z=function(n,t,r){var e=x(n);return 1===e.length?t?_(t[e[0]],r):r:j(e,t,function(n,t){return _(n[t],r)},!1,r)},O=function(n,t,r){var e=x(n),u=d(t)?b(t):A(e[0]);return 1===e.length?(r(u,e[0]),u):j(e,u,r,!0)},$=function(n,t){return void 0!==z(n,t)},P=function(n){return null==n||h(n)&&!n.length},k=t(function(n,r,t){return d(t)?P(n)?w(t,r,!1):O(n,t,function(n,t){n[t]=w(n[t],r,!1)}):r}),D=t(function(n,t,r,e){return void 0===e&&(e=r),P(n)?m(r,e,t):(u=e,o=t,i=r,1===(f=x(n)).length?i?m(i[f[0]],u,o):void 0:j(f,i,function(n,t){return m(n[t],u,o)}));var u,o,i,f},3),E=t(function(n,t){return P(n)?t:z(n,t)}),F=t(function(n,t,r){return P(t)?r:z(t,r,n)}),M=t(function(n,t){return P(n)?null!=t:$(n,t)}),R=t(function(n,r,t){return d(t)?P(n)?w(t,r,!0):O(n,t,function(n,t){n[t]=w(n[t],r,!0)}):r}),q=t(function(n,t){return P(n)?h(t)?[]:{}:$(n,t)?O(n,t,function(n,t){h(n)?function(n,t){if(n.length){for(var r=n.length,e=t;e<r;)n[e]=n[e+1],e++;n.length--}}(n,t):delete n[t]}):t}),B=t(function(n,r,t){return P(n)?r:O(n,t,function(n,t){n[t]=r})}),C=t(function(n,r,t){for(var e=arguments.length,u=new Array(3<e?e-3:0),o=3;o<e;o++)u[o-3]=arguments[o];return P(n)?r.apply(void 0,[t].concat(u)):O(n,t,function(n,t){return n[t]=r.apply(void 0,[n[t]].concat(u))})},3),G=t(function(n,t,r){var e=E(n,r),u=h(e)?h(n)?n.concat([e.length]):(P(n)?"":n)+"["+e.length+"]":n;return B(u,t,r)});n.__=o,n.assign=k,n.call=D,n.get=E,n.getOr=F,n.has=M,n.merge=R,n.remove=q,n.set=B,n.transform=C,n.add=G,Object.defineProperty(n,"__esModule",{value:!0})});
// external dependencies
import { __, curry } from 'curriable'; // utils
import { callIfFunction, callNestedProperty, getDeepClone, getDeeplyMergedObject, getNestedProperty, getNewEmptyObject, hasNestedProperty, isArray, isCloneable, isEmptyPath, splice } from './utils';
import { callIfFunction, callNestedProperty, getDeepClone, getMergedObject, getNestedProperty, getNewEmptyObject, hasNestedProperty, isArray, isCloneable, isEmptyPath, splice } from './utils';
export { __ };
/**
* @function assign
*
* @description
* get the shallowly-merged object at path
*
* @param {Array<number|string>|null|number|string} path the path to match on the object
* @param {Array<*>|Object} objectToAssign the object to merge
* @param {Array<*>|Object} object the object to merge with
* @returns {Array<*>|Object} the new merged object
*/
export var assign = curry(function (path, objectToAssign, object) {
if (!isCloneable(object)) {
return objectToAssign;
}
return isEmptyPath(path) ? getMergedObject(object, objectToAssign, false) : getDeepClone(path, object, function (ref, key) {
ref[key] = getMergedObject(ref[key], objectToAssign, false);
});
});
/**
* @function call

@@ -81,3 +102,3 @@ *

* @param {Array<number|string>|null|number|string} path the path to match on the object
* @param {Array<*>|Object} object the object to merge
* @param {Array<*>|Object} objectToMerge the object to merge
* @param {Array<*>|Object} object the object to merge with

@@ -92,4 +113,4 @@ * @returns {Array<*>|Object} the new merged object

return isEmptyPath(path) ? getDeeplyMergedObject(object, objectToMerge) : getDeepClone(path, object, function (ref, key) {
ref[key] = getDeeplyMergedObject(ref[key], objectToMerge);
return isEmptyPath(path) ? getMergedObject(object, objectToMerge, true) : getDeepClone(path, object, function (ref, key) {
ref[key] = getMergedObject(ref[key], objectToMerge, true);
});

@@ -96,0 +117,0 @@ });

@@ -248,3 +248,3 @@ // external dependencies

/**
* @function getDeeplyMergedObject
* @function getMergedObject
*

@@ -256,9 +256,10 @@ * @description

* @param {Array<*>|Object} object2 the object to merge
* @param {boolean} isDeep is the object deeply merged
* @returns {Array<*>|Object} the merged object
*/
export var getDeeplyMergedObject = function getDeeplyMergedObject(object1, object2) {
export var getMergedObject = function getMergedObject(object1, object2, isDeep) {
var isObject1Array = isArray(object1);
return isObject1Array !== isArray(object2) || !isCloneable(object1) ? cloneIfPossible(object2) : isObject1Array ? object1.concat(object2.map(cloneIfPossible)) : reduce(keys(object2), function (clone, key) {
clone[key] = isCloneable(object2[key]) ? getDeeplyMergedObject(object1[key], object2[key]) : object2[key];
clone[key] = isDeep && isCloneable(object2[key]) ? getMergedObject(object1[key], object2[key], isDeep) : object2[key];
return clone;

@@ -265,0 +266,0 @@ }, reduce(keys(object1), function (clone, key) {

"use strict";
exports.__esModule = true;
exports.add = exports.transform = exports.set = exports.remove = exports.merge = exports.has = exports.getOr = exports.get = exports.call = void 0;
exports.add = exports.transform = exports.set = exports.remove = exports.merge = exports.has = exports.getOr = exports.get = exports.call = exports.assign = void 0;

@@ -16,2 +16,22 @@ var _curriable = require("curriable");

/**
* @function assign
*
* @description
* get the shallowly-merged object at path
*
* @param {Array<number|string>|null|number|string} path the path to match on the object
* @param {Array<*>|Object} objectToAssign the object to merge
* @param {Array<*>|Object} object the object to merge with
* @returns {Array<*>|Object} the new merged object
*/
var assign = (0, _curriable.curry)(function (path, objectToAssign, object) {
if (!(0, _utils.isCloneable)(object)) {
return objectToAssign;
}
return (0, _utils.isEmptyPath)(path) ? (0, _utils.getMergedObject)(object, objectToAssign, false) : (0, _utils.getDeepClone)(path, object, function (ref, key) {
ref[key] = (0, _utils.getMergedObject)(ref[key], objectToAssign, false);
});
});
/**
* @function call

@@ -27,2 +47,4 @@ *

*/
exports.assign = assign;
var call = (0, _curriable.curry)(function (path, parameters, object, context) {

@@ -94,3 +116,3 @@ if (context === void 0) {

* @param {Array<number|string>|null|number|string} path the path to match on the object
* @param {Array<*>|Object} object the object to merge
* @param {Array<*>|Object} objectToMerge the object to merge
* @param {Array<*>|Object} object the object to merge with

@@ -106,4 +128,4 @@ * @returns {Array<*>|Object} the new merged object

return (0, _utils.isEmptyPath)(path) ? (0, _utils.getDeeplyMergedObject)(object, objectToMerge) : (0, _utils.getDeepClone)(path, object, function (ref, key) {
ref[key] = (0, _utils.getDeeplyMergedObject)(ref[key], objectToMerge);
return (0, _utils.isEmptyPath)(path) ? (0, _utils.getMergedObject)(object, objectToMerge, true) : (0, _utils.getDeepClone)(path, object, function (ref, key) {
ref[key] = (0, _utils.getMergedObject)(ref[key], objectToMerge, true);
});

@@ -110,0 +132,0 @@ });

"use strict";
exports.__esModule = true;
exports.splice = exports.isEmptyPath = exports.hasNestedProperty = exports.getDeepClone = exports.getNestedProperty = exports.callNestedProperty = exports.getParsedPath = exports.getDeeplyMergedObject = exports.onMatchAtPath = exports.getCoalescedValue = exports.getNewChildClone = exports.cloneIfPossible = exports.getNewEmptyObject = exports.getNewEmptyChild = exports.getShallowClone = exports.callIfFunction = exports.isGlobalConstructor = exports.isCloneable = exports.assign = exports.reduce = exports.cloneArray = exports.isArray = void 0;
exports.splice = exports.isEmptyPath = exports.hasNestedProperty = exports.getDeepClone = exports.getNestedProperty = exports.callNestedProperty = exports.getParsedPath = exports.getMergedObject = exports.onMatchAtPath = exports.getCoalescedValue = exports.getNewChildClone = exports.cloneIfPossible = exports.getNewEmptyObject = exports.getNewEmptyChild = exports.getShallowClone = exports.callIfFunction = exports.isGlobalConstructor = exports.isCloneable = exports.assign = exports.reduce = exports.cloneArray = exports.isArray = void 0;

@@ -291,3 +291,3 @@ var _pathington = require("pathington");

/**
* @function getDeeplyMergedObject
* @function getMergedObject
*

@@ -299,2 +299,3 @@ * @description

* @param {Array<*>|Object} object2 the object to merge
* @param {boolean} isDeep is the object deeply merged
* @returns {Array<*>|Object} the merged object

@@ -306,6 +307,6 @@ */

var getDeeplyMergedObject = function getDeeplyMergedObject(object1, object2) {
var getMergedObject = function getMergedObject(object1, object2, isDeep) {
var isObject1Array = isArray(object1);
return isObject1Array !== isArray(object2) || !isCloneable(object1) ? cloneIfPossible(object2) : isObject1Array ? object1.concat(object2.map(cloneIfPossible)) : reduce(keys(object2), function (clone, key) {
clone[key] = isCloneable(object2[key]) ? getDeeplyMergedObject(object1[key], object2[key]) : object2[key];
clone[key] = isDeep && isCloneable(object2[key]) ? getMergedObject(object1[key], object2[key], isDeep) : object2[key];
return clone;

@@ -328,3 +329,3 @@ }, reduce(keys(object1), function (clone, key) {

exports.getDeeplyMergedObject = getDeeplyMergedObject;
exports.getMergedObject = getMergedObject;

@@ -331,0 +332,0 @@ var getParsedPath = function getParsedPath(path) {

@@ -45,3 +45,3 @@ {

"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^2.1.0",
"eslint-loader": "^2.1.1",
"html-webpack-plugin": "^3.2.0",

@@ -56,3 +56,3 @@ "in-publish": "^2.0.0",

"react-dom": "^16.4.2",
"rollup": "^0.66.0",
"rollup": "^0.66.1",
"rollup-plugin-babel": "^4.0.1",

@@ -100,3 +100,3 @@ "rollup-plugin-node-resolve": "^3.3.0",

"sideEffects": false,
"version": "1.4.2"
"version": "1.5.0"
}
# unchanged
A tiny (~1.9b minified+gzipped), [fast](https://github.com/planttheidea/unchanged/blob/master/benchmark_results.csv), unopinionated handler for updating JS objects and arrays immutably.
A tiny (~1.8kB minified+gzipped), [fast](https://github.com/planttheidea/unchanged/blob/master/benchmark_results.csv), unopinionated handler for updating JS objects and arrays immutably.

@@ -17,2 +17,3 @@ Supports nested key paths via path arrays or [dot-bracket syntax](https://github.com/planttheidea/pathington), and all methods are curriable (with placeholder support) for composability. Can be a drop-in replacement for the `lodash/fp` methods `get`, `set`, `merge`, and `omit` with a 90% smaller footprint.

- [merge](#merge)
- [assign](#assign)
- [call](#call)

@@ -32,3 +33,14 @@ - [transform](#transform)

```javascript
import { __, add, get, getOr, merge, remove, set } from "unchanged";
import {
__,
add,
assign,
call,
get,
getOr,
merge,
remove,
set,
transform
} from "unchanged";

@@ -178,3 +190,3 @@ const object = {

Returns a new object that is a deep merge of the two `object`s passed at the `path` specified.
Returns a new object that is a deep merge of `value` into `object` at the `path` specified. If you want to perform a shallow merge, see [`assign`](#assign).

@@ -194,6 +206,20 @@ ```javascript

console.log(merge("object", object2, object1)); // {oneSpecific: 'value', object: {one: 'new value', two: 'value1', three: 'value3'}}
console.log(merge("object", object2, object1));
/*
{
oneSpecific: 'value',
object: {
one: 'value1',
deeply: {
nested: 'other value',
untouched: true,
},
two: 'value2',
three: 'value3
}
}
*/
```
NOTE: If you want to merge the entirety of both objects, pass `null` as the key:
NOTE: If you want to `merge` the entirety of both objects, pass `null` as the key:

@@ -205,2 +231,6 @@ ```javascript

one: "value1",
deeply: {
nested: "value",
untouched: true
},
two: "value2"

@@ -211,8 +241,114 @@ }

one: "new value",
deeply: {
nested: "other value"
},
three: "value3"
};
console.log(merge(null, object2, object1)); // {one: 'new value', oneSpecific: 'value', object: {one: 'value1', two: 'value1'}, three: 'value3'}
console.log(merge(null, object2, object1));
/*
{
one: 'new value',
oneSpecific: 'value',
object: {
one: 'value1',
deeply: {
nested: 'value',
untouched: true,
},
two: 'value2',
},
deeply: {
nested: 'other value',
},
three: 'value3
}
*/
```
#### assign
`assign(path: (Array<number|string>|number|string), value: any, object: (Array<any>|object)): (Array<any>|Object)`
Returns a new object that is a shallow merge of `value` into `object` at the `path` specified. If you want to perform a deep merge, see [`merge`](#merge).
```javascript
const object1 = {
oneSpecific: "value",
object: {
one: "value1",
deeply: {
nested: "value",
untouched: false
},
two: "value2"
}
};
const object2 = {
one: "new value",
deeply: {
nested: "other value"
},
three: "value3"
};
console.log(assign("object", object2, object1));
/*
{
oneSpecific: 'value',
object: {
one: 'value1',
deeply: {
nested: 'other value',
},
two: 'value2',
three: 'value3
}
}
*/
```
NOTE: If you want to `assign` the entirety of both objects, pass `null` as the key:
```javascript
const object1 = {
oneSpecific: "value",
object: {
one: "value1",
deeply: {
nested: "value",
untouched: true
},
two: "value2"
}
};
const object2 = {
one: "new value",
deeply: {
nested: "other value"
},
three: "value3"
};
console.log(assign(null, object2, object1));
/*
{
one: 'new value',
oneSpecific: 'value',
object: {
one: 'value1',
deeply: {
nested: 'value',
untouched: true,
},
two: 'value2',
},
deeply: {
nested: 'other value',
},
three: 'value3
}
*/
```
#### call

@@ -219,0 +355,0 @@

Sorry, the diff of this file is not supported yet

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