ut2
Version:
一个现代 JavaScript 实用工具库。[点击查看在线文档]。
28 lines (24 loc) • 1.03 kB
JavaScript
;
var tslib = require('tslib');
var isIndex = require('./internals/isIndex.js');
var native = require('./internals/native.js');
var isArray = require('./isArray.js');
var isObject = require('./isObject.js');
var set = require('./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(native.nativeUndefined, firstPairPath[0], native.nativeUndefined) : native.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 = tslib.__read(pathPair, 2), paths = _a[0], val = _a[1];
set(result, paths, val, customizer);
}
}
return result;
}
module.exports = fromPathPairs;