@instana/core
Version:
Core library for Instana's Node.js packages
25 lines (22 loc) • 457 B
JavaScript
/*
* (c) Copyright IBM Corp. 2022
*/
;
/**
* mkdir -p for objects.
*
* @param {Object} object
* @param {Array.<string>} pathInObject
*/
module.exports = function ensureNestedObjectExists(object, pathInObject) {
const [head, ...tail] = pathInObject;
// @ts-ignore
if (!object[head]) {
// @ts-ignore
object[head] = {};
}
if (tail.length >= 1) {
// @ts-ignore
ensureNestedObjectExists(object[head], tail);
}
};