Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@umijs/route-utils

Package Overview
Dependencies
Maintainers
14
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@umijs/route-utils - npm Package Compare versions

Comparing version 1.0.37 to 2.0.0

0

dist/getFlatMenus/getFlatMenus.d.ts

@@ -0,0 +0,0 @@ import { MenuDataItem } from '../types';

4

dist/getFlatMenus/getFlatMenus.js

@@ -17,4 +17,4 @@ import { stripQueryStringAndHashFromPath } from '../transformRoute/transformRoute';

menus[item.key || item.path || '/'] = { ...item };
if (item.children) {
menus = { ...menus, ...getFlatMenus(item.children) };
if (item.routes) {
menus = { ...menus, ...getFlatMenus(item.routes) };
}

@@ -21,0 +21,0 @@ });

@@ -0,0 +0,0 @@ import type { MenuDataItem } from '../types';

@@ -0,0 +0,0 @@ import { pathToRegexp } from '@qixian.cs/path-to-regexp';

@@ -0,0 +0,0 @@ import { MenuDataItem } from './types';

@@ -0,0 +0,0 @@ export { default as transformRoute } from './transformRoute/transformRoute';

declare function digest(data: string): String;
export default digest;

@@ -0,0 +0,0 @@ /* eslint-disable no-redeclare */

@@ -0,0 +0,0 @@ import { MenuDataItem, Route, MessageDescriptor } from '../types';

@@ -64,3 +64,3 @@ import isEqual from 'fast-deep-equal/es6/index';

const bigfishCompatibleConversions = (route, props) => {
const { menu = {}, indexRoute, path = '', children } = route;
const { menu = {}, indexRoute, path = '', routers } = route;
const { name = route.name, icon = route.icon, hideChildren = route.hideChildren, flatMenu = route.flatMenu, } = menu; // 兼容平铺式写法

@@ -77,4 +77,4 @@ // 拼接 childrenRoutes, 处理存在 indexRoute 时的逻辑

},
].concat(children || [])
: children;
].concat(routers || [])
: routers;
// 拼接返回的 menu 数据

