"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getResByPath = exports.isPath = exports.parseJsonStr = exports.getDataType = void 0;
function getDataType(data) {
    if (Array.isArray(data)) {
        if (data.length) {
            var item = data[0];
            if (Array.isArray(item)) {
                return 'array-matrix';
            }
            return 'array-obj';
        }
        return 'array-empty';
    }
    if (typeof data === 'object') {
        return 'object';
    }
    return 'unknown';
}
exports.getDataType = getDataType;
function parseJsonStr(str) {
    var jsonObj = null;
    try {
        jsonObj = JSON.parse(str);
    }
    catch (e) {
        jsonObj = null;
    }
    return jsonObj;
}
exports.parseJsonStr = parseJsonStr;
function isPath(str) {
    return str.startsWith('.');
}
exports.isPath = isPath;
function getResByPath(data, path) {
    var pathArr = path.split('.');
    pathArr.shift();
    var lastPath = '';
    var getCurPathRes = function (target, deep) {
        var curPath = pathArr[deep];
        if (curPath === '*') {
            if (!Array.isArray(target)) {
                console.error("wecharts: The data path is not compatible with the graph data, ".concat(lastPath, ".* is not a Array."));
                return null;
            }
            lastPath = curPath;
            return target.map(function (item) { return getCurPathRes(item, deep + 1); });
        }
        if (deep < pathArr.length - 1) {
            if (!target[curPath]) {
                console.error("wecharts: The data path is not compatible with the graph data, ".concat(lastPath, ".").concat(curPath, " is undefined."));
                return null;
            }
            lastPath = curPath;
            return getCurPathRes(target[curPath], deep + 1);
        }
        return target[curPath];
    };
    return getCurPathRes(data, 0);
}
exports.getResByPath = getResByPath;
//# sourceMappingURL=utils.js.map