UNPKG

flo-utils

Version:
44 lines (35 loc) 908 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; /** * @name getValueByPath * @param {any} entity * @param {any} path a.b.c.d * @param {string} [defaultValue=""] * @returns * @description 通过路径获取数据 */ function getValueByPath(entity, path) { var defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '-'; var props = path; if (typeof props === 'string') { props = props.split('.').filter(function (d) { return d; }); } var current = entity; for (var i = 0; i < props.length; i += 1) { if (current === null || current === undefined) { return defaultValue; } current = current[props[i]]; } if (current === null || current === undefined) { return defaultValue; } return current; } var _default = getValueByPath; exports.default = _default;