Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@supertenant/core / src / util / ensureNestedObjectExists.js
Size: Mime:
/*
 * (c) Copyright IBM Corp. 2022
 */

'use strict';

/**
 * 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);
  }
};