New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@ultraq/object-utils

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ultraq/object-utils - npm Package Compare versions

Comparing version
2.1.0
to
3.0.0
+48
object-utils.d.ts
/**
* Deep-equality comparison between 2 objects on whether they contain the same
* values as each other. Only works with objects that act as data structures,
* not classes or the like as this function only compares primitives using
* identity (`===`) comparison.
*
* @param {any} object1
* @param {any} object2
* @return {boolean}
*/
export function equals(object1: any, object2: any): boolean;
/**
* Deep-merges all of the properties of the objects in `sources` with `target`,
* modifying the target object and returning it.
*
* @param {object} target
* @param {...object} sources
* @return {object} The modified target object.
*/
export function merge(target?: object, ...sources: object[]): object;
/**
* Returns a value from an object via a path string that describes the nesting
* of objects to get to the value.
*
* eg:
*
* ```
* let object = {
* greeting: {
* message: 'Hello!'
* }
* };
* let pathToMessage = 'greeting.message';
* ```
*
* > The null-safe nature of this method is now in JavaScript as the optional
* > chaining operator (`?.`). If you're not using string paths/selectors to
* > the item in your object, then I suggest you use that instead. Otherwise,
* > if you're using string path selectors or can't use that method because of
* > browser support, this method will still do the job 🙂
*
* @param {object} object
* @param {string} path A dot-separated path string to get to the desired value
* within the object
* @return {object} The value at the given path within the object, or
* `undefined` if the path doesn't resolve within the object.
*/
export function navigate(object: object, path: string): object;
+22
-44
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -11,5 +10,3 @@ value: true

