UNPKG

@txdfe/at

Version:

一个设计体系组件库

55 lines (43 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.statics = exports.fetchDataByPath = void 0; var blackList = ['defaultProps', 'propTypes', 'contextTypes', 'childContextTypes', 'displayName']; var statics = function statics(Target, Component) { Object.keys(Component).forEach(function (property) { if (blackList.indexOf(property) === -1) { Target[property] = Component[property]; } }); }; exports.statics = statics; var fetchDataByPath = function fetchDataByPath(object, path) { if (!object || !path) { return false; } path = path.toString(); var field = path.split('.'); var val, key; if (field.length) { key = field[0]; // lists[1].name if (key.indexOf('[') >= 0) { key = key.match(/(.*)\[(.*)\]/); if (key) { val = object[key[1]][key[2]]; } } else { val = object[field[0]]; } if (val) { for (var colIndex = 1; colIndex < field.length; colIndex++) { val = val[field[colIndex]]; if (typeof val === 'undefined') { break; } } } } return val; }; exports.fetchDataByPath = fetchDataByPath;