@@ -93,7 +93,7 @@ const result = {

if (hideChildren) {
delete result.children;
delete result.routers;
return result;
}
// 需要重新进行一次
const routers = formatter({
const finRouters = formatter({
...props,

@@ -104,5 +104,5 @@ data: childrenRoutes,

if (flatMenu) {
return routers;
return finRouters;
}
result.children = routers;
result.routers = finRouters;
}

@@ -125,3 +125,3 @@ return result;

return false;
if (item.routes || item.children)
if (item.routes)
return true;

@@ -165,3 +165,3 @@ if (item.path)

// eslint-disable-next-line @typescript-eslint/naming-convention
pro_layout_parentKeys = [], children, icon, flatMenu, indexRoute, ...restParent } = parent;
pro_layout_parentKeys = [], routers, icon, flatMenu, indexRoute, ...restParent } = parent;
const finallyItem = {

@@ -174,3 +174,2 @@ ...restParent,

key: item.key || getKeyByPath({ ...item, path }),
routes: null,
pro_layout_parentKeys: Array.from(new Set([

@@ -191,15 +190,15 @@ ...(item.parentKeys || []),

}
if (item.routes || item.children) {
if (item.routes) {
const formatterChildren = formatter({
...props,
data: item.routes || item.children,
data: item.routes,
parentName: locale || '',
}, finallyItem);
// Reduce memory usage
finallyItem.children =
finallyItem.routes =
formatterChildren && formatterChildren.length > 0
? formatterChildren
: undefined;
if (!finallyItem.children) {
delete finallyItem.children;
if (!finallyItem.routes) {
delete finallyItem.routes;
}

@@ -217,15 +216,15 @@ }

.filter((item) => item &&
(item.name || item.children) &&
(item.name || item.routes) &&
!item.hideInMenu &&
!item.redirect)
.map((item) => {
if (item.children &&
Array.isArray(item.children) &&
if (item.routes &&
Array.isArray(item.routes) &&
!item.hideChildrenInMenu &&
item.children.some((child) => child && !!child.name)) {
const children = defaultFilterMenuData(item.children);
if (children.length)
return { ...item, children };
item.routes.some((child) => child && !!child.name)) {
const routes = defaultFilterMenuData(item.routes);
if (routes.length)
return { ...item, routes };
}
return { ...item, children: undefined };
return { ...item, routes: undefined };
})

@@ -265,4 +264,4 @@ .filter((item) => item);

data.forEach((menuItem) => {
if (menuItem && menuItem.children) {
flattenMenuData(menuItem.children, menuItem);
if (menuItem && menuItem.routes) {
flattenMenuData(menuItem.routes, menuItem);
}

@@ -281,11 +280,9 @@ // Reduce memory usage

.map((item) => {
if (item.children &&
Array.isArray(item.children) &&
item.children.length > 0) {
const children = clearChildren(item.children);
if (children.length)
return { ...item, children };
if (item.routes && Array.isArray(item.routes) && item.routes.length > 0) {
const routes = clearChildren(item.routes);
if (routes.length)
return { ...item, routes };
}
const finallyItem = { ...item };
delete finallyItem.children;
delete finallyItem.routes;
return finallyItem;

@@ -292,0 +289,0 @@ })

@@ -10,3 +10,3 @@ export interface Route extends MenuDataItem {

export interface MenuDataItem {
children?: MenuDataItem[];
routes?: MenuDataItem[];
hideChildrenInMenu?: boolean;

@@ -13,0 +13,0 @@ hideInMenu?: boolean;

@@ -25,4 +25,4 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

if (item.children) {
menus = _objectSpread(_objectSpread({}, menus), getFlatMenus(item.children));
if (item.routes) {
menus = _objectSpread(_objectSpread({}, menus), getFlatMenus(item.routes));
}

@@ -29,0 +29,0 @@ });

@@ -140,3 +140,3 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

path = _route$path === void 0 ? '' : _route$path,
children = route.children;
routers = route.routers;
var _menu$name = menu.name,

@@ -156,3 +156,3 @@ name = _menu$name === void 0 ? route.name : _menu$name,

menu: menu
}, indexRoute)].concat(children || []) : children; // 拼接返回的 menu 数据
}, indexRoute)].concat(routers || []) : routers; // 拼接返回的 menu 数据

@@ -172,3 +172,3 @@ var result = _objectSpread({}, route);

if (hideChildren) {
delete result.children;
delete result.routers;
return result;

@@ -178,3 +178,3 @@ } // 需要重新进行一次

var routers = formatter(_objectSpread(_objectSpread({}, props), {}, {
var finRouters = formatter(_objectSpread(_objectSpread({}, props), {}, {
data: childrenRoutes

@@ -185,6 +185,6 @@ }), route);

if (flatMenu) {
return routers;
return finRouters;
}
result.children = routers;
result.routers = finRouters;
}

@@ -216,3 +216,3 @@

if (!item) return false;
if (item.routes || item.children) return true;
if (item.routes) return true;
if (item.path) return true;

@@ -260,7 +260,7 @@ if (item.layout) return true; // 重定向

pro_layout_parentKeys = _parent$pro_layout_pa === void 0 ? [] : _parent$pro_layout_pa,
children = parent.children,
routers = parent.routers,
icon = parent.icon,
flatMenu = parent.flatMenu,
indexRoute = parent.indexRoute,
restParent = _objectWithoutProperties(parent, ["pro_layout_parentKeys", "children", "icon", "flatMenu", "indexRoute"]);
restParent = _objectWithoutProperties(parent, ["pro_layout_parentKeys", "routers", "icon", "flatMenu", "indexRoute"]);

@@ -275,3 +275,2 @@ var finallyItem = _objectSpread(_objectSpread(_objectSpread({}, restParent), {}, {

})),
routes: null,
pro_layout_parentKeys: Array.from(new Set([].concat(_toConsumableArray(item.parentKeys || []), _toConsumableArray(pro_layout_parentKeys), ["/".concat(parent.key || '').replace(/\/\//g, '/').replace(/\/\//g, '/')]))).filter(function (key) {

@@ -292,12 +291,12 @@ return key && key !== '/';

if (item.routes || item.children) {
if (item.routes) {
var formatterChildren = formatter(_objectSpread(_objectSpread({}, props), {}, {
data: item.routes || item.children,
data: item.routes,
parentName: locale || ''
}), finallyItem); // Reduce memory usage
finallyItem.children = formatterChildren && formatterChildren.length > 0 ? formatterChildren : undefined;
finallyItem.routes = formatterChildren && formatterChildren.length > 0 ? formatterChildren : undefined;
if (!finallyItem.children) {
delete finallyItem.children;
if (!finallyItem.routes) {
delete finallyItem.routes;
}

@@ -318,10 +317,10 @@ }

return menuData.filter(function (item) {
return item && (item.name || item.children) && !item.hideInMenu && !item.redirect;
return item && (item.name || item.routes) && !item.hideInMenu && !item.redirect;
}).map(function (item) {
if (item.children && Array.isArray(item.children) && !item.hideChildrenInMenu && item.children.some(function (child) {
if (item.routes && Array.isArray(item.routes) && !item.hideChildrenInMenu && item.routes.some(function (child) {
return child && !!child.name;
})) {
var children = defaultFilterMenuData(item.children);
if (children.length) return _objectSpread(_objectSpread({}, item), {}, {
children: children
var routes = defaultFilterMenuData(item.routes);
if (routes.length) return _objectSpread(_objectSpread({}, item), {}, {
routes: routes
});

@@ -331,3 +330,3 @@ }

return _objectSpread(_objectSpread({}, item), {}, {
children: undefined
routes: undefined
});

@@ -404,4 +403,4 @@ }).filter(function (item) {

data.forEach(function (menuItem) {
if (menuItem && menuItem.children) {
flattenMenuData(menuItem.children, menuItem);
if (menuItem && menuItem.routes) {
flattenMenuData(menuItem.routes, menuItem);
} // Reduce memory usage

@@ -424,6 +423,6 @@

return menuData.map(function (item) {
if (item.children && Array.isArray(item.children) && item.children.length > 0) {
var children = clearChildren(item.children);
if (children.length) return _objectSpread(_objectSpread({}, item), {}, {
children: children
if (item.routes && Array.isArray(item.routes) && item.routes.length > 0) {
var routes = clearChildren(item.routes);
if (routes.length) return _objectSpread(_objectSpread({}, item), {}, {
routes: routes
});

@@ -434,3 +433,3 @@ }

delete finallyItem.children;
delete finallyItem.routes;
return finallyItem;

@@ -437,0 +436,0 @@ }).filter(function (item) {

@@ -32,4 +32,4 @@ "use strict";

if (item.children) {
menus = _objectSpread(_objectSpread({}, menus), getFlatMenus(item.children));
if (item.routes) {
menus = _objectSpread(_objectSpread({}, menus), getFlatMenus(item.routes));
}

@@ -36,0 +36,0 @@ });

@@ -161,3 +161,3 @@ "use strict";

path = _route$path === void 0 ? '' : _route$path,
children = route.children;
routers = route.routers;
var _menu$name = menu.name,

@@ -177,3 +177,3 @@ name = _menu$name === void 0 ? route.name : _menu$name,

menu: menu
}, indexRoute)].concat(children || []) : children; // 拼接返回的 menu 数据
}, indexRoute)].concat(routers || []) : routers; // 拼接返回的 menu 数据

@@ -193,3 +193,3 @@ var result = _objectSpread({}, route);

if (hideChildren) {
delete result.children;
delete result.routers;
return result;

@@ -199,3 +199,3 @@ } // 需要重新进行一次

var routers = formatter(_objectSpread(_objectSpread({}, props), {}, {
var finRouters = formatter(_objectSpread(_objectSpread({}, props), {}, {
data: childrenRoutes

@@ -206,6 +206,6 @@ }), route);

if (flatMenu) {
return routers;
return finRouters;
}
result.children = routers;
result.routers = finRouters;
}

@@ -237,3 +237,3 @@

if (!item) return false;
if (item.routes || item.children) return true;
if (item.routes) return true;
if (item.path) return true;

@@ -281,7 +281,7 @@ if (item.layout) return true; // 重定向

pro_layout_parentKeys = _parent$pro_layout_pa === void 0 ? [] : _parent$pro_layout_pa,
children = parent.children,
routers = parent.routers,
icon = parent.icon,
flatMenu = parent.flatMenu,
indexRoute = parent.indexRoute,
restParent = _objectWithoutProperties(parent, ["pro_layout_parentKeys", "children", "icon", "flatMenu", "indexRoute"]);
restParent = _objectWithoutProperties(parent, ["pro_layout_parentKeys", "routers", "icon", "flatMenu", "indexRoute"]);

@@ -296,3 +296,2 @@ var finallyItem = _objectSpread(_objectSpread(_objectSpread({}, restParent), {}, {

})),
routes: null,
pro_layout_parentKeys: Array.from(new Set([].concat(_toConsumableArray(item.parentKeys || []), _toConsumableArray(pro_layout_parentKeys), ["/".concat(parent.key || '').replace(/\/\//g, '/').replace(/\/\//g, '/')]))).filter(function (key) {

@@ -313,12 +312,12 @@ return key && key !== '/';

if (item.routes || item.children) {
if (item.routes) {
var formatterChildren = formatter(_objectSpread(_objectSpread({}, props), {}, {
data: item.routes || item.children,
data: item.routes,
parentName: locale || ''
}), finallyItem); // Reduce memory usage
finallyItem.children = formatterChildren && formatterChildren.length > 0 ? formatterChildren : undefined;
finallyItem.routes = formatterChildren && formatterChildren.length > 0 ? formatterChildren : undefined;
if (!finallyItem.children) {
delete finallyItem.children;
if (!finallyItem.routes) {
delete finallyItem.routes;
}

@@ -339,10 +338,10 @@ }

return menuData.filter(function (item) {
return item && (item.name || item.children) && !item.hideInMenu && !item.redirect;
return item && (item.name || item.routes) && !item.hideInMenu && !item.redirect;
}).map(function (item) {
if (item.children && Array.isArray(item.children) && !item.hideChildrenInMenu && item.children.some(function (child) {
if (item.routes && Array.isArray(item.routes) && !item.hideChildrenInMenu && item.routes.some(function (child) {
return child && !!child.name;
})) {
var children = defaultFilterMenuData(item.children);
if (children.length) return _objectSpread(_objectSpread({}, item), {}, {
children: children
var routes = defaultFilterMenuData(item.routes);
if (routes.length) return _objectSpread(_objectSpread({}, item), {}, {
routes: routes
});

@@ -352,3 +351,3 @@ }

return _objectSpread(_objectSpread({}, item), {}, {
children: undefined
routes: undefined
});

@@ -425,4 +424,4 @@ }).filter(function (item) {

data.forEach(function (menuItem) {
if (menuItem && menuItem.children) {
flattenMenuData(menuItem.children, menuItem);
if (menuItem && menuItem.routes) {
flattenMenuData(menuItem.routes, menuItem);
} // Reduce memory usage

@@ -445,6 +444,6 @@

return menuData.map(function (item) {
if (item.children && Array.isArray(item.children) && item.children.length > 0) {
var children = clearChildren(item.children);
if (children.length) return _objectSpread(_objectSpread({}, item), {}, {
children: children
if (item.routes && Array.isArray(item.routes) && item.routes.length > 0) {
var routes = clearChildren(item.routes);
if (routes.length) return _objectSpread(_objectSpread({}, item), {}, {
routes: routes
});

@@ -455,3 +454,3 @@ }

delete finallyItem.children;
delete finallyItem.routes;
return finallyItem;

@@ -458,0 +457,0 @@ }).filter(function (item) {

{
"name": "@umijs/route-utils",
"version": "1.0.37",
"version": "2.0.0",
"description": "Quickly process the routing of umi",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

![](https://codecov.io/gh/umijs/route-utils/branch/master/graph/badge.svg) [![npm package](https://img.shields.io/npm/v/@umijs/route-utils.svg?style=flat-square?style=flat-square)](https://www.npmjs.com/package/@umijs/route-utils)
# @umijs/route-utils

@@ -17,6 +18,3 @@

```tsx
import {
transformRoute,
getMatchMenu,
} from '@umijs/route-utils';
import { transformRoute, getMatchMenu } from '@umijs/route-utils';

@@ -52,3 +50,3 @@ const routes = [

export interface MenuDataItem {
children?: MenuDataItem[];
routes?: MenuDataItem[];
hideChildrenInMenu?: boolean;

@@ -55,0 +53,0 @@ hideInMenu?: boolean;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc