@nocobase/utils 1.6.21 → 1.6.23

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/lib/common.d.ts CHANGED
@@ -12,3 +12,14 @@ export declare const isEmpty: (value: unknown) => boolean;
12
12
  export declare const isPlainObject: (value: any) => boolean;
13
13
  export declare const hasEmptyValue: (objOrArr: object | any[]) => any;
14
14
  export declare const nextTick: (fn: () => void) => void;
15
+ /**
16
+ * 通用树节点深度优先遍历函数
17
+ * @param {Object|Array} tree - 要遍历的树结构
18
+ * @param {Function} callback - 遍历每个节点时执行的回调函数,返回真值时停止遍历并返回当前节点
19
+ * @param {Object} options - 配置选项
20
+ * @param {string|Function} options.childrenKey - 子节点的属性名,默认为'children',也可以是一个函数
21
+ * @returns {any|undefined} - 找到的节点或undefined
22
+ */
23
+ export declare function treeFind<T = any>(tree: T | T[], callback: (node: T) => boolean, options?: {
24
+ childrenKey?: string | ((node: T) => T[] | undefined);
25
+ }): T | undefined;
package/lib/common.js CHANGED
@@ -32,7 +32,8 @@ __export(common_exports, {
32
32
  isEmpty: () => isEmpty,
33
33
  isPlainObject: () => isPlainObject,
34
34
  isString: () => isString,
35
- nextTick: () => nextTick
35
+ nextTick: () => nextTick,
36
+ treeFind: () => treeFind
36
37
  });
37
38
  module.exports = __toCommonJS(common_exports);
38
39
  const isString = /* @__PURE__ */ __name((value) => {
@@ -76,6 +77,25 @@ const hasEmptyValue = /* @__PURE__ */ __name((objOrArr) => {
76
77
  const nextTick = /* @__PURE__ */ __name((fn) => {
77
78
  setTimeout(fn);
78
79
  }, "nextTick");
80
+ function treeFind(tree, callback, options = {}) {
81
+ if (!tree) return void 0;
82
+ const { childrenKey = "children" } = options;
83
+ const nodes = Array.isArray(tree) ? [...tree] : [tree];
84
+ for (const node of nodes) {
85
+ if (callback(node)) {
86
+ return node;
87
+ }
88
+ const children = typeof childrenKey === "function" ? childrenKey(node) : node[childrenKey];
89
+ if (Array.isArray(children) && children.length > 0) {
90
+ const found = treeFind(children, callback, options);
91
+ if (found !== void 0) {
92
+ return found;
93
+ }
94
+ }
95
+ }
96
+ return void 0;
97
+ }
98
+ __name(treeFind, "treeFind");
79
99
  // Annotate the CommonJS export names for ESM import in node:
80
100
  0 && (module.exports = {
81
101
  hasEmptyValue,
@@ -83,5 +103,6 @@ const nextTick = /* @__PURE__ */ __name((fn) => {
83
103
  isEmpty,
84
104
  isPlainObject,
85
105
  isString,
86
- nextTick
106
+ nextTick,
107
+ treeFind
87
108
  });
package/lib/date.js CHANGED
@@ -88,12 +88,13 @@ const toLocal = /* @__PURE__ */ __name((value) => {
88
88
  }
89
89
  }, "toLocal");
90
90
  const convertQuarterToFirstDay = /* @__PURE__ */ __name((quarterStr) => {
91
- if ((0, import_dayjs.dayjs)(quarterStr).isValid()) {
91
+ try {
92
92
  const year = parseInt(quarterStr.slice(0, 4));
93
93
  const quarter = parseInt(quarterStr.slice(-1));
94
94
  return (0, import_dayjs.dayjs)().quarter(quarter).year(year);
95
+ } catch (error) {
96
+ return null;
95
97
  }
96
- return null;
97
98
  }, "convertQuarterToFirstDay");
98
99
  const toMoment = /* @__PURE__ */ __name((val, options) => {
99
100
  if (!val) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "1.6.21",
3
+ "version": "1.6.23",
4
4
  "main": "lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "license": "AGPL-3.0",
@@ -13,8 +13,8 @@
13
13
  "flat-to-nested": "^1.1.1",
14
14
  "graphlib": "^2.1.8",
15
15
  "handlebars": "^4.7.8",
16
- "multer": "^1.4.5-lts.1",
16
+ "multer": "^1.4.5-lts.2",
17
17
  "object-path": "^0.11.8"
18
18
  },
19
- "gitHead": "2538df7c081e1bb558acead3f0cd87b6a7f02c78"
19
+ "gitHead": "2ec917c09dc303978bdd33893d27c775d532c8f9"
20
20
  }