123456789101112131415161718192021222324252627282930313233343536373839 |
- const hasOwnProperty = Object.prototype.hasOwnProperty;
- export function hasOwn(obj, key) {
- return hasOwnProperty.call(obj, key);
- };
- function extend(to, _from) {
- for (let key in _from) {
- to[key] = _from[key];
- }
- return to;
- };
- export function toObject(arr) {
- var res = {};
- for (let i = 0; i < arr.length; i++) {
- if (arr[i]) {
- extend(res, arr[i]);
- }
- }
- return res;
- };
- export const getValueByPath = function(object, prop) {
- prop = prop || '';
- const paths = prop.split('.');
- let current = object;
- let result = null;
- for (let i = 0, j = paths.length; i < j; i++) {
- const path = paths[i];
- if (!current) break;
- if (i === j - 1) {
- result = current[path];
- break;
- }
- current = current[path];
- }
- return result;
- };
|