sculp-js 1.19.0 → 1.19.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.
Files changed (62) hide show
  1. package/dist/cjs/array.cjs +1 -1
  2. package/dist/cjs/async.cjs +1 -1
  3. package/dist/cjs/base64.cjs +1 -1
  4. package/dist/cjs/clipboard.cjs +1 -1
  5. package/dist/cjs/cloneDeep.cjs +1 -1
  6. package/dist/cjs/cookie.cjs +1 -1
  7. package/dist/cjs/date.cjs +130 -70
  8. package/dist/cjs/dom.cjs +1 -1
  9. package/dist/cjs/download.cjs +1 -1
  10. package/dist/cjs/file.cjs +1 -1
  11. package/dist/cjs/func.cjs +1 -1
  12. package/dist/cjs/index.cjs +3 -3
  13. package/dist/cjs/isEqual.cjs +1 -1
  14. package/dist/cjs/math.cjs +1 -1
  15. package/dist/cjs/number.cjs +1 -1
  16. package/dist/cjs/object.cjs +1 -1
  17. package/dist/cjs/path.cjs +1 -1
  18. package/dist/cjs/qs.cjs +1 -1
  19. package/dist/cjs/random.cjs +1 -1
  20. package/dist/cjs/string.cjs +1 -1
  21. package/dist/cjs/tooltip.cjs +1 -1
  22. package/dist/cjs/tree.cjs +1 -1
  23. package/dist/cjs/type.cjs +1 -1
  24. package/dist/cjs/unicodeToolkit.cjs +19 -19
  25. package/dist/cjs/unique.cjs +1 -1
  26. package/dist/cjs/url.cjs +1 -1
  27. package/dist/cjs/validator.cjs +1 -1
  28. package/dist/cjs/variable.cjs +1 -1
  29. package/dist/cjs/watermark.cjs +1 -1
  30. package/dist/esm/array.mjs +1 -1
  31. package/dist/esm/async.mjs +1 -1
  32. package/dist/esm/base64.mjs +1 -1
  33. package/dist/esm/clipboard.mjs +1 -1
  34. package/dist/esm/cloneDeep.mjs +1 -1
  35. package/dist/esm/cookie.mjs +1 -1
  36. package/dist/esm/date.mjs +130 -78
  37. package/dist/esm/dom.mjs +1 -1
  38. package/dist/esm/download.mjs +1 -1
  39. package/dist/esm/file.mjs +1 -1
  40. package/dist/esm/func.mjs +1 -1
  41. package/dist/esm/index.mjs +3 -10
  42. package/dist/esm/isEqual.mjs +1 -1
  43. package/dist/esm/math.mjs +1 -1
  44. package/dist/esm/number.mjs +1 -1
  45. package/dist/esm/object.mjs +1 -1
  46. package/dist/esm/path.mjs +1 -1
  47. package/dist/esm/qs.mjs +1 -1
  48. package/dist/esm/random.mjs +1 -1
  49. package/dist/esm/string.mjs +1 -1
  50. package/dist/esm/tooltip.mjs +1 -1
  51. package/dist/esm/tree.mjs +1 -1
  52. package/dist/esm/type.mjs +1 -1
  53. package/dist/esm/unicodeToolkit.mjs +19 -19
  54. package/dist/esm/unique.mjs +1 -1
  55. package/dist/esm/url.mjs +1 -1
  56. package/dist/esm/validator.mjs +1 -1
  57. package/dist/esm/variable.mjs +1 -1
  58. package/dist/esm/watermark.mjs +1 -1
  59. package/dist/types/date.d.ts +124 -28
  60. package/dist/types/index.d.ts +58 -0
  61. package/dist/umd/index.min.js +2 -2
  62. package/package.json +1 -1
package/dist/esm/date.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -111,19 +111,25 @@ function dateToEnd(value) {
111
111
  return dateParse(d.getTime() - 1);
112
112
  }
