lei-jia-utils
Version:
78 lines (74 loc) • 5.15 kB
JavaScript
/*
* ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
* This devtool is neither made for production nor for readable output files.
* It uses "eval()" calls to create a separate source file in the browser devtools.
* If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
* or disable the default devtool with "devtool: false".
* If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["jiaUtils"] = factory();
else
root["jiaUtils"] = factory();
})(self, function() {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/index.js":
/*!**********************!*\
!*** ./src/index.js ***!
\**********************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"hello\": () => (/* binding */ hello),\n/* harmony export */ \"deepClone\": () => (/* binding */ deepClone),\n/* harmony export */ \"uniqueArr\": () => (/* binding */ uniqueArr),\n/* harmony export */ \"listToTreeUper\": () => (/* binding */ listToTreeUper),\n/* harmony export */ \"listToTreeLower\": () => (/* binding */ listToTreeLower)\n/* harmony export */ });\nfunction hello() {\r\n console.log('hello, dujiajia')\r\n}\r\n\r\nfunction deepClone(source) {\r\n if (!source && typeof source !== 'object') {\r\n throw new Error('error arguments', 'deepClone')\r\n }\r\n const targetObj = source.constructor === Array ? [] : {}\r\n Object.keys(source).forEach(keys => {\r\n if (source[keys] && typeof source[keys] === 'object') {\r\n targetObj[keys] = deepClone(source[keys])\r\n } else {\r\n targetObj[keys] = source[keys]\r\n }\r\n })\r\n return targetObj\r\n}\r\n\r\nfunction uniqueArr(arr) {\r\n return Array.from(new Set(arr))\r\n}\r\n\r\nfunction listToTreeUper(ParentId, all) {\r\n let tree = []\r\n let arr = all\r\n arr.forEach(item => {\r\n if (item.ParentId == ParentId) {\r\n if (listToTree(item.Id, arr).length > 0) {\r\n // 递归如果存在children设置children\r\n item.Children = listToTree(item.Id, arr)\r\n }\r\n // 取出最顶层的 放到一个新的数组中 \r\n tree.push(item)\r\n }\r\n })\r\n return tree\r\n}\r\n\r\nfunction listToTreeLower(parentId, all) {\r\n let tree = []\r\n let arr = all\r\n arr.forEach(item => {\r\n if (item.parentId == parentId) {\r\n if (listToTree(item.id, arr).length > 0) {\r\n // 递归如果存在children设置children\r\n item.children = listToTree(item.id, arr)\r\n }\r\n // 取出最顶层的 放到一个新的数组中 \r\n tree.push(item)\r\n }\r\n })\r\n return tree\r\n}\r\n\n\n//# sourceURL=webpack://jiaUtils/./src/index.js?");
/***/ })
/******/ });
/************************************************************************/
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module can't be inlined because the eval devtool is used.
/******/ var __webpack_exports__ = {};
/******/ __webpack_modules__["./src/index.js"](0, __webpack_exports__, __webpack_require__);
/******/
/******/ return __webpack_exports__;
/******/ })()
;
});