libraries/tracking-core/helpers/formatHelpers.js
function get(object, path, defaultValue) {
  // Initialize the parameters
  const data = object || {};
  const dataPath = path || '';
  const defaultReturnValue = defaultValue;

  // Get the segments of the path
  const pathSegments = dataPath.split('.');

  if (!dataPath || !pathSegments.length) {
    // No path or path segments where determinable - return the default value
    return defaultReturnValue;
  }

  /**
   * Recursive callable function to traverse through a complex object
   *
   * @param {Object} currentData The current data that shall be investigated
   * @param {number} currentPathSegmentIndex The current index within the path segment list
   * @returns {*} The value at the end of the path or the default one
   */
  function checkPathSegment(currentData, currentPathSegmentIndex) {
    // Get the current segment within the path
    const currentPathSegment = pathSegments[currentPathSegmentIndex];
    const nextPathSegmentIndex = currentPathSegmentIndex + 1;

    /**
     * Prepare the default value as return value for the case that no matching property was
     * found for the current path segment. In that case the path must be wrong.
     */
    let result = defaultReturnValue;

    if (currentData && currentData.hasOwnProperty(currentPathSegment)) {
      if (
        typeof currentData[currentPathSegment] !== 'object' ||
        pathSegments.length === nextPathSegmentIndex
      ) {
        // A final value was found
        result = currentData[currentPathSegment];
      } else {
        // The value at the current step within the path is another object. Traverse through it
        result = checkPathSegment(currentData[currentPathSegment], nextPathSegmentIndex);
      }
    }

    return result;
  }

  // Start traversing the path within the data object
  return checkPathSegment(data, 0);
}
function get(object, path, defaultValue) {
  // Initialize the parameters
  const data = object || {};
  const dataPath = path || '';
  const defaultReturnValue = defaultValue;

  // Get the segments of the path
  const pathSegments = dataPath.split('.');

  if (!dataPath || !pathSegments.length) {
    // No path or path segments where determinable - return the default value
    return defaultReturnValue;
  }

  /**
   * Recursive callable function to traverse through a complex object
   *
   * @param {Object} currentData The current data that shall be investigated
   * @param {number} currentPathSegmentIndex The current index within the path segment list
   * @returns {*} The value at the end of the path or the default one
   */
  function checkPathSegment(currentData, currentPathSegmentIndex) {
    // Get the current segment within the path
    const currentPathSegment = pathSegments[currentPathSegmentIndex];
    const nextPathSegmentIndex = currentPathSegmentIndex + 1;

    /**
     * Prepare the default value as return value for the case that no matching property was
     * found for the current path segment. In that case the path must be wrong.
     */
    let result = defaultReturnValue;

    if (currentData && currentData.hasOwnProperty(currentPathSegment)) {
      if (
        typeof currentData[currentPathSegment] !== 'object' ||
        pathSegments.length === nextPathSegmentIndex
      ) {
        // A final value was found
        result = currentData[currentPathSegment];
      } else {
        // The value at the current step within the path is another object. Traverse through it
        result = checkPathSegment(currentData[currentPathSegment], nextPathSegmentIndex);
      }
    }

    return result;
  }

  // Start traversing the path within the data object
  return checkPathSegment(data, 0);
}
function get ( object , path , defaultValue ) { // Initialize the parameters const data = object || { } ; const dataPath = path || '' ; const defaultReturnValue = defaultValue ; // Get the segments of the path const pathSegments = dataPath . split ( '.' ) ; if ( ! dataPath || ! pathSegments . length ) { // No path or path segments where determinable - return the default value return defaultReturnValue ; } /**
   * Recursive callable function to traverse through a complex object
   *
   * @param {Object} currentData The current data that shall be investigated
   * @param {number} currentPathSegmentIndex The current index within the path segment list
   * @returns {*} The value at the end of the path or the default one
   */ function checkPathSegment ( currentData , currentPathSegmentIndex ) { // Get the current segment within the path const currentPathSegment = pathSegments [ currentPathSegmentIndex ] ; const nextPathSegmentIndex = currentPathSegmentIndex + 1 ; /**
     * Prepare the default value as return value for the case that no matching property was
     * found for the current path segment. In that case the path must be wrong.
     */ let result = defaultReturnValue ; if ( currentData && currentData . hasOwnProperty ( currentPathSegment ) ) { if ( typeof currentData [ currentPathSegment ] !== 'object' || pathSegments . length === nextPathSegmentIndex ) { // A final value was found result = currentData [ currentPathSegment ] ; } else { // The value at the current step within the path is another object. Traverse through it result = checkPathSegment ( currentData [ currentPathSegment ] , nextPathSegmentIndex ) ; } } return result ; } // Start traversing the path within the data object return checkPathSegment ( data , 0 ) ; }
Gets the value at path of object. If the resolved value is undefined,
the defaultValue is used in its place.

@param {Object} object The object to query
@param {string} path The path of the property to get
@param {*} [defaultValue] The value returned for undefined resolved values
@returns {*} Returns the resolved value
Gets the value at path of object . If the resolved value is undefined the defaultValue is used in its place .