"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _ = require("lodash");
/**
 * Resolves the given local data path against the root data.
 *
 * @param rootData the root data to resolve the data from
 * @param path The path to resolve against the root data
 * @return the resolved data or {null} if the path is not a valid path in the root data
 */
exports.resolveLocalData = function (rootData, path) {
    var resolvedData = rootData;
    for (var _i = 0, _a = path.split('/'); _i < _a.length; _i++) {
        var segment = _a[_i];
        if (segment === '#' || _.isEmpty(segment)) {
            continue;
        }
        if (_.isEmpty(resolvedData) || !resolvedData.hasOwnProperty(segment)) {
            console.warn("The local path '" + path + "' cannot be resolved in the given data:", rootData);
            return null;
        }
        resolvedData = _.get(resolvedData, segment);
    }
    return resolvedData;
};
/**
 * Extract the array index from the given path.
 */
exports.indexFromPath = function (path) {
    return parseInt(_.last(path.split('.')), 10);
};
/**
 * Gets the parent path from the given path by cutting of the last segment
 *
 * @param path The path to get the parent path from
 */
exports.parentPath = function (path) {
    return path.substring(0, path.lastIndexOf('.'));
};
//# sourceMappingURL=util.js.map