1 line
9.6 KiB
JSON
1 line
9.6 KiB
JSON
|
{"ast":null,"code":"import _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _toArray from \"@babel/runtime/helpers/esm/toArray\";\nimport get from \"./get\";\nfunction internalSet(entity, paths, value, removeIfUndefined) {\n if (!paths.length) {\n return value;\n }\n var _paths = _toArray(paths),\n path = _paths[0],\n restPath = _paths.slice(1);\n var clone;\n if (!entity && typeof path === 'number') {\n clone = [];\n } else if (Array.isArray(entity)) {\n clone = _toConsumableArray(entity);\n } else {\n clone = _objectSpread({}, entity);\n }\n\n // Delete prop if `removeIfUndefined` and value is undefined\n if (removeIfUndefined && value === undefined && restPath.length === 1) {\n delete clone[path][restPath[0]];\n } else {\n clone[path] = internalSet(clone[path], restPath, value, removeIfUndefined);\n }\n return clone;\n}\nexport default function set(entity, paths, value) {\n var removeIfUndefined = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;\n // Do nothing if `removeIfUndefined` and parent object not exist\n if (paths.length && removeIfUndefined && value === undefined && !get(entity, paths.slice(0, -1))) {\n return entity;\n }\n return internalSet(entity, paths, value, removeIfUndefined);\n}\nfunction isObject(obj) {\n return _typeof(obj) === 'object' && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;\n}\nfunction createEmpty(source) {\n return Array.isArray(source) ? [] : {};\n}\nvar keys = typeof Reflect === 'undefined' ? Object.keys : Reflect.ownKeys;\n\n/**\n * Merge objects which will create\n */\nexport function merge() {\n for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) {\n sources[_key] = arguments[_key];\n }\n var clone = createEmpty(sources[0]);\n sources.forEach(function (src) {\n function internalMerge(path, parentLoopSet) {\n var loopSet = new Set(parentLoopSet);\n var value = get(src, path);\n var isArr = Array.isArray(value);\n if (isArr || isObject(value)) {\n // Only add not loop obj\n if (!loopSet.has(value)) {\n loopSet.add(value);\n var originValue = get(clone, path);\n if (isArr) {\n // Array will always be override\n clone = set(clone, path, []);\n } else if (!originValue || _typeof(originValue) !== 'object') {\n // Init container if not exist\n clone = set(clone, path, createEmpty(value));\n }\n keys(value).forEach(function (key) {\n internalMerge([].concat(_toConsumableArray(path), [key]), loopSet);\n });\n }\n } else {\n clone = set(clone, path, value);\n }\n }\n internalMerge([]);\n });\n return clone;\n}","map":{"version":3,"names":["_typeof","_objectSpread","_toConsumableArray","_toArray","get","internalSet","entity","paths","value","removeIfUndefined","length","_paths","path","restPath","slice","clone","Array","isArray","undefined","set","arguments","isObject","obj","Object","getPrototypeOf","prototype","createEmpty","source","keys","Reflect","ownKeys","merge","_len","sources","_key","forEach","src","internalMerge","parentLoopSet","loopSet","Set","isArr","has","add","originValue","key","concat"],"sources":["C:/Users/Аришина)/Desktop/promo/node_modules/rc-util/es/utils/set.js"],"sourcesContent":["import _typeof from \"@babel/runtime/helpers/esm/typeof\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport _toArray from \"@babel/runtime/helpers/esm/toArray\";\nimport get from \"./get\";\nfunction internalSet(entity, paths, value, removeIfUndefined) {\n if (!paths.length) {\n return value;\n }\n var _paths = _toArray(paths),\n path = _paths[0],\n restPath = _paths.slice(1);\
|