@ruan-cat/utils 4.3.0 → 4.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruan-cat/utils",
3
- "version": "4.3.0",
3
+ "version": "4.3.2",
4
4
  "description": "阮喵喵工具集合。默认提供js文件,也直接提供ts文件。",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -78,13 +78,13 @@
78
78
  "typedoc-plugin-frontmatter": "^1.3.0",
79
79
  "typedoc-plugin-markdown": "^4.5.0",
80
80
  "typescript": "^5.8.2",
81
- "unplugin-vue-router": "^0.11.2",
81
+ "unplugin-vue-router": "^0.12.0",
82
82
  "vite-plugin-autogeneration-import-file": "^3.0.0",
83
83
  "vitepress": "^1.6.3"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "typescript": "5.7.3",
87
- "unplugin-vue-router": "^0.10.0",
87
+ "unplugin-vue-router": "^0.12.0",
88
88
  "vite-plugin-autogeneration-import-file": ">=3"
89
89
  },
90
90
  "peerDependenciesMeta": {
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import type { RouteRecordRaw } from "vue-router";
11
11
  import { omit } from "lodash-es";
12
+ import { consola } from "consola";
12
13
 
13
14
  /**
14
15
  * 处理单个路由,包括处理空路径子路由和拼接完整路径
@@ -67,3 +68,38 @@ export function disposalAutoRouter(routes: RouteRecordRaw[]): RouteRecordRaw[] {
67
68
  // 处理所有顶级路由
68
69
  return routes.map((route) => processRoute(route));
69
70
  }
71
+
72
+ /**
73
+ * 打印自动路由信息(支持嵌套,完整打印每层对象)
74
+ * @param routes 路由对象或数组
75
+ * @param level 当前缩进层级(内部递归用)
76
+ * @description
77
+ * 一个辅助函数 帮助打印路由的信息
78
+ *
79
+ * @deprecated
80
+ * 废弃 不如直接json转换一次,输出效果还好。
81
+ * `JSON.stringify(result, null, 2)`
82
+ */
83
+ export function printAutoRouter(routes: RouteRecordRaw[] | RouteRecordRaw, level = 0): void {
84
+ const indent = (n: number) => " ".repeat(n);
85
+
86
+ const printOne = (route: RouteRecordRaw, lvl: number) => {
87
+ const prefix = indent(lvl);
88
+ // console.log(`${prefix}Route Level ${lvl}`);
89
+ console.warn(prefix + JSON.stringify(route, null, 2));
90
+ if (route.children && route.children.length > 0) {
91
+ // console.log(`${prefix}children:`);
92
+ route.children.forEach((child) => printOne(child, lvl + 1));
93
+ }
94
+ };
95
+
96
+ if (Array.isArray(routes)) {
97
+ // console.log("打印路由数组...");
98
+ routes.forEach((route) => printOne(route, level));
99
+ // console.log("打印结束");
100
+ } else {
101
+ // console.log("打印单个路由...");
102
+ printOne(routes, level);
103
+ // console.log("打印结束");
104
+ }
105
+ }
@@ -1,3 +1,5 @@
1
+ export * from "./disposal-auto-router";
2
+
1
3
  import { type Options } from "unplugin-vue-router";
2
4
 
3
5
  type GetRouteName = NonNullable<Options["getRouteName"]>;