Files
FrenoCorp/node_modules/fast-stable-stringify/util/object-path.js
Michael Freno 7c684a42cc FRE-600: Fix code review blockers
- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-25 00:08:01 -04:00

47 lines
1.3 KiB
JavaScript

/**
* Returns the element within root under the path given by pathSegments.
* @param {Object} root
* @param {string[]} pathSegments
* @param {boolean} [appendIfMissing=false] - all objects are created if they do not exist
* @returns {Object} - the object under the path. If appendIsMissing is false and the path does not exist, returns null
*/
module.exports.getObject = function getObject(root, pathSegments, appendIfMissing) {
var target = root;
var pathSeg;
var i;
for (i = 0; i < pathSegments.length; i++) {
pathSeg = pathSegments[i];
if (!target.hasOwnProperty(pathSeg)) {
if (appendIfMissing) {
target[pathSeg] = {};
} else {
return null;
}
}
target = target[pathSeg];
}
return target;
};
/**
* Writes the object to the path in root. Overwrites if an object exists.
* Note: root is edited in place!
* @param {Object} root
* @param {string[]} pathSegments
* @param {Object} obj
*/
module.exports.setObject = function setObject(root, pathSegments, obj) {
var target = root;
var pathSeg;
var i;
var max = pathSegments.length;
for (i = 0; i < max; i++) {
pathSeg = pathSegments[i];
if (i === max - 1) {
target[pathSeg] = obj;
} else if (!target.hasOwnProperty(pathSeg)) {
target[pathSeg] = {};
}
target = target[pathSeg];
}
};