UNPKG

ut2

Version:

一个现代 JavaScript 实用工具库。[点击查看在线文档]。

26 lines (23 loc) 991 B
import { __read } from 'tslib'; import isIndex from './internals/isIndex.js'; import { nativeUndefined } from './internals/native.js'; import isArray from './isArray.js'; import isObject from './isObject.js'; import set from './set.js'; function fromPathPairs(value, customizer) { var valueIsArray = isArray(value); var firstPairPath = valueIsArray && isArray(value[0]) && isArray(value[0][0]) ? value[0][0] : []; var firstNode = customizer ? customizer(nativeUndefined, firstPairPath[0], nativeUndefined) : nativeUndefined; var result = isObject(firstNode) ? firstNode : isIndex(firstPairPath[0]) ? [] : {}; var length = valueIsArray ? value.length : 0; var index = -1; while (++index < length) { var pathPair = value[index]; if (isArray(pathPair)) { var _a = __read(pathPair, 2), paths = _a[0], val = _a[1]; set(result, paths, val, customizer); } } return result; } export { fromPathPairs as default };