exports.navigate = navigate;
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
/*

@@ -37,41 +34,25 @@ * Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)

*
* @param {*} object1
* @param {*} object2
* @return {Boolean}
* @param {any} object1
* @param {any} object2
* @return {boolean}
*/
function equals() {
var object1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var object2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
function equals(object1, object2) {
// Identity
if (object1 === object2) {
return true;
} // One argument null and the other isn't
if (object1 === null && object2 !== null) {
return false;
}
if (object1 !== null && object2 === null) {
return false;
} // Compare objects
if ((0, _typeof2.default)(object1) === 'object' && (0, _typeof2.default)(object2) === 'object') {
// Compare objects
if ((0, _typeof2["default"])(object1) === 'object' && (0, _typeof2["default"])(object2) === 'object') {
var keys1 = Object.keys(object1);
var keys2 = Object.keys(object2);
if (keys1.length !== keys2.length) {
return false;
}
return keys1.every(function (key) {
return keys1.length === keys2.length && keys1.every(function (key) {
return equals(object1[key], object2[key]);
});
} // Compare primitives
}
// Compare primitives
return object1 === object2;
}
/**

@@ -81,15 +62,11 @@ * Deep-merges all of the properties of the objects in `sources` with `target`,

*
* @param {Object} target
* @param {...Object} sources
* @return {Object} The modified target object.
* @param {object} target
* @param {...object} sources
* @return {object} The modified target object.
*/
function merge() {
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
sources[_key - 1] = arguments[_key];
}
sources.forEach(function (source) {

@@ -106,2 +83,3 @@ if (source) {

}
/**

@@ -122,14 +100,14 @@ * Returns a value from an object via a path string that describes the nesting

*
* > This is now natively in JavaScript as the optional chaining operator (`?.`).
* > If you have access to that feature, I suggest you use that instead. If you
* > don't, then this method will still do the job 🙂
* > The null-safe nature of this method is now in JavaScript as the optional
* > chaining operator (`?.`). If you're not using string paths/selectors to
* > the item in your object, then I suggest you use that instead. Otherwise,
* > if you're using string path selectors or can't use that method because of
* > browser support, this method will still do the job 🙂
*
* @param {Object} object
* @param {String} path A dot-separated path string to get to the desired value
* @param {object} object
* @param {string} path A dot-separated path string to get to the desired value
* within the object
* @return {Object} The value at the given path within the object, or
* @return {object} The value at the given path within the object, or
* `undefined` if the path doesn't resolve within the object.
*/
function navigate(object, path) {

@@ -136,0 +114,0 @@ return path.split('.').reduce(function (previousValue, pathToken) {

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

{"version":3,"sources":["object-utils.js"],"names":[],"mappings":";;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;AAgBA;;;;;;;;;;AAUO,SAAS,MAAT,GAAgD;AAAA,MAAhC,OAAgC,uEAAtB,IAAsB;AAAA,MAAhB,OAAgB,uEAAN,IAAM;;AAEtD;AACA,MAAI,OAAO,KAAK,OAAhB,EAAyB;AACxB,WAAO,IAAP;AACA,GALqD,CAOtD;;;AACA,MAAI,OAAO,KAAK,IAAZ,IAAoB,OAAO,KAAK,IAApC,EAA0C;AACzC,WAAO,KAAP;AACA;;AACD,MAAI,OAAO,KAAK,IAAZ,IAAoB,OAAO,KAAK,IAApC,EAA0C;AACzC,WAAO,KAAP;AACA,GAbqD,CAetD;;;AACA,MAAI,sBAAO,OAAP,MAAmB,QAAnB,IAA+B,sBAAO,OAAP,MAAmB,QAAtD,EAAgE;AAC/D,QAAI,KAAK,GAAG,MAAM,CAAC,IAAP,CAAY,OAAZ,CAAZ;AACA,QAAI,KAAK,GAAG,MAAM,CAAC,IAAP,CAAY,OAAZ,CAAZ;;AACA,QAAI,KAAK,CAAC,MAAN,KAAiB,KAAK,CAAC,MAA3B,EAAmC;AAClC,aAAO,KAAP;AACA;;AACD,WAAO,KAAK,CAAC,KAAN,CAAY,UAAA,GAAG;AAAA,aAAI,MAAM,CAAC,OAAO,CAAC,GAAD,CAAR,EAAe,OAAO,CAAC,GAAD,CAAtB,CAAV;AAAA,KAAf,CAAP;AACA,GAvBqD,CAyBtD;;;AACA,SAAO,OAAO,KAAK,OAAnB;AACA;AAED;;;;;;;;;;AAQO,SAAS,KAAT,GAAwC;AAAA,MAAzB,MAAyB,uEAAhB,EAAgB;;AAAA,oCAAT,OAAS;AAAT,IAAA,OAAS;AAAA;;AAE9C,EAAA,OAAO,CAAC,OAAR,CAAgB,UAAA,MAAM,EAAI;AACzB,QAAI,MAAJ,EAAY;AACX,MAAA,MAAM,CAAC,IAAP,CAAY,MAAZ,EAAoB,OAApB,CAA4B,UAAA,GAAG,EAAI;AAClC,YAAI,WAAW,GAAG,MAAM,CAAC,GAAD,CAAxB;AACA,YAAI,WAAW,GAAG,MAAM,CAAC,GAAD,CAAxB;AACA,QAAA,MAAM,CAAC,GAAD,CAAN,GAAc,WAAW,YAAY,MAAvB,IAAiC,WAAW,YAAY,MAAxD,GACb,KAAK,CAAC,WAAD,EAAc,WAAd,CADQ,GAEb,WAFD;AAGA,OAND;AAOA;AACD,GAVD;AAWA,SAAO,MAAP;AACA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBO,SAAS,QAAT,CAAkB,MAAlB,EAA0B,IAA1B,EAAgC;AAEtC,SAAO,IAAI,CAAC,KAAL,CAAW,GAAX,EAAgB,MAAhB,CAAuB,UAAC,aAAD,EAAgB,SAAhB,EAA8B;AAC3D,WAAO,aAAa,IAAI,aAAa,CAAC,SAAD,CAArC;AACA,GAFM,EAEJ,MAFI,CAAP;AAGA","file":"object-utils.cjs.js","sourcesContent":["/* \n * Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Deep-equality comparison between 2 objects on whether they contain the same\n * values as each other. Only works with objects that act as data structures,\n * not classes or the like as this function only compares primitives using\n * identity (`===`) comparison.\n * \n * @param {*} object1\n * @param {*} object2\n * @return {Boolean}\n */\nexport function equals(object1 = null, object2 = null) {\n\n\t// Identity\n\tif (object1 === object2) {\n\t\treturn true;\n\t}\n\n\t// One argument null and the other isn't\n\tif (object1 === null && object2 !== null) {\n\t\treturn false;\n\t}\n\tif (object1 !== null && object2 === null) {\n\t\treturn false;\n\t}\n\n\t// Compare objects\n\tif (typeof object1 === 'object' && typeof object2 === 'object') {\n\t\tlet keys1 = Object.keys(object1);\n\t\tlet keys2 = Object.keys(object2);\n\t\tif (keys1.length !== keys2.length) {\n\t\t\treturn false;\n\t\t}\n\t\treturn keys1.every(key => equals(object1[key], object2[key]));\n\t}\n\n\t// Compare primitives\n\treturn object1 === object2;\n}\n\n/**\n * Deep-merges all of the properties of the objects in `sources` with `target`,\n * modifying the target object and returning it.\n * \n * @param {Object} target\n * @param {...Object} sources\n * @return {Object} The modified target object.\n */\nexport function merge(target = {}, ...sources) {\n\n\tsources.forEach(source => {\n\t\tif (source) {\n\t\t\tObject.keys(source).forEach(key => {\n\t\t\t\tlet targetValue = target[key];\n\t\t\t\tlet sourceValue = source[key];\n\t\t\t\ttarget[key] = targetValue instanceof Object && sourceValue instanceof Object ?\n\t\t\t\t\tmerge(targetValue, sourceValue) :\n\t\t\t\t\tsourceValue;\n\t\t\t});\n\t\t}\n\t});\n\treturn target;\n}\n\n/**\n * Returns a value from an object via a path string that describes the nesting\n * of objects to get to the value.\n * \n * eg:\n * \n * ```\n * let object = {\n * greeting: {\n * message: 'Hello!'\n * }\n * };\n * let pathToMessage = 'greeting.message';\n * ```\n * \n * > This is now natively in JavaScript as the optional chaining operator (`?.`).\n * > If you have access to that feature, I suggest you use that instead. If you\n * > don't, then this method will still do the job 🙂\n * \n * @param {Object} object\n * @param {String} path A dot-separated path string to get to the desired value\n * within the object\n * @return {Object} The value at the given path within the object, or\n * `undefined` if the path doesn't resolve within the object.\n */\nexport function navigate(object, path) {\n\n\treturn path.split('.').reduce((previousValue, pathToken) => {\n\t\treturn previousValue && previousValue[pathToken];\n\t}, object);\n}\n"]}
{"version":3,"file":"object-utils.cjs.js","names":["equals","object1","object2","_typeof2","keys1","Object","keys","keys2","length","every","key","merge","target","arguments","undefined","_len","sources","Array","_key","forEach","source","targetValue","sourceValue","navigate","object","path","split","reduce","previousValue","pathToken"],"sources":["object-utils.js"],"sourcesContent":["/* \n * Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Deep-equality comparison between 2 objects on whether they contain the same\n * values as each other. Only works with objects that act as data structures,\n * not classes or the like as this function only compares primitives using\n * identity (`===`) comparison.\n * \n * @param {any} object1\n * @param {any} object2\n * @return {boolean}\n */\nexport function equals(object1, object2) {\n\n\t// Identity\n\tif (object1 === object2) {\n\t\treturn true;\n\t}\n\n\t// Compare objects\n\tif (typeof object1 === 'object' && typeof object2 === 'object') {\n\t\tlet keys1 = Object.keys(object1);\n\t\tlet keys2 = Object.keys(object2);\n\t\treturn keys1.length === keys2.length && keys1.every(key => equals(object1[key], object2[key]));\n\t}\n\n\t// Compare primitives\n\treturn object1 === object2;\n}\n\n/**\n * Deep-merges all of the properties of the objects in `sources` with `target`,\n * modifying the target object and returning it.\n * \n * @param {object} target\n * @param {...object} sources\n * @return {object} The modified target object.\n */\nexport function merge(target = {}, ...sources) {\n\n\tsources.forEach(source => {\n\t\tif (source) {\n\t\t\tObject.keys(source).forEach(key => {\n\t\t\t\tlet targetValue = target[key];\n\t\t\t\tlet sourceValue = source[key];\n\t\t\t\ttarget[key] = targetValue instanceof Object && sourceValue instanceof Object ?\n\t\t\t\t\tmerge(targetValue, sourceValue) :\n\t\t\t\t\tsourceValue;\n\t\t\t});\n\t\t}\n\t});\n\treturn target;\n}\n\n/**\n * Returns a value from an object via a path string that describes the nesting\n * of objects to get to the value.\n * \n * eg:\n * \n * ```\n * let object = {\n * greeting: {\n * message: 'Hello!'\n * }\n * };\n * let pathToMessage = 'greeting.message';\n * ```\n * \n * > The null-safe nature of this method is now in JavaScript as the optional\n * > chaining operator (`?.`). If you're not using string paths/selectors to\n * > the item in your object, then I suggest you use that instead. Otherwise,\n * > if you're using string path selectors or can't use that method because of\n * > browser support, this method will still do the job 🙂\n * \n * @param {object} object\n * @param {string} path A dot-separated path string to get to the desired value\n * within the object\n * @return {object} The value at the given path within the object, or\n * `undefined` if the path doesn't resolve within the object.\n */\nexport function navigate(object, path) {\n\n\treturn path.split('.').reduce((previousValue, pathToken) => {\n\t\treturn previousValue && previousValue[pathToken];\n\t}, object);\n}\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,MAAMA,CAACC,OAAO,EAAEC,OAAO,EAAE;EAExC;EACA,IAAID,OAAO,KAAKC,OAAO,EAAE;IACxB,OAAO,IAAI;EACZ;;EAEA;EACA,IAAI,IAAAC,QAAA,aAAOF,OAAO,MAAK,QAAQ,IAAI,IAAAE,QAAA,aAAOD,OAAO,MAAK,QAAQ,EAAE;IAC/D,IAAIE,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACL,OAAO,CAAC;IAChC,IAAIM,KAAK,GAAGF,MAAM,CAACC,IAAI,CAACJ,OAAO,CAAC;IAChC,OAAOE,KAAK,CAACI,MAAM,KAAKD,KAAK,CAACC,MAAM,IAAIJ,KAAK,CAACK,KAAK,CAAC,UAAAC,GAAG;MAAA,OAAIV,MAAM,CAACC,OAAO,CAACS,GAAG,CAAC,EAAER,OAAO,CAACQ,GAAG,CAAC,CAAC;IAAA,EAAC;EAC/F;;EAEA;EACA,OAAOT,OAAO,KAAKC,OAAO;AAC3B;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SA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 * Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)

*
* @param {*} object1
* @param {*} object2
* @return {Boolean}
* @param {any} object1
* @param {any} object2
* @return {boolean}
*/
export function equals() {
var object1 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var object2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
export function equals(object1, object2) {
// Identity
if (object1 === object2) {
return true;
} // One argument null and the other isn't
if (object1 === null && object2 !== null) {
return false;
}
if (object1 !== null && object2 === null) {
return false;
} // Compare objects
// Compare objects
if (_typeof(object1) === 'object' && _typeof(object2) === 'object') {
var keys1 = Object.keys(object1);
var keys2 = Object.keys(object2);
if (keys1.length !== keys2.length) {
return false;
}
return keys1.every(function (key) {
return keys1.length === keys2.length && keys1.every(function (key) {
return equals(object1[key], object2[key]);
});
} // Compare primitives
}
// Compare primitives
return object1 === object2;
}
/**

@@ -69,14 +52,11 @@ * Deep-merges all of the properties of the objects in `sources` with `target`,

*
* @param {Object} target
* @param {...Object} sources
* @return {Object} The modified target object.
* @param {object} target
* @param {...object} sources
* @return {object} The modified target object.
*/
export function merge() {
var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
sources[_key - 1] = arguments[_key];
}
sources.forEach(function (source) {

@@ -93,2 +73,3 @@ if (source) {

}
/**

@@ -109,13 +90,14 @@ * Returns a value from an object via a path string that describes the nesting

*
* > This is now natively in JavaScript as the optional chaining operator (`?.`).
* > If you have access to that feature, I suggest you use that instead. If you
* > don't, then this method will still do the job 🙂
* > The null-safe nature of this method is now in JavaScript as the optional
* > chaining operator (`?.`). If you're not using string paths/selectors to
* > the item in your object, then I suggest you use that instead. Otherwise,
* > if you're using string path selectors or can't use that method because of
* > browser support, this method will still do the job 🙂
*
* @param {Object} object
* @param {String} path A dot-separated path string to get to the desired value
* @param {object} object
* @param {string} path A dot-separated path string to get to the desired value
* within the object
* @return {Object} The value at the given path within the object, or
* @return {object} The value at the given path within the object, or
* `undefined` if the path doesn't resolve within the object.
*/
export function navigate(object, path) {

@@ -122,0 +104,0 @@ return path.split('.').reduce(function (previousValue, pathToken) {

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

{"version":3,"sources":["object-utils.js"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;;;AAgBA;;;;;;;;;;AAUA,OAAO,SAAS,MAAT,GAAgD;AAAA,MAAhC,OAAgC,uEAAtB,IAAsB;AAAA,MAAhB,OAAgB,uEAAN,IAAM;;AAEtD;AACA,MAAI,OAAO,KAAK,OAAhB,EAAyB;AACxB,WAAO,IAAP;AACA,GALqD,CAOtD;;;AACA,MAAI,OAAO,KAAK,IAAZ,IAAoB,OAAO,KAAK,IAApC,EAA0C;AACzC,WAAO,KAAP;AACA;;AACD,MAAI,OAAO,KAAK,IAAZ,IAAoB,OAAO,KAAK,IAApC,EAA0C;AACzC,WAAO,KAAP;AACA,GAbqD,CAetD;;;AACA,MAAI,QAAO,OAAP,MAAmB,QAAnB,IAA+B,QAAO,OAAP,MAAmB,QAAtD,EAAgE;AAC/D,QAAI,KAAK,GAAG,MAAM,CAAC,IAAP,CAAY,OAAZ,CAAZ;AACA,QAAI,KAAK,GAAG,MAAM,CAAC,IAAP,CAAY,OAAZ,CAAZ;;AACA,QAAI,KAAK,CAAC,MAAN,KAAiB,KAAK,CAAC,MAA3B,EAAmC;AAClC,aAAO,KAAP;AACA;;AACD,WAAO,KAAK,CAAC,KAAN,CAAY,UAAA,GAAG;AAAA,aAAI,MAAM,CAAC,OAAO,CAAC,GAAD,CAAR,EAAe,OAAO,CAAC,GAAD,CAAtB,CAAV;AAAA,KAAf,CAAP;AACA,GAvBqD,CAyBtD;;;AACA,SAAO,OAAO,KAAK,OAAnB;AACA;AAED;;;;;;;;;AAQA,OAAO,SAAS,KAAT,GAAwC;AAAA,MAAzB,MAAyB,uEAAhB,EAAgB;;AAAA,oCAAT,OAAS;AAAT,IAAA,OAAS;AAAA;;AAE9C,EAAA,OAAO,CAAC,OAAR,CAAgB,UAAA,MAAM,EAAI;AACzB,QAAI,MAAJ,EAAY;AACX,MAAA,MAAM,CAAC,IAAP,CAAY,MAAZ,EAAoB,OAApB,CAA4B,UAAA,GAAG,EAAI;AAClC,YAAI,WAAW,GAAG,MAAM,CAAC,GAAD,CAAxB;AACA,YAAI,WAAW,GAAG,MAAM,CAAC,GAAD,CAAxB;AACA,QAAA,MAAM,CAAC,GAAD,CAAN,GAAc,WAAW,YAAY,MAAvB,IAAiC,WAAW,YAAY,MAAxD,GACb,KAAK,CAAC,WAAD,EAAc,WAAd,CADQ,GAEb,WAFD;AAGA,OAND;AAOA;AACD,GAVD;AAWA,SAAO,MAAP;AACA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA,OAAO,SAAS,QAAT,CAAkB,MAAlB,EAA0B,IAA1B,EAAgC;AAEtC,SAAO,IAAI,CAAC,KAAL,CAAW,GAAX,EAAgB,MAAhB,CAAuB,UAAC,aAAD,EAAgB,SAAhB,EAA8B;AAC3D,WAAO,aAAa,IAAI,aAAa,CAAC,SAAD,CAArC;AACA,GAFM,EAEJ,MAFI,CAAP;AAGA","file":"object-utils.es.js","sourcesContent":["/* \n * Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Deep-equality comparison between 2 objects on whether they contain the same\n * values as each other. Only works with objects that act as data structures,\n * not classes or the like as this function only compares primitives using\n * identity (`===`) comparison.\n * \n * @param {*} object1\n * @param {*} object2\n * @return {Boolean}\n */\nexport function equals(object1 = null, object2 = null) {\n\n\t// Identity\n\tif (object1 === object2) {\n\t\treturn true;\n\t}\n\n\t// One argument null and the other isn't\n\tif (object1 === null && object2 !== null) {\n\t\treturn false;\n\t}\n\tif (object1 !== null && object2 === null) {\n\t\treturn false;\n\t}\n\n\t// Compare objects\n\tif (typeof object1 === 'object' && typeof object2 === 'object') {\n\t\tlet keys1 = Object.keys(object1);\n\t\tlet keys2 = Object.keys(object2);\n\t\tif (keys1.length !== keys2.length) {\n\t\t\treturn false;\n\t\t}\n\t\treturn keys1.every(key => equals(object1[key], object2[key]));\n\t}\n\n\t// Compare primitives\n\treturn object1 === object2;\n}\n\n/**\n * Deep-merges all of the properties of the objects in `sources` with `target`,\n * modifying the target object and returning it.\n * \n * @param {Object} target\n * @param {...Object} sources\n * @return {Object} The modified target object.\n */\nexport function merge(target = {}, ...sources) {\n\n\tsources.forEach(source => {\n\t\tif (source) {\n\t\t\tObject.keys(source).forEach(key => {\n\t\t\t\tlet targetValue = target[key];\n\t\t\t\tlet sourceValue = source[key];\n\t\t\t\ttarget[key] = targetValue instanceof Object && sourceValue instanceof Object ?\n\t\t\t\t\tmerge(targetValue, sourceValue) :\n\t\t\t\t\tsourceValue;\n\t\t\t});\n\t\t}\n\t});\n\treturn target;\n}\n\n/**\n * Returns a value from an object via a path string that describes the nesting\n * of objects to get to the value.\n * \n * eg:\n * \n * ```\n * let object = {\n * greeting: {\n * message: 'Hello!'\n * }\n * };\n * let pathToMessage = 'greeting.message';\n * ```\n * \n * > This is now natively in JavaScript as the optional chaining operator (`?.`).\n * > If you have access to that feature, I suggest you use that instead. If you\n * > don't, then this method will still do the job 🙂\n * \n * @param {Object} object\n * @param {String} path A dot-separated path string to get to the desired value\n * within the object\n * @return {Object} The value at the given path within the object, or\n * `undefined` if the path doesn't resolve within the object.\n */\nexport function navigate(object, path) {\n\n\treturn path.split('.').reduce((previousValue, pathToken) => {\n\t\treturn previousValue && previousValue[pathToken];\n\t}, object);\n}\n"]}
{"version":3,"file":"object-utils.es.js","names":["equals","object1","object2","_typeof","keys1","Object","keys","keys2","length","every","key","merge","target","arguments","undefined","_len","sources","Array","_key","forEach","source","targetValue","sourceValue","navigate","object","path","split","reduce","previousValue","pathToken"],"sources":["object-utils.js"],"sourcesContent":["/* \n * Copyright 2017, Emanuel Rabina (http://www.ultraq.net.nz/)\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * Deep-equality comparison between 2 objects on whether they contain the same\n * values as each other. Only works with objects that act as data structures,\n * not classes or the like as this function only compares primitives using\n * identity (`===`) comparison.\n * \n * @param {any} object1\n * @param {any} object2\n * @return {boolean}\n */\nexport function equals(object1, object2) {\n\n\t// Identity\n\tif (object1 === object2) {\n\t\treturn true;\n\t}\n\n\t// Compare objects\n\tif (typeof object1 === 'object' && typeof object2 === 'object') {\n\t\tlet keys1 = Object.keys(object1);\n\t\tlet keys2 = Object.keys(object2);\n\t\treturn keys1.length === keys2.length && keys1.every(key => equals(object1[key], object2[key]));\n\t}\n\n\t// Compare primitives\n\treturn object1 === object2;\n}\n\n/**\n * Deep-merges all of the properties of the objects in `sources` with `target`,\n * modifying the target object and returning it.\n * \n * @param {object} target\n * @param {...object} sources\n * @return {object} The modified target object.\n */\nexport function merge(target = {}, ...sources) {\n\n\tsources.forEach(source => {\n\t\tif (source) {\n\t\t\tObject.keys(source).forEach(key => {\n\t\t\t\tlet targetValue = target[key];\n\t\t\t\tlet sourceValue = source[key];\n\t\t\t\ttarget[key] = targetValue instanceof Object && sourceValue instanceof Object ?\n\t\t\t\t\tmerge(targetValue, sourceValue) :\n\t\t\t\t\tsourceValue;\n\t\t\t});\n\t\t}\n\t});\n\treturn target;\n}\n\n/**\n * Returns a value from an object via a path string that describes the nesting\n * of objects to get to the value.\n * \n * eg:\n * \n * ```\n * let object = {\n * greeting: {\n * message: 'Hello!'\n * }\n * };\n * let pathToMessage = 'greeting.message';\n * ```\n * \n * > The null-safe nature of this method is now in JavaScript as the optional\n * > chaining operator (`?.`). If you're not using string paths/selectors to\n * > the item in your object, then I suggest you use that instead. Otherwise,\n * > if you're using string path selectors or can't use that method because of\n * > browser support, this method will still do the job 🙂\n * \n * @param {object} object\n * @param {string} path A dot-separated path string to get to the desired value\n * within the object\n * @return {object} The value at the given path within the object, or\n * `undefined` if the path doesn't resolve within the object.\n */\nexport function navigate(object, path) {\n\n\treturn path.split('.').reduce((previousValue, pathToken) => {\n\t\treturn previousValue && previousValue[pathToken];\n\t}, object);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,MAAMA,CAACC,OAAO,EAAEC,OAAO,EAAE;EAExC;EACA,IAAID,OAAO,KAAKC,OAAO,EAAE;IACxB,OAAO,IAAI;EACZ;;EAEA;EACA,IAAIC,OAAA,CAAOF,OAAO,MAAK,QAAQ,IAAIE,OAAA,CAAOD,OAAO,MAAK,QAAQ,EAAE;IAC/D,IAAIE,KAAK,GAAGC,MAAM,CAACC,IAAI,CAACL,OAAO,CAAC;IAChC,IAAIM,KAAK,GAAGF,MAAM,CAACC,IAAI,CAACJ,OAAO,CAAC;IAChC,OAAOE,KAAK,CAACI,MAAM,KAAKD,KAAK,CAACC,MAAM,IAAIJ,KAAK,CAACK,KAAK,CAAC,UAAAC,GAAG;MAAA,OAAIV,MAAM,CAACC,OAAO,CAACS,GAAG,CAAC,EAAER,OAAO,CAACQ,GAAG,CAAC,CAAC;IAAA,EAAC;EAC/F;;EAEA;EACA,OAAOT,OAAO,KAAKC,OA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,MAAM,CAAC;AACX"}

@@ -23,7 +23,7 @@ /*

*
* @param {*} object1
* @param {*} object2
* @return {Boolean}
* @param {any} object1
* @param {any} object2
* @return {boolean}
*/
export function equals(object1 = null, object2 = null) {
export function equals(object1, object2) {

@@ -35,10 +35,2 @@ // Identity

// One argument null and the other isn't
if (object1 === null && object2 !== null) {
return false;
}
if (object1 !== null && object2 === null) {
return false;
}
// Compare objects

@@ -48,6 +40,3 @@ if (typeof object1 === 'object' && typeof object2 === 'object') {

let keys2 = Object.keys(object2);
if (keys1.length !== keys2.length) {
return false;
}
return keys1.every(key => equals(object1[key], object2[key]));
return keys1.length === keys2.length && keys1.every(key => equals(object1[key], object2[key]));
}

@@ -63,5 +52,5 @@

*
* @param {Object} target
* @param {...Object} sources
* @return {Object} The modified target object.
* @param {object} target
* @param {...object} sources
* @return {object} The modified target object.
*/

@@ -99,10 +88,12 @@ export function merge(target = {}, ...sources) {

*
* > This is now natively in JavaScript as the optional chaining operator (`?.`).
* > If you have access to that feature, I suggest you use that instead. If you
* > don't, then this method will still do the job 🙂
* > The null-safe nature of this method is now in JavaScript as the optional
* > chaining operator (`?.`). If you're not using string paths/selectors to
* > the item in your object, then I suggest you use that instead. Otherwise,
* > if you're using string path selectors or can't use that method because of
* > browser support, this method will still do the job 🙂
*
* @param {Object} object
* @param {String} path A dot-separated path string to get to the desired value
* @param {object} object
* @param {string} path A dot-separated path string to get to the desired value
* within the object
* @return {Object} The value at the given path within the object, or
* @return {object} The value at the given path within the object, or
* `undefined` if the path doesn't resolve within the object.

@@ -109,0 +100,0 @@ */

@@ -23,3 +23,3 @@ /*

*/
describe('ObjectUtils', function() {
describe('object-utils', function() {

@@ -49,3 +49,3 @@ describe('#equals', function() {

let object2 = {
b: '1'
a: '1'
};

@@ -59,2 +59,5 @@ expect(equals(object1, object2)).toBe(false);

expect(equals(null, null)).toBe(true);
expect(equals(null, undefined)).toBe(false);
expect(equals({a: null}, {a: undefined})).toBe(false);
expect(equals(undefined, undefined)).toBe(true);
});

@@ -61,0 +64,0 @@ });

{
"name": "@ultraq/object-utils",
"version": "2.1.0",
"version": "3.0.0",
"description": "A collection of utilities for JavaScript objects",

@@ -19,2 +19,3 @@ "author": "Emanuel Rabina <emanuelrabina@gmail.com> (http://www.ultraq.net.nz/)",

"module": "object-utils.es.js",
"types": "object-utils.d.ts",
"sideEffects": false,

@@ -24,24 +25,26 @@ "scripts": {

"test": "jest",
"coverage": "cat ./coverage/lcov.info | coveralls",
"build": "npm run build:cjs && npm run build:es",
"build": "npm run build:cjs && npm run build:es && npm run build:dts",
"build:cjs": "BABEL_ENV=cjs babel object-utils.js --out-file object-utils.cjs.js --source-maps",
"build:es": "BABEL_ENV=es babel object-utils.js --out-file object-utils.es.js --source-maps",
"build:dts": "tsc --allowJs --declaration --emitDeclarationOnly object-utils.js",
"prepublishOnly": "npm run build"
},
"dependencies": {
"@babel/runtime": "^7.11.2"
"@babel/runtime": "^7.22.15"
},
"devDependencies": {
"@babel/core": "^7.9.6",
"@babel/cli": "^7.8.4",
"@babel/plugin-transform-runtime": "^7.11.0",
"@babel/preset-env": "^7.9.6",
"coveralls": "^3.1.0",
"eslint": "^6.8.0",
"eslint-config-ultraq": "^2.3.3",
"jest": "^25.5.4"
"@babel/core": "^7.22.20",
"@babel/cli": "^7.22.15",
"@babel/plugin-transform-runtime": "^7.22.15",
"@babel/preset-env": "^7.22.20",
"@types/jest": "^29.5.5",
"eslint": "^8.49.0",
"eslint-config-ultraq": "^3.1.1",
"eslint-plugin-jsdoc": "^46.8.2",
"jest": "^29.7.0",
"typescript": "^5.2.2"
},
"engines": {
"node": ">=8"
"node": ">=18"
}
}

@@ -5,4 +5,4 @@

[![Build Status](https://travis-ci.com/ultraq/object-utils.svg?branch=master)](https://travis-ci.com/ultraq/object-utils)
[![Coverage Status](https://coveralls.io/repos/github/ultraq/object-utils/badge.svg?branch=master)](https://coveralls.io/github/ultraq/object-utils?branch=master)
[![Build Status](https://github.com/ultraq/object-utils/actions/workflows/build.yml/badge.svg)](https://github.com/ultraq/object-utils/actions)
[![codecov](https://codecov.io/gh/ultraq/object-utils/branch/master/graph/badge.svg?token=whGWdtrpdC)](https://codecov.io/gh/ultraq/object-utils)
[![npm](https://img.shields.io/npm/v/@ultraq/object-utils.svg?maxAge=3600)](https://www.npmjs.com/package/@ultraq/object-utils)

@@ -45,5 +45,7 @@ [![Bundlephobia minified size](https://img.shields.io/bundlephobia/min/@ultraq/object-utils)](https://bundlephobia.com/result?p=@ultraq/object-utils)

> This is now natively in JavaScript as the optional chaining operator (`?.`).
> If you have access to that feature, I suggest you use that instead. If you
> don't, then this method will still do the job 🙂
> The null-safe nature of this method is now in JavaScript as the optional
> chaining operator (`?.`). If you're not using string paths/selectors to the
> item in your object, then I suggest you use that instead. Otherwise, if
> you're using string path selectors or can't use that method because of browser
> support, this method will still do the job 🙂

@@ -50,0 +52,0 @@ Returns a value from an object via a path string that describes the nesting of