@nocobase/utils 1.7.0-beta.9 → 1.8.0-beta.1

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/assign.js CHANGED
@@ -53,8 +53,14 @@ function getKeys(target) {
53
53
  }
54
54
  __name(getKeys, "getKeys");
55
55
  const mergeStrategies = /* @__PURE__ */ new Map();
56
- mergeStrategies.set("overwrite", (_, y) => {
57
- if (typeof y === "string") {
56
+ mergeStrategies.set("overwrite", (x, y) => {
57
+ if (y === void 0) {
58
+ if (typeof x === "string" && x.includes(",")) {
59
+ return x.split(",");
60
+ }
61
+ return x;
62
+ }
63
+ if (typeof y === "string" && y.includes(",")) {
58
64
  y = y.split(",");
59
65
  }
60
66
  return y;
@@ -123,15 +129,22 @@ mergeStrategies.set(
123
129
  })().filter(Boolean)
124
130
  );
125
131
  function assign(target, source, strategies = {}) {
126
- getKeys(source).forEach((sourceKey) => {
132
+ const sourceKeys = getKeys(source);
133
+ const targetKeys = getKeys(target);
134
+ import_lodash.default.uniq([...sourceKeys, ...targetKeys]).forEach((sourceKey) => {
127
135
  const strategy = strategies[sourceKey];
128
- let func = mergeStrategies.get("deepMerge");
136
+ let func;
129
137
  if (typeof strategy === "function") {
130
138
  func = strategy;
131
139
  } else if (typeof strategy === "string" && mergeStrategies.has(strategy)) {
132
140
  func = mergeStrategies.get(strategy);
133
141
  }
134
- target[sourceKey] = func(target[sourceKey], source[sourceKey]);
142
+ if (func) {
143
+ target[sourceKey] = func(target[sourceKey], source[sourceKey]);
144
+ } else if (sourceKeys.includes(sourceKey)) {
145
+ const func2 = mergeStrategies.get("deepMerge");
146
+ target[sourceKey] = func2(target[sourceKey], source[sourceKey]);
147
+ }
135
148
  });
136
149
  return target;
137
150
  }
package/lib/client.d.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import lodash from 'lodash';
10
10
  import { dayjs } from './dayjs';
11
+ import { getDayRangeByParams, getOffsetRangeByParams } from './dateRangeUtils';
11
12
  export * from './collections-graph';
12
13
  export * from './common';
13
14
  export * from './date';
@@ -28,4 +29,4 @@ export * from './parseHTML';
28
29
  export * from './uid';
29
30
  export * from './url';
30
31
  export * from './transformMultiColumnToSingleColumn';
31
- export { dayjs, lodash };
32
+ export { dayjs, lodash, getDayRangeByParams, getOffsetRangeByParams };
package/lib/client.js CHANGED
@@ -38,11 +38,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
38
38
  var client_exports = {};
39
39
  __export(client_exports, {
40
40
  dayjs: () => import_dayjs.dayjs,
41
+ getDayRangeByParams: () => import_dateRangeUtils.getDayRangeByParams,
42
+ getOffsetRangeByParams: () => import_dateRangeUtils.getOffsetRangeByParams,
41
43
  lodash: () => import_lodash.default
42
44
  });
43
45
  module.exports = __toCommonJS(client_exports);
44
46
  var import_lodash = __toESM(require("lodash"));
45
47
  var import_dayjs = require("./dayjs");
48
+ var import_dateRangeUtils = require("./dateRangeUtils");
46
49
  __reExport(client_exports, require("./collections-graph"), module.exports);
47
50
  __reExport(client_exports, require("./common"), module.exports);
48
51
  __reExport(client_exports, require("./date"), module.exports);
@@ -66,6 +69,8 @@ __reExport(client_exports, require("./transformMultiColumnToSingleColumn"), modu
66
69
  // Annotate the CommonJS export names for ESM import in node:
67
70
  0 && (module.exports = {
68
71
  dayjs,
72
+ getDayRangeByParams,
73
+ getOffsetRangeByParams,
69
74
  lodash,
70
75
  ...require("./collections-graph"),
71
76
  ...require("./common"),
package/lib/common.d.ts CHANGED
@@ -12,3 +12,23 @@ 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
+ * Generic tree node depth-first traversal function
17
+ * @param {Object|Array} tree - The tree structure to traverse
18
+ * @param {Function} callback - The callback function executed for each node, stops traversing and returns the current node when a truthy value is returned
19
+ * @param {Object} options - Configuration options
20
+ * @param {string|Function} options.childrenKey - The property name of child nodes, defaults to 'children', can also be a function
21
+ * @returns {any|undefined} - The found node or 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;
26
+ /**
27
+ * Sort a tree structure
28
+ * @param {Array} tree - Tree structure array
29
+ * @param {string|Function} sortBy - Sort field or sort function
30
+ * @param {string} childrenKey - The key name of child nodes, defaults to 'children'
31
+ * @param {boolean} isAsc - Whether to sort in ascending order, defaults to true
32
+ * @returns {Array} - The sorted tree structure
33
+ */
34
+ export declare function sortTree(tree: any[], sortBy: string | Function, childrenKey?: string, isAsc?: boolean): any;
package/lib/common.js CHANGED
@@ -7,9 +7,11 @@
7
7
  * For more information, please refer to: https://www.nocobase.com/agreement.
8
8
  */
9
9
 
10
+ var __create = Object.create;
10
11
  var __defProp = Object.defineProperty;
11
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
13
  var __getOwnPropNames = Object.getOwnPropertyNames;
14
+ var __getProtoOf = Object.getPrototypeOf;
13
15
  var __hasOwnProp = Object.prototype.hasOwnProperty;
14
16
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
17
  var __export = (target, all) => {
@@ -24,6 +26,14 @@ var __copyProps = (to, from, except, desc) => {
24
26
  }
25
27
  return to;
26
28
  };
29
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
+ // If the importer is in node compatibility mode or this is not an ESM
31
+ // file that has been converted to a CommonJS file using a Babel-
32
+ // compatible transform (i.e. "__esModule" has not been set), then set
33
+ // "default" to the CommonJS "module.exports" for node compatibility.
34
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
+ mod
36
+ ));
27
37
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
38
  var common_exports = {};
29
39
  __export(common_exports, {
@@ -32,9 +42,12 @@ __export(common_exports, {
32
42
  isEmpty: () => isEmpty,
33
43
  isPlainObject: () => isPlainObject,
34
44
  isString: () => isString,
35
- nextTick: () => nextTick
45
+ nextTick: () => nextTick,
46
+ sortTree: () => sortTree,
47
+ treeFind: () => treeFind
36
48
  });
37
49
  module.exports = __toCommonJS(common_exports);
50
+ var import_lodash = __toESM(require("lodash"));
38
51
  const isString = /* @__PURE__ */ __name((value) => {
39
52
  return typeof value === "string";
40
53
  }, "isString");
@@ -76,6 +89,41 @@ const hasEmptyValue = /* @__PURE__ */ __name((objOrArr) => {
76
89
  const nextTick = /* @__PURE__ */ __name((fn) => {
77
90
  setTimeout(fn);
78
91
  }, "nextTick");
92
+ function treeFind(tree, callback, options = {}) {
93
+ if (!tree) return void 0;
94
+ const { childrenKey = "children" } = options;
95
+ const nodes = Array.isArray(tree) ? [...tree] : [tree];
96
+ for (const node of nodes) {
97
+ if (callback(node)) {
98
+ return node;
99
+ }
100
+ const children = typeof childrenKey === "function" ? childrenKey(node) : node[childrenKey];
101
+ if (Array.isArray(children) && children.length > 0) {
102
+ const found = treeFind(children, callback, options);
103
+ if (found !== void 0) {
104
+ return found;
105
+ }
106
+ }
107
+ }
108
+ return void 0;
109
+ }
110
+ __name(treeFind, "treeFind");
111
+ function sortTree(tree, sortBy, childrenKey = "children", isAsc = true) {
112
+ if (!tree || !Array.isArray(tree) || tree.length === 0) {
113
+ return tree;
114
+ }
115
+ const sortedTree = import_lodash.default.orderBy(tree, sortBy, isAsc ? "asc" : "desc");
116
+ return sortedTree.map((node) => {
117
+ if (node[childrenKey] && node[childrenKey].length > 0) {
118
+ return {
119
+ ...node,
120
+ [childrenKey]: sortTree(node[childrenKey], sortBy, childrenKey, isAsc)
121
+ };
122
+ }
123
+ return node;
124
+ });
125
+ }
126
+ __name(sortTree, "sortTree");
79
127
  // Annotate the CommonJS export names for ESM import in node:
80
128
  0 && (module.exports = {
81
129
  hasEmptyValue,
@@ -83,5 +131,7 @@ const nextTick = /* @__PURE__ */ __name((fn) => {
83
131
  isEmpty,
84
132
  isPlainObject,
85
133
  isString,
86
- nextTick
134
+ nextTick,
135
+ sortTree,
136
+ treeFind
87
137
  });
package/lib/date.d.ts CHANGED
@@ -35,5 +35,6 @@ export declare const moment2str: (value?: dayjs.Dayjs, options?: Moment2strOptio
35
35
  * from https://github.com/moment/moment/blob/dca02edaeceda3fcd52b20b51c130631a058a022/src/lib/units/offset.js#L55-L70
36
36
  */
37
37
  export declare function offsetFromString(string: string | number): number;
38
- export declare const getPickerFormat: (picker: any) => "YYYY-MM" | "YYYY" | "YYYY[W]W" | "YYYY-MM-DD" | "YYYY[Q]Q";
38
+ export declare const getPickerFormat: (picker: any) => "YYYY-MM-DD" | "YYYY-MM" | "YYYY" | "YYYY[Q]Q" | "YYYY[W]W";
39
39
  export declare const getDateTimeFormat: (picker: any, format: any, showTime: any, timeFormat: any) => any;
40
+ export declare function getFormatFromDateStr(dateStr: string): string | null;
package/lib/date.js CHANGED
@@ -39,6 +39,7 @@ var date_exports = {};
39
39
  __export(date_exports, {
40
40
  getDateTimeFormat: () => getDateTimeFormat,
41
41
  getDefaultFormat: () => getDefaultFormat,
42
+ getFormatFromDateStr: () => getFormatFromDateStr,
42
43
  getPickerFormat: () => getPickerFormat,
43
44
  moment2str: () => moment2str,
44
45
  offsetFromString: () => offsetFromString,
@@ -88,12 +89,13 @@ const toLocal = /* @__PURE__ */ __name((value) => {
88
89
  }
89
90
  }, "toLocal");
90
91
  const convertQuarterToFirstDay = /* @__PURE__ */ __name((quarterStr) => {
91
- if ((0, import_dayjs.dayjs)(quarterStr).isValid()) {
92
+ try {
92
93
  const year = parseInt(quarterStr.slice(0, 4));
93
94
  const quarter = parseInt(quarterStr.slice(-1));
94
95
  return (0, import_dayjs.dayjs)().quarter(quarter).year(year);
96
+ } catch (error) {
97
+ return null;
95
98
  }
96
- return null;
97
99
  }, "convertQuarterToFirstDay");
98
100
  const toMoment = /* @__PURE__ */ __name((val, options) => {
99
101
  if (!val) {
@@ -215,10 +217,21 @@ const getDateTimeFormat = /* @__PURE__ */ __name((picker, format, showTime, time
215
217
  }
216
218
  return format;
217
219
  }, "getDateTimeFormat");
220
+ function getFormatFromDateStr(dateStr) {
221
+ if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(dateStr)) return "YYYY-MM-DD HH:mm:ss";
222
+ if (/^\d{4}-\d{2}-\d{2}$/.test(dateStr)) return "YYYY-MM-DD";
223
+ if (/^\d{4}-\d{2}$/.test(dateStr)) return "YYYY-MM";
224
+ if (/^\d{4}$/.test(dateStr)) return "YYYY";
225
+ if (/^\d{4}Q[1-4]$/.test(dateStr)) return "YYYY[Q]Q";
226
+ if (/^\d{4}-\d{2}-\d{2}T/.test(dateStr)) return "YYYY-MM-DDTHH:mm:ss.SSSZ";
227
+ return null;
228
+ }
229
+ __name(getFormatFromDateStr, "getFormatFromDateStr");
218
230
  // Annotate the CommonJS export names for ESM import in node:
219
231
  0 && (module.exports = {
220
232
  getDateTimeFormat,
221
233
  getDefaultFormat,
234
+ getFormatFromDateStr,
222
235
  getPickerFormat,
223
236
  moment2str,
224
237
  offsetFromString,
@@ -0,0 +1,22 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+ type DateUnit = 'day' | 'week' | 'isoWeek' | 'month' | 'quarter' | 'year';
10
+ type RangeType = 'today' | 'yesterday' | 'tomorrow' | 'thisWeek' | 'lastWeek' | 'nextWeek' | 'thisMonth' | 'lastMonth' | 'nextMonth' | 'thisQuarter' | 'lastQuarter' | 'nextQuarter' | 'thisYear' | 'lastYear' | 'nextYear' | 'past' | 'next';
11
+ interface RangeParams {
12
+ type: RangeType;
13
+ unit?: DateUnit;
14
+ number?: number;
15
+ timezone?: string;
16
+ }
17
+ export declare const getOffsetRangeByParams: (params: RangeParams) => [string, string];
18
+ /**
19
+ * 获取某个时间范围的起止时间(字符串格式)
20
+ */
21
+ export declare const getDayRangeByParams: (params: RangeParams) => [string, string];
22
+ export {};
@@ -0,0 +1,101 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ var __defProp = Object.defineProperty;
11
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12
+ var __getOwnPropNames = Object.getOwnPropertyNames;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var dateRangeUtils_exports = {};
29
+ __export(dateRangeUtils_exports, {
30
+ getDayRangeByParams: () => getDayRangeByParams,
31
+ getOffsetRangeByParams: () => getOffsetRangeByParams
32
+ });
33
+ module.exports = __toCommonJS(dateRangeUtils_exports);
34
+ var import_dayjs2 = require("./dayjs");
35
+ const getNow = /* @__PURE__ */ __name((tz) => {
36
+ if (!tz) return (0, import_dayjs2.dayjs)();
37
+ if (/^[+-]\d{2}:\d{2}$/.test(tz)) {
38
+ const [sign, hour, minute] = tz.match(/([+-])(\d{2}):(\d{2})/).slice(1);
39
+ const offset = (parseInt(hour) * 60 + parseInt(minute)) * (sign === "+" ? 1 : -1);
40
+ return (0, import_dayjs2.dayjs)().utcOffset(offset);
41
+ }
42
+ return (0, import_dayjs2.dayjs)().tz(tz);
43
+ }, "getNow");
44
+ const getOffsetRangeByParams = /* @__PURE__ */ __name((params) => {
45
+ const { type, unit = "day", number = 1, timezone } = params;
46
+ const now = getNow(timezone);
47
+ const actualUnit = unit === "week" ? "isoWeek" : unit;
48
+ let start;
49
+ let end;
50
+ if (type === "past") {
51
+ const base = now.startOf(actualUnit);
52
+ start = base.subtract(number, unit).startOf(actualUnit);
53
+ end = base.subtract(1, unit).endOf(actualUnit);
54
+ } else if (type === "next") {
55
+ const base = now.startOf(actualUnit);
56
+ start = base.add(1, unit).startOf(actualUnit);
57
+ end = start.add(number - 1, unit).endOf(actualUnit);
58
+ } else {
59
+ throw new Error(`Unsupported type: ${type}`);
60
+ }
61
+ return [start.format("YYYY-MM-DD HH:mm:ss"), end.format("YYYY-MM-DD HH:mm:ss")];
62
+ }, "getOffsetRangeByParams");
63
+ const getStart = /* @__PURE__ */ __name((offset, unit, tz) => {
64
+ const actualUnit = unit === "isoWeek" ? "week" : unit;
65
+ return getNow(tz).add(offset, actualUnit).startOf(unit);
66
+ }, "getStart");
67
+ const getEnd = /* @__PURE__ */ __name((offset, unit, tz) => {
68
+ const actualUnit = unit === "isoWeek" ? "week" : unit;
69
+ return getNow(tz).add(offset, actualUnit).endOf(unit);
70
+ }, "getEnd");
71
+ const strategies = {
72
+ today: /* @__PURE__ */ __name((params) => [getStart(0, "day", params == null ? void 0 : params.timezone), getEnd(0, "day", params == null ? void 0 : params.timezone)], "today"),
73
+ yesterday: /* @__PURE__ */ __name((params) => [getStart(-1, "day", params == null ? void 0 : params.timezone), getEnd(-1, "day", params == null ? void 0 : params.timezone)], "yesterday"),
74
+ tomorrow: /* @__PURE__ */ __name((params) => [getStart(1, "day", params == null ? void 0 : params.timezone), getEnd(1, "day", params == null ? void 0 : params.timezone)], "tomorrow"),
75
+ thisWeek: /* @__PURE__ */ __name((params) => [getStart(0, "isoWeek", params == null ? void 0 : params.timezone), getEnd(0, "isoWeek", params == null ? void 0 : params.timezone)], "thisWeek"),
76
+ lastWeek: /* @__PURE__ */ __name((params) => [getStart(-1, "isoWeek", params == null ? void 0 : params.timezone), getEnd(-1, "isoWeek", params == null ? void 0 : params.timezone)], "lastWeek"),
77
+ nextWeek: /* @__PURE__ */ __name((params) => [getStart(1, "isoWeek", params == null ? void 0 : params.timezone), getEnd(1, "isoWeek", params == null ? void 0 : params.timezone)], "nextWeek"),
78
+ thisMonth: /* @__PURE__ */ __name((params) => [getStart(0, "month", params == null ? void 0 : params.timezone), getEnd(0, "month", params == null ? void 0 : params.timezone)], "thisMonth"),
79
+ lastMonth: /* @__PURE__ */ __name((params) => [getStart(-1, "month", params == null ? void 0 : params.timezone), getEnd(-1, "month", params == null ? void 0 : params.timezone)], "lastMonth"),
80
+ nextMonth: /* @__PURE__ */ __name((params) => [getStart(1, "month", params == null ? void 0 : params.timezone), getEnd(1, "month", params == null ? void 0 : params.timezone)], "nextMonth"),
81
+ thisQuarter: /* @__PURE__ */ __name((params) => [getStart(0, "quarter", params == null ? void 0 : params.timezone), getEnd(0, "quarter", params == null ? void 0 : params.timezone)], "thisQuarter"),
82
+ lastQuarter: /* @__PURE__ */ __name((params) => [getStart(-1, "quarter", params == null ? void 0 : params.timezone), getEnd(-1, "quarter", params == null ? void 0 : params.timezone)], "lastQuarter"),
83
+ nextQuarter: /* @__PURE__ */ __name((params) => [getStart(1, "quarter", params == null ? void 0 : params.timezone), getEnd(1, "quarter", params == null ? void 0 : params.timezone)], "nextQuarter"),
84
+ thisYear: /* @__PURE__ */ __name((params) => [getStart(0, "year", params == null ? void 0 : params.timezone), getEnd(0, "year", params == null ? void 0 : params.timezone)], "thisYear"),
85
+ lastYear: /* @__PURE__ */ __name((params) => [getStart(-1, "year", params == null ? void 0 : params.timezone), getEnd(-1, "year", params == null ? void 0 : params.timezone)], "lastYear"),
86
+ nextYear: /* @__PURE__ */ __name((params) => [getStart(1, "year", params == null ? void 0 : params.timezone), getEnd(1, "year", params == null ? void 0 : params.timezone)], "nextYear")
87
+ };
88
+ const getDayRangeByParams = /* @__PURE__ */ __name((params) => {
89
+ if (params.type === "past" || params.type === "next") {
90
+ return getOffsetRangeByParams(params);
91
+ }
92
+ const fn = strategies[params.type];
93
+ if (!fn) throw new Error(`Unsupported type: ${params.type}`);
94
+ const [start, end] = fn(params);
95
+ return [start.format("YYYY-MM-DD HH:mm:ss"), end.format("YYYY-MM-DD HH:mm:ss")];
96
+ }, "getDayRangeByParams");
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ getDayRangeByParams,
100
+ getOffsetRangeByParams
101
+ });
package/lib/dayjs.js CHANGED
@@ -42,6 +42,7 @@ module.exports = __toCommonJS(dayjs_exports);
42
42
  var import_dayjs = __toESM(require("dayjs"));
43
43
  var import_advancedFormat = __toESM(require("dayjs/plugin/advancedFormat"));
44
44
  var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat"));
45
+ var import_duration = __toESM(require("dayjs/plugin/duration"));
45
46
  var import_isBetween = __toESM(require("dayjs/plugin/isBetween"));
46
47
  var import_isSameOrAfter = __toESM(require("dayjs/plugin/isSameOrAfter"));
47
48
  var import_isSameOrBefore = __toESM(require("dayjs/plugin/isSameOrBefore"));
@@ -66,6 +67,7 @@ import_dayjs.default.extend(import_weekOfYear.default);
66
67
  import_dayjs.default.extend(import_weekYear.default);
67
68
  import_dayjs.default.extend(import_customParseFormat.default);
68
69
  import_dayjs.default.extend(import_advancedFormat.default);
70
+ import_dayjs.default.extend(import_duration.default);
69
71
  // Annotate the CommonJS export names for ESM import in node:
70
72
  0 && (module.exports = {
71
73
  dayjs
package/lib/index.d.ts CHANGED
@@ -37,4 +37,5 @@ export * from './url';
37
37
  export * from './i18n';
38
38
  export * from './wrap-middleware';
39
39
  export * from './object-to-cli-args';
40
+ export * from './dateRangeUtils';
40
41
  export { Schema } from '@formily/json-schema';
package/lib/index.js CHANGED
@@ -72,6 +72,7 @@ __reExport(src_exports, require("./url"), module.exports);
72
72
  __reExport(src_exports, require("./i18n"), module.exports);
73
73
  __reExport(src_exports, require("./wrap-middleware"), module.exports);
74
74
  __reExport(src_exports, require("./object-to-cli-args"), module.exports);
75
+ __reExport(src_exports, require("./dateRangeUtils"), module.exports);
75
76
  var import_json_schema = require("@formily/json-schema");
76
77
  // Annotate the CommonJS export names for ESM import in node:
77
78
  0 && (module.exports = {
@@ -105,5 +106,6 @@ var import_json_schema = require("@formily/json-schema");
105
106
  ...require("./url"),
106
107
  ...require("./i18n"),
107
108
  ...require("./wrap-middleware"),
108
- ...require("./object-to-cli-args")
109
+ ...require("./object-to-cli-args"),
110
+ ...require("./dateRangeUtils")
109
111
  });
package/lib/parse-date.js CHANGED
@@ -33,14 +33,16 @@ __export(parse_date_exports, {
33
33
  module.exports = __toCommonJS(parse_date_exports);
34
34
  var import_date = require("./date");
35
35
  var import_dayjs = require("./dayjs");
36
+ var import_dateRangeUtils = require("./dateRangeUtils");
36
37
  function parseUTC(value) {
38
+ var _a;
37
39
  if (value instanceof Date || import_dayjs.dayjs.isDayjs(value)) {
38
40
  return {
39
41
  unit: "utc",
40
42
  start: value.toISOString()
41
43
  };
42
44
  }
43
- if (value.endsWith("Z")) {
45
+ if ((_a = value == null ? void 0 : value.endsWith) == null ? void 0 : _a.call(value, "Z")) {
44
46
  return {
45
47
  unit: "utc",
46
48
  start: value
@@ -186,6 +188,9 @@ function parseDate(value, options = {}) {
186
188
  if (!value) {
187
189
  return;
188
190
  }
191
+ if (value.type) {
192
+ value = (0, import_dateRangeUtils.getDayRangeByParams)({ ...value, ...options });
193
+ }
189
194
  if (Array.isArray(value)) {
190
195
  return parseDateBetween(value, options);
191
196
  }
@@ -53,6 +53,7 @@ var import_moment = __toESM(require("moment"));
53
53
  var import_date = require("./date");
54
54
  var import_dayjs = require("./dayjs");
55
55
  var import_getValuesByPath = require("./getValuesByPath");
56
+ var import_dateRangeUtils = require("./dateRangeUtils");
56
57
  const re = /^\s*\{\{([\s\S]*)\}\}\s*$/;
57
58
  function isBuffer(obj) {
58
59
  return obj && obj.constructor && typeof obj.constructor.isBuffer === "function" && obj.constructor.isBuffer(obj);
@@ -131,6 +132,9 @@ const dateValueWrapper = /* @__PURE__ */ __name((value, timezone) => {
131
132
  if (!value) {
132
133
  return null;
133
134
  }
135
+ if (value.type) {
136
+ value = (0, import_dateRangeUtils.getDayRangeByParams)({ ...value, timezone });
137
+ }
134
138
  if (Array.isArray(value)) {
135
139
  if (value.length === 2) {
136
140
  value.push("[]", timezone);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/utils",
3
- "version": "1.7.0-beta.9",
3
+ "version": "1.8.0-beta.1",
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": "7013a5080f3695d7750ab21005c90d2172c16480"
19
+ "gitHead": "103935669123174f2942247202e3d9ff15f0d4ed"
20
20
  }