113
113
  /**
114
- * 格式化为日期对象(带自定义格式化模板)
114
+ * 格式化为日期对象 (带自定义格式化模板)
115
115
  * @param {Date} value - 可以是数值、字符串或 Date 对象
116
116
  * @param {string} [format] - 模板,默认是 YYYY-MM-DD HH:mm:ss,模板字符:
117
- * - YYYY:年
118
- * - yyyy: 年
119
- * - MM:月
120
- * - DD:日
121
- * - dd: 日
122
- * - HH:时(24 小时制)
123
- * - mm:分
124
- * - ss:秒
125
- * - SSS:毫秒
126
- * - ww: 周
117
+ * - YYYY/yyyy:年
118
+ * - MM:月(补零)
119
+ * - M:月(不补零)
120
+ * - DD/dd:日(补零)
121
+ * - D/d:日(不补零)
122
+ * - HH:时(24 小时制,补零)
123
+ * - H:时(24 小时制,不补零)
124
+ * - mm:分(补零)
125
+ * - m:分(不补零)
126
+ * - ss:秒(补零)
127
+ * - s:秒(不补零)
128
+ * - SSS:毫秒(3 位)
129
+ * - SS:毫秒(2 位)
130
+ * - S:毫秒(1 位)
131
+ * - ww:中文完整星期(如:周日)
132
+ * - w:中文星期(如:周日)
127
133
  * @returns {string} 格式化后的日期字符串
128
134
  */
129
135
  function formatDate(value, format = 'YYYY-MM-DD HH:mm:ss') {
@@ -152,61 +158,113 @@ function formatDate(value, format = 'YYYY-MM-DD HH:mm:ss') {
152
158
  return fmt;
153
159
  }
154
160
  /**
155
- * 计算向前或向后N天的具体日期
156
- * @param {DateValue} originDate - 参考日期
157
- * @param {number} n - 正数:向后推算;负数:向前推算
158
- * @param {string} sep - 日期格式的分隔符
159
- * @returns {string} 计算后的目标日期
160
- */
161
- function calculateDate(originDate, n, sep = '-') {
162
- //originDate 为字符串日期 如:'2019-01-01' n为你要传入的参数,当前为0,前一天为-1,后一天为1
163
- const date = new Date(originDate); //这边给定一个特定时间
164
- const newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
165
- const millisecondGap = newDate.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
166
- const targetDate = new Date(millisecondGap);
167
- const finalNewDate =
168
- targetDate.getFullYear() +
169
- sep +
170
- String(targetDate.getMonth() + 1).padStart(2, '0') +
171
- '-' +
172
- String(targetDate.getDate()).padStart(2, '0');
173
- return finalNewDate;
174
- }
175
- /**
176
- * 计算向前或向后N天的具体日期时间
177
- * @param {DateValue} originDateTime - 参考日期时间
178
- * @param {number} n - 正数:向后推算;负数:向前推算
179
- * @param {string} dateSep - 日期分隔符
180
- * @param {string} timeSep - 时间分隔符
181
- * @returns {string} 转换后的目标日期时间
161
+ * 调整日期(增加或减少特定时间单位)
162
+ * @param {DateValue} originDate - 参考日期,可以是 Date 对象、时间戳或日期字符串
163
+ * @param {CalculateDateOptions} options - 配置项,支持多种时间单位
164
+ * @returns {string | Date} 计算后的日期/日期时间字符串或 Date 对象
165
+ * @example
166
+ * // 基础用法(向后 2 天)
167
+ * adjustDate('2024-01-01', { days: 2 }) // '2024-01-03'
168
+ *
169
+ * // 向前 2
170
+ * adjustDate('2024-01-01', { days: -2 }) // '2023-12-30'
171
+ *
172
+ * // 向后 1 年 2 个月 3 天
173
+ * adjustDate('2024-01-01', { years: 1, months: 2, days: 3 }) // '2025-03-04'
174
+ *
175
+ * // 向后 2 周
176
+ * adjustDate('2024-01-01', { weeks: 2 }) // '2024-01-15'
177
+ *
178
+ * // 包含时间(向后 2 天 3 小时 30 分钟)
179
+ * adjustDate('2024-01-01 10:30:00', { days: 2, hours: 3, minutes: 30 }) // '2024-01-03 14:00'
180
+ *
181
+ * // 自定义格式
182
+ * adjustDate('2024-01-01', { days: 2, format: 'YYYY/MM/DD' }) // '2024/01/03'
183
+ * adjustDate('2024-01-01', { days: 2, format: 'YYYY 年 MM 月 DD 日' }) // '2024 年 01 月 03 日'
184
+ *
185
+ * // 时间戳输入
186
+ * adjustDate(1717330884896, { days: 2 }) // '2024-06-04'
187
+ *
188
+ * // 精确到毫秒
189
+ * adjustDate('2024-01-01 10:30:00', { hours: 1, minutes: 30, seconds: 45, milliseconds: 500 })
190
+ *
191
+ * // 返回 Date 对象
192
+ * adjustDate('2024-01-01', { days: 2, returnDate: true }) // Date 对象
182
193
  */
183
- function calculateDateTime(originDateTime, n, dateSep = '-', timeSep = ':') {
184
- const date = new Date(originDateTime);
185
- const separator1 = dateSep;
186
- const separator2 = timeSep;
187
- const dateTime = new Date(
188
- date.getFullYear(),
189
- date.getMonth(),
190
- date.getDate(),
191
- date.getHours(),
192
- date.getMinutes(),
193
- date.getSeconds()
194
- );
195
- const millisecondGap = dateTime.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
196
- const targetDateTime = new Date(millisecondGap);
197
- return (
198
- targetDateTime.getFullYear() +
199
- separator1 +
200
- String(targetDateTime.getMonth() + 1).padStart(2, '0') +
201
- separator1 +
202
- String(targetDateTime.getDate()).padStart(2, '0') +
203
- ' ' +
204
- String(targetDateTime.getHours()).padStart(2, '0') +
205
- separator2 +
206
- String(targetDateTime.getMinutes()).padStart(2, '0') +
207
- separator2 +
208
- String(targetDateTime.getSeconds()).padStart(2, '0')
209
- );
194
+ function adjustDate(originDate, options = {}) {
195
+ const {
196
+ format,
197
+ returnDate = false,
198
+ years = 0,
199
+ months = 0,
200
+ weeks = 0,
201
+ days = 0,
202
+ hours = 0,
203
+ minutes = 0,
204
+ seconds = 0,
205
+ milliseconds = 0
206
+ } = options;
207
+ const date = dateParse(originDate);
208
+ const targetDate = new Date(date);
209
+ // 保存原始日期以便处理月末边界
210
+ const originalDay = date.getDate();
211
+ const originalMonthDays = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
212
+ const isEndOfMonth = originalDay === originalMonthDays;
213
+ targetDate.setFullYear(targetDate.getFullYear() + years);
214
+ // 处理月末边界:如果原始日期是月末,需要特殊处理
215
+ if (months !== 0) {
216
+ const targetMonthIndex = targetDate.getMonth() + months;
217
+ const targetMonthDays = new Date(targetDate.getFullYear(), targetMonthIndex + 1, 0).getDate();
218
+ // 先将日期设为 1 号,避免 setMonth 时因日期过大而自动进位
219
+ targetDate.setDate(1);
220
+ targetDate.setMonth(targetMonthIndex);
221
+ // 如果原始日期是月末,则调整为目标月份的月末
222
+ if (isEndOfMonth) {
223
+ targetDate.setDate(targetMonthDays);
224
+ } else if (originalDay > targetMonthDays) {
225
+ // 如果原始日期大于目标月份的最大天数,也调整为目标月份的月末
226
+ targetDate.setDate(targetMonthDays);
227
+ } else {
228
+ // 否则保持原始日期
229
+ targetDate.setDate(originalDay);
230
+ }
231
+ }
232
+ // 处理天数(不包括月份变化)
233
+ if (days !== 0 || weeks !== 0) {
234
+ targetDate.setDate(targetDate.getDate() + days + weeks * 7);
235
+ }
236
+ targetDate.setHours(targetDate.getHours() + hours);
237
+ targetDate.setMinutes(targetDate.getMinutes() + minutes);
238
+ targetDate.setSeconds(targetDate.getSeconds() + seconds);
239
+ targetDate.setMilliseconds(targetDate.getMilliseconds() + milliseconds);
240
+ if (returnDate) {
241
+ return targetDate;
242
+ }
243
+ if (format) {
244
+ return formatDate(targetDate, format);
245
+ }
246
+ const year = targetDate.getFullYear();
247
+ const month = String(targetDate.getMonth() + 1).padStart(2, '0');
248
+ const day = String(targetDate.getDate()).padStart(2, '0');
249
+ const hoursStr = String(targetDate.getHours()).padStart(2, '0');
250
+ const minutesStr = String(targetDate.getMinutes()).padStart(2, '0');
251
+ const secondsStr = String(targetDate.getSeconds()).padStart(2, '0');
252
+ const hasTimeParam =
253
+ options.hasOwnProperty('hours') ||
254
+ options.hasOwnProperty('minutes') ||
255
+ options.hasOwnProperty('seconds') ||
256
+ options.hasOwnProperty('milliseconds');
257
+ if (hasTimeParam) {
258
+ if (options.hasOwnProperty('milliseconds')) {
259
+ const msStr = String(targetDate.getMilliseconds()).padStart(3, '0');
260
+ return `${year}-${month}-${day} ${hoursStr}:${minutesStr}:${secondsStr}.${msStr}`;
261
+ }
262
+ if (options.hasOwnProperty('seconds')) {
263
+ return `${year}-${month}-${day} ${hoursStr}:${minutesStr}:${secondsStr}`;
264
+ }
265
+ return `${year}-${month}-${day} ${hoursStr}:${minutesStr}`;
266
+ }
267
+ return `${year}-${month}-${day}`;
210
268
  }
211
269
  var date = {
212
270
  isValidDate,
@@ -214,17 +272,11 @@ var date = {
214
272
  dateToStart,
215
273
  dateToEnd,
216
274
  formatDate,
217
- calculateDate,
218
- calculateDateTime
275
+ adjustDate,
276
+ /**
277
+ * @deprecated 已废弃,请使用 adjustDate
278
+ */
279
+ calculateDate: adjustDate
219
280
  };
220
281
 
221
- export {
222
- calculateDate,
223
- calculateDateTime,
224
- dateParse,
225
- dateToEnd,
226
- dateToStart,
227
- date as default,
228
- formatDate,
229
- isValidDate
230
- };
282
+ export { adjustDate, dateParse, dateToEnd, dateToStart, date as default, formatDate, isValidDate };
package/dist/esm/dom.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/file.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/func.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -11,15 +11,7 @@ export { copyText, fallbackCopyText } from './clipboard.mjs';
11
11
  import * as cookie from './cookie.mjs';
12
12
  export { cookieDel, cookieGet, cookieSet } from './cookie.mjs';
13
13
  import * as date from './date.mjs';
14
- export {
15
- calculateDate,
16
- calculateDateTime,
17
- dateParse,
18
- dateToEnd,
19
- dateToStart,
20
- formatDate,
21
- isValidDate
22
- } from './date.mjs';
14
+ export { adjustDate, dateParse, dateToEnd, dateToStart, formatDate, isValidDate } from './date.mjs';
23
15
  import * as dom from './dom.mjs';
24
16
  export {
25
17
  addClass,
@@ -157,6 +149,7 @@ export { isEqual } from './isEqual.mjs';
157
149
  import * as unicodeToolkit from './unicodeToolkit.mjs';
158
150
  export { UnicodeToolkit } from './unicodeToolkit.mjs';
159
151
 
152
+ // 导出默认对象(使用类型断言避免私有类型问题)
160
153
  var index = {
161
154
  ...array,
162
155
  ...clipboard,
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/math.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/path.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/qs.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/tree.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/type.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,24 +8,6 @@
8
8
  * 增强型 Unicode/HTML/UTF-8 编码解码工具
9
9
  */
10
10
  class UnicodeToolkit {
11
- // 基础 HTML 实体映射
12
- static ENTITY_MAP = {
13
- '&': '&',
14
- '<': '&lt;',
15
- '>': '&gt;',
16
- '"': '&quot;',
17
- "'": '&#39;'
18
- };
19
- static NAMED_ENTITIES = {
20
- '&quot;': '"',
21
- '&amp;': '&',
22
- '&lt;': '<',
23
- '&gt;': '>',
24
- '&nbsp;': '\u00A0',
25
- '&copy;': '©',
26
- '&trade;': '™',
27
- '&reg;': '®'
28
- };
29
11
  /**
30
12
  * 编码函数
31
13
  * @param {string} str 原始字符串
@@ -113,6 +95,24 @@ class UnicodeToolkit {
113
95
  return decoded;
114
96
  }
115
97
  }
98
+ // 基础 HTML 实体映射
99
+ UnicodeToolkit.ENTITY_MAP = {
100
+ '&': '&amp;',
101
+ '<': '&lt;',
102
+ '>': '&gt;',
103
+ '"': '&quot;',
104
+ "'": '&#39;'
105
+ };
106
+ UnicodeToolkit.NAMED_ENTITIES = {
107
+ '&quot;': '"',
108
+ '&amp;': '&',
109
+ '&lt;': '<',
110
+ '&gt;': '>',
111
+ '&nbsp;': '\u00A0',
112
+ '&copy;': '©',
113
+ '&trade;': '™',
114
+ '&reg;': '®'
115
+ };
116
116
  var unicodeToolkit = {
117
117
  UnicodeToolkit
118
118
  };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
package/dist/esm/url.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.19.0
2
+ * sculp-js v1.19.2
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -38,46 +38,142 @@ export declare function dateToStart(value: DateValue): Date;
38
38
  */
39
39
  export declare function dateToEnd(value: DateValue): Date;
40
40
  /**
41
- * 格式化为日期对象(带自定义格式化模板)
41
+ * 格式化为日期对象 (带自定义格式化模板)
42
42
  * @param {Date} value - 可以是数值、字符串或 Date 对象
43
43
  * @param {string} [format] - 模板,默认是 YYYY-MM-DD HH:mm:ss,模板字符:
44
- * - YYYY:年
45
- * - yyyy: 年
46
- * - MM:月
47
- * - DD:日
48
- * - dd: 日
49
- * - HH:时(24 小时制)
50
- * - mm:分
51
- * - ss:秒
52
- * - SSS:毫秒
53
- * - ww: 周
44
+ * - YYYY/yyyy:年
45
+ * - MM:月(补零)
46
+ * - M:月(不补零)
47
+ * - DD/dd:日(补零)
48
+ * - D/d:日(不补零)
49
+ * - HH:时(24 小时制,补零)
50
+ * - H:时(24 小时制,不补零)
51
+ * - mm:分(补零)
52
+ * - m:分(不补零)
53
+ * - ss:秒(补零)
54
+ * - s:秒(不补零)
55
+ * - SSS:毫秒(3 位)
56
+ * - SS:毫秒(2 位)
57
+ * - S:毫秒(1 位)
58
+ * - ww:中文完整星期(如:周日)
59
+ * - w:中文星期(如:周日)
54
60
  * @returns {string} 格式化后的日期字符串
55
61
  */
56
62
  export declare function formatDate(value: DateValue, format?: string): string;
63
+ export interface CalculateDateOptions {
64
+ /**
65
+ * 输出格式模板(传递给 formatDate 函数处理)
66
+ * 支持以下占位符:
67
+ * - YYYY/yyyy: 4 位年份
68
+ * - YY/yy: 2 位年份
69
+ * - MM: 2 位月份
70
+ * - M: 不补零月份
71
+ * - DD/dd: 2 位日期
72
+ * - D/d: 不补零日期
73
+ * - HH: 2 位小时 (24 小时制)
74
+ * - H: 不补零小时
75
+ * - mm: 2 位分钟
76
+ * - m: 不补零分钟
77
+ * - ss: 2 位秒
78
+ * - s: 不补零秒
79
+ * - SSS: 3 位毫秒
80
+ * - SS: 2 位毫秒
81
+ * - S: 1 位毫秒
82
+ * - ww/w: 中文星期
83
+ * @default 'YYYY-MM-DD'
84
+ */
85
+ format?: string;
86
+ /**
87
+ * 年数(正数表示向后,负数表示向前)
88
+ * @default 0
89
+ */
90
+ years?: number;
91
+ /**
92
+ * 月数(正数表示向后,负数表示向前)
93
+ * @default 0
94
+ */
95
+ months?: number;
96
+ /**
97
+ * 周数(正数表示向后,负数表示向前)
98
+ * @default 0
99
+ */
100
+ weeks?: number;
101
+ /**
102
+ * 天数(正数表示向后,负数表示向前)
103
+ * @default 0
104
+ */
105
+ days?: number;
106
+ /**
107
+ * 小时数(正数表示向后,负数表示向前)
108
+ * @default 0
109
+ */
110
+ hours?: number;
111
+ /**
112
+ * 分钟数(正数表示向后,负数表示向前)
113
+ * @default 0
114
+ */
115
+ minutes?: number;
116
+ /**
117
+ * 秒数(正数表示向后,负数表示向前)
118
+ * @default 0
119
+ */
120
+ seconds?: number;
121
+ /**
122
+ * 毫秒数(正数表示向后,负数表示向前)
123
+ * @default 0
124
+ */
125
+ milliseconds?: number;
126
+ /**
127
+ * 是否返回 Date 对象而非字符串
128
+ * @default false
129
+ */
130
+ returnDate?: boolean;
131
+ }
57
132
  /**
58
- * 计算向前或向后N天的具体日期
59
- * @param {DateValue} originDate - 参考日期
60
- * @param {number} n - 正数:向后推算;负数:向前推算
61
- * @param {string} sep - 日期格式的分隔符
62
- * @returns {string} 计算后的目标日期
63
- */
64
- export declare function calculateDate(originDate: DateValue, n: number, sep?: string): string;
65
- /**
66
- * 计算向前或向后N天的具体日期时间
67
- * @param {DateValue} originDateTime - 参考日期时间
68
- * @param {number} n - 正数:向后推算;负数:向前推算
69
- * @param {string} dateSep - 日期分隔符
70
- * @param {string} timeSep - 时间分隔符
71
- * @returns {string} 转换后的目标日期时间
133
+ * 调整日期(增加或减少特定时间单位)
134
+ * @param {DateValue} originDate - 参考日期,可以是 Date 对象、时间戳或日期字符串
135
+ * @param {CalculateDateOptions} options - 配置项,支持多种时间单位
136
+ * @returns {string | Date} 计算后的日期/日期时间字符串或 Date 对象
137
+ * @example
138
+ * // 基础用法(向后 2 天)
139
+ * adjustDate('2024-01-01', { days: 2 }) // '2024-01-03'
140
+ *
141
+ * // 向前 2 天
142
+ * adjustDate('2024-01-01', { days: -2 }) // '2023-12-30'
143
+ *
144
+ * // 向后 1 2 个月 3 天
145
+ * adjustDate('2024-01-01', { years: 1, months: 2, days: 3 }) // '2025-03-04'
146
+ *
147
+ * // 向后 2 周
148
+ * adjustDate('2024-01-01', { weeks: 2 }) // '2024-01-15'
149
+ *
150
+ * // 包含时间(向后 2 天 3 小时 30 分钟)
151
+ * adjustDate('2024-01-01 10:30:00', { days: 2, hours: 3, minutes: 30 }) // '2024-01-03 14:00'
152
+ *
153
+ * // 自定义格式
154
+ * adjustDate('2024-01-01', { days: 2, format: 'YYYY/MM/DD' }) // '2024/01/03'
155
+ * adjustDate('2024-01-01', { days: 2, format: 'YYYY 年 MM 月 DD 日' }) // '2024 年 01 月 03 日'
156
+ *
157
+ * // 时间戳输入
158
+ * adjustDate(1717330884896, { days: 2 }) // '2024-06-04'
159
+ *
160
+ * // 精确到毫秒
161
+ * adjustDate('2024-01-01 10:30:00', { hours: 1, minutes: 30, seconds: 45, milliseconds: 500 })
162
+ *
163
+ * // 返回 Date 对象
164
+ * adjustDate('2024-01-01', { days: 2, returnDate: true }) // Date 对象
72
165
  */
73
- export declare function calculateDateTime(originDateTime: DateValue, n: number, dateSep?: string, timeSep?: string): string;
166
+ export declare function adjustDate(originDate: DateValue, options?: CalculateDateOptions): string | Date;
74
167
  declare const _default: {
75
168
  isValidDate: (any: unknown) => any is Date;
76
169
  dateParse: typeof dateParse;
77
170
  dateToStart: typeof dateToStart;
78
171
  dateToEnd: typeof dateToEnd;
79
172
  formatDate: typeof formatDate;
80
- calculateDate: typeof calculateDate;
81
- calculateDateTime: typeof calculateDateTime;
173
+ adjustDate: typeof adjustDate;
174
+ /**
175
+ * @deprecated 已废弃,请使用 adjustDate
176
+ */
177
+ calculateDate: typeof adjustDate;
82
178
  };
83
179
  export default _default;