sculp-js 1.3.0 → 1.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.
Files changed (52) hide show
  1. package/README.md +7 -6
  2. package/lib/cjs/array.js +1 -1
  3. package/lib/cjs/async.js +1 -1
  4. package/lib/cjs/clipboard.js +1 -1
  5. package/lib/cjs/cookie.js +1 -1
  6. package/lib/cjs/date.js +28 -42
  7. package/lib/cjs/dom.js +1 -1
  8. package/lib/cjs/download.js +1 -1
  9. package/lib/cjs/easing.js +1 -1
  10. package/lib/cjs/file.js +1 -1
  11. package/lib/cjs/func.js +1 -1
  12. package/lib/cjs/index.js +1 -1
  13. package/lib/cjs/number.js +1 -1
  14. package/lib/cjs/object.js +1 -1
  15. package/lib/cjs/path.js +1 -1
  16. package/lib/cjs/qs.js +1 -1
  17. package/lib/cjs/random.js +1 -1
  18. package/lib/cjs/string.js +1 -1
  19. package/lib/cjs/tooltip.js +1 -1
  20. package/lib/cjs/tree.js +9 -13
  21. package/lib/cjs/type.js +1 -1
  22. package/lib/cjs/unique.js +1 -1
  23. package/lib/cjs/url.js +1 -1
  24. package/lib/cjs/watermark.js +1 -1
  25. package/lib/cjs/we-decode.js +1 -1
  26. package/lib/es/array.js +1 -1
  27. package/lib/es/async.js +1 -1
  28. package/lib/es/clipboard.js +1 -1
  29. package/lib/es/cookie.js +1 -1
  30. package/lib/es/date.js +28 -42
  31. package/lib/es/dom.js +1 -1
  32. package/lib/es/download.js +1 -1
  33. package/lib/es/easing.js +1 -1
  34. package/lib/es/file.js +1 -1
  35. package/lib/es/func.js +1 -1
  36. package/lib/es/index.js +1 -1
  37. package/lib/es/number.js +1 -1
  38. package/lib/es/object.js +1 -1
  39. package/lib/es/path.js +1 -1
  40. package/lib/es/qs.js +1 -1
  41. package/lib/es/random.js +1 -1
  42. package/lib/es/string.js +1 -1
  43. package/lib/es/tooltip.js +1 -1
  44. package/lib/es/tree.js +9 -13
  45. package/lib/es/type.js +1 -1
  46. package/lib/es/unique.js +1 -1
  47. package/lib/es/url.js +1 -1
  48. package/lib/es/watermark.js +1 -1
  49. package/lib/es/we-decode.js +1 -1
  50. package/lib/index.d.ts +5 -4
  51. package/lib/umd/index.js +37 -55
  52. package/package.json +2 -1
package/README.md CHANGED
@@ -54,7 +54,7 @@
54
54
 
55
55
  - stringCamelCase
56
56
  - stringKebabCase
57
- - getStrWidthPx
57
+ - getStrWidthPx (web)
58
58
 
59
59
  - Unique
60
60
 
@@ -69,18 +69,19 @@
69
69
  - calculateDate
70
70
  - calculateDateTime
71
71
 
72
- - Download
72
+ - Download (web)
73
73
 
74
74
  - downloadURL
75
75
  - downloadHref
76
76
  - downloadBlob
77
77
  - downloadData
78
78
 
79
- - File
79
+ - File (web)
80
80
 
81
81
  - chooseLocalFile
82
+ - compressImg 压缩图片
82
83
 
83
- - Dom
84
+ - Dom (web)
84
85
 
85
86
  - hasClass
86
87
  - addClass
@@ -89,11 +90,11 @@
89
90
  - getStyle
90
91
  - getComputedCssVal
91
92
 
92
- - Watermark
93
+ - Watermark (web)
93
94
 
94
95
  - genCanvasWM
95
96
 
96
- - Clipboard
97
+ - Clipboard (web)
97
98
  - copyText
98
99
 
99
100
  ## Install
package/lib/cjs/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -163,64 +163,50 @@ function formatDate(value, format = 'YYYY-MM-DD HH:mm:ss') {
163
163
  }
164
164
  /**
165
165
  * 计算向前或向后N天的具体日期
166
- * @param {string} strDate - 参考日期
166
+ * @param {DateValue} originDate - 参考日期
167
167
  * @param {number} n - 正数:向后推算;负数:向前推算
168
168
  * @param {string} sep - 日期格式的分隔符
169
169
  * @returns {string} 计算后的目标日期
170
170
  */
171
- function calculateDate(strDate, n, sep = '-') {
172
- //strDate 为字符串日期 如:'2019-01-01' n为你要传入的参数,当前为0,前一天为-1,后一天为1
173
- const dateArr = strDate.split(sep); //这边给定一个特定时间
174
- const newDate = new Date(+dateArr[0], +dateArr[1] - 1, +dateArr[2]);
175
- const befminuts = newDate.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
176
- const beforeDat = new Date();
177
- beforeDat.setTime(befminuts);
178
- const befMonth = beforeDat.getMonth() + 1;
179
- const mon = befMonth >= 10 ? befMonth : '0' + befMonth;
180
- const befDate = beforeDat.getDate();
181
- const da = befDate >= 10 ? befDate : '0' + befDate;
182
- const finalNewDate = beforeDat.getFullYear() + '-' + mon + '-' + da;
171
+ function calculateDate(originDate, n, sep = '-') {
172
+ //originDate 为字符串日期 如:'2019-01-01' n为你要传入的参数,当前为0,前一天为-1,后一天为1
173
+ const date = new Date(originDate); //这边给定一个特定时间
174
+ const newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
175
+ const millisecondGap = newDate.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
176
+ const targetDate = new Date(millisecondGap);
177
+ const finalNewDate = targetDate.getFullYear() +
178
+ sep +
179
+ String(targetDate.getMonth() + 1).padStart(2, '0') +
180
+ '-' +
181
+ String(targetDate.getDate()).padStart(2, '0');
183
182
  return finalNewDate;
184
183
  }
185
184
  /**
186
- * 计算向前或向后N天的具体时间日期
185
+ * 计算向前或向后N天的具体日期时间
186
+ * @param {DateValue} originDateTime - 参考日期时间
187
187
  * @param {number} n - 正数:向后推算;负数:向前推算
188
188
  * @param {string} dateSep - 日期分隔符
189
189
  * @param {string} timeSep - 时间分隔符
190
190
  * @returns {string} 转换后的目标日期时间
191
191
  */
192
- function calculateDateTime(n, dateSep = '-', timeSep = ':') {
193
- const date = new Date();
194
- const separator1 = '-';
195
- const separator2 = ':';
196
- let year = date.getFullYear();
197
- let month = date.getMonth() + 1;
198
- let strDate = date.getDate() + n;
199
- if (strDate > new Date(year, month, 0).getDate()) {
200
- month += 1;
201
- strDate -= new Date(year, month, 0).getDate();
202
- if (month > 12) {
203
- year += 1;
204
- month = 1;
205
- }
206
- }
207
- if (month >= 1 && month <= 9) {
208
- month = '0' + month;
209
- }
210
- if (strDate >= 0 && strDate <= 9) {
211
- strDate = '0' + strDate;
212
- }
213
- return (year +
192
+ function calculateDateTime(originDateTime, n, dateSep = '-', timeSep = ':') {
193
+ const date = new Date(originDateTime);
194
+ const separator1 = dateSep;
195
+ const separator2 = timeSep;
196
+ const dateTime = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
197
+ const millisecondGap = dateTime.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
198
+ const targetDateTime = new Date(millisecondGap);
199
+ return (targetDateTime.getFullYear() +
214
200
  separator1 +
215
- month +
201
+ String(targetDateTime.getMonth() + 1).padStart(2, '0') +
216
202
  separator1 +
217
- strDate +
203
+ String(targetDateTime.getDate()).padStart(2, '0') +
218
204
  ' ' +
219
- date.getHours() +
205
+ String(targetDateTime.getHours()).padStart(2, '0') +
220
206
  separator2 +
221
- date.getMinutes() +
207
+ String(targetDateTime.getMinutes()).padStart(2, '0') +
222
208
  separator2 +
223
- date.getSeconds());
209
+ String(targetDateTime.getSeconds()).padStart(2, '0'));
224
210
  }
225
211
 
226
212
  exports.calculateDate = calculateDate;
package/lib/cjs/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/string.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -16,8 +16,8 @@ const defaultFieldOptions = { keyField: 'key', childField: 'children', pidField:
16
16
  * @returns {*}
17
17
  */
18
18
  function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
19
- let level = 0, isBreak = false;
20
- const walk = (arr, parent) => {
19
+ let isBreak = false;
20
+ const walk = (arr, parent, level = 0) => {
21
21
  if (isReverse) {
22
22
  for (let i = arr.length - 1; i >= 0; i--) {
23
23
  if (isBreak) {
@@ -33,9 +33,8 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
33
33
  }
34
34
  // @ts-ignore
35
35
  if (arr[i] && Array.isArray(arr[i][children])) {
36
- ++level;
37
36
  // @ts-ignore
38
- walk(arr[i][children], arr[i]);
37
+ walk(arr[i][children], arr[i], level + 1);
39
38
  }
40
39
  }
41
40
  }
@@ -54,9 +53,8 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
54
53
  }
55
54
  // @ts-ignore
56
55
  if (arr[i] && Array.isArray(arr[i][children])) {
57
- ++level;
58
56
  // @ts-ignore
59
- walk(arr[i][children], arr[i]);
57
+ walk(arr[i][children], arr[i], level + 1);
60
58
  }
61
59
  }
62
60
  }
@@ -72,9 +70,9 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
72
70
  * @returns {any[]} 新的一棵树
73
71
  */
74
72
  function forEachMap(tree, iterator, children = 'children', isReverse = false) {
75
- let level = 0, isBreak = false;
73
+ let isBreak = false;
76
74
  const newTree = [];
77
- const walk = (arr, parent, newTree) => {
75
+ const walk = (arr, parent, newTree, level = 0) => {
78
76
  if (isReverse) {
79
77
  for (let i = arr.length - 1; i >= 0; i--) {
80
78
  if (isBreak) {
@@ -91,10 +89,9 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
91
89
  newTree.push(re);
92
90
  // @ts-ignore
93
91
  if (arr[i] && Array.isArray(arr[i][children])) {
94
- ++level;
95
92
  newTree[newTree.length - 1][children] = [];
96
93
  // @ts-ignore
97
- walk(arr[i][children], arr[i], newTree[newTree.length - 1][children]);
94
+ walk(arr[i][children], arr[i], newTree[newTree.length - 1][children], level + 1);
98
95
  }
99
96
  else {
100
97
  // children非有效数组时,移除该属性字段
@@ -118,10 +115,9 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
118
115
  newTree.push(re);
119
116
  // @ts-ignore
120
117
  if (arr[i] && Array.isArray(arr[i][children])) {
121
- ++level;
122
118
  newTree[newTree.length - 1][children] = [];
123
119
  // @ts-ignore
124
- walk(arr[i][children], arr[i], newTree[newTree.length - 1][children]);
120
+ walk(arr[i][children], arr[i], newTree[newTree.length - 1][children], level + 1);
125
121
  }
126
122
  else {
127
123
  // children非有效数组时,移除该属性字段
package/lib/cjs/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -161,64 +161,50 @@ function formatDate(value, format = 'YYYY-MM-DD HH:mm:ss') {
161
161
  }
162
162
  /**
163
163
  * 计算向前或向后N天的具体日期
164
- * @param {string} strDate - 参考日期
164
+ * @param {DateValue} originDate - 参考日期
165
165
  * @param {number} n - 正数:向后推算;负数:向前推算
166
166
  * @param {string} sep - 日期格式的分隔符
167
167
  * @returns {string} 计算后的目标日期
168
168
  */
169
- function calculateDate(strDate, n, sep = '-') {
170
- //strDate 为字符串日期 如:'2019-01-01' n为你要传入的参数,当前为0,前一天为-1,后一天为1
171
- const dateArr = strDate.split(sep); //这边给定一个特定时间
172
- const newDate = new Date(+dateArr[0], +dateArr[1] - 1, +dateArr[2]);
173
- const befminuts = newDate.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
174
- const beforeDat = new Date();
175
- beforeDat.setTime(befminuts);
176
- const befMonth = beforeDat.getMonth() + 1;
177
- const mon = befMonth >= 10 ? befMonth : '0' + befMonth;
178
- const befDate = beforeDat.getDate();
179
- const da = befDate >= 10 ? befDate : '0' + befDate;
180
- const finalNewDate = beforeDat.getFullYear() + '-' + mon + '-' + da;
169
+ function calculateDate(originDate, n, sep = '-') {
170
+ //originDate 为字符串日期 如:'2019-01-01' n为你要传入的参数,当前为0,前一天为-1,后一天为1
171
+ const date = new Date(originDate); //这边给定一个特定时间
172
+ const newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
173
+ const millisecondGap = newDate.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
174
+ const targetDate = new Date(millisecondGap);
175
+ const finalNewDate = targetDate.getFullYear() +
176
+ sep +
177
+ String(targetDate.getMonth() + 1).padStart(2, '0') +
178
+ '-' +
179
+ String(targetDate.getDate()).padStart(2, '0');
181
180
  return finalNewDate;
182
181
  }
183
182
  /**
184
- * 计算向前或向后N天的具体时间日期
183
+ * 计算向前或向后N天的具体日期时间
184
+ * @param {DateValue} originDateTime - 参考日期时间
185
185
  * @param {number} n - 正数:向后推算;负数:向前推算
186
186
  * @param {string} dateSep - 日期分隔符
187
187
  * @param {string} timeSep - 时间分隔符
188
188
  * @returns {string} 转换后的目标日期时间
189
189
  */
190
- function calculateDateTime(n, dateSep = '-', timeSep = ':') {
191
- const date = new Date();
192
- const separator1 = '-';
193
- const separator2 = ':';
194
- let year = date.getFullYear();
195
- let month = date.getMonth() + 1;
196
- let strDate = date.getDate() + n;
197
- if (strDate > new Date(year, month, 0).getDate()) {
198
- month += 1;
199
- strDate -= new Date(year, month, 0).getDate();
200
- if (month > 12) {
201
- year += 1;
202
- month = 1;
203
- }
204
- }
205
- if (month >= 1 && month <= 9) {
206
- month = '0' + month;
207
- }
208
- if (strDate >= 0 && strDate <= 9) {
209
- strDate = '0' + strDate;
210
- }
211
- return (year +
190
+ function calculateDateTime(originDateTime, n, dateSep = '-', timeSep = ':') {
191
+ const date = new Date(originDateTime);
192
+ const separator1 = dateSep;
193
+ const separator2 = timeSep;
194
+ const dateTime = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
195
+ const millisecondGap = dateTime.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
196
+ const targetDateTime = new Date(millisecondGap);
197
+ return (targetDateTime.getFullYear() +
212
198
  separator1 +
213
- month +
199
+ String(targetDateTime.getMonth() + 1).padStart(2, '0') +
214
200
  separator1 +
215
- strDate +
201
+ String(targetDateTime.getDate()).padStart(2, '0') +
216
202
  ' ' +
217
- date.getHours() +
203
+ String(targetDateTime.getHours()).padStart(2, '0') +
218
204
  separator2 +
219
- date.getMinutes() +
205
+ String(targetDateTime.getMinutes()).padStart(2, '0') +
220
206
  separator2 +
221
- date.getSeconds());
207
+ String(targetDateTime.getSeconds()).padStart(2, '0'));
222
208
  }
223
209
 
224
210
  export { calculateDate, calculateDateTime, dateParse, dateToEnd, dateToStart, formatDate, isValidDate };
package/lib/es/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/string.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/tooltip.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -14,8 +14,8 @@ const defaultFieldOptions = { keyField: 'key', childField: 'children', pidField:
14
14
  * @returns {*}
15
15
  */
16
16
  function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
17
- let level = 0, isBreak = false;
18
- const walk = (arr, parent) => {
17
+ let isBreak = false;
18
+ const walk = (arr, parent, level = 0) => {
19
19
  if (isReverse) {
20
20
  for (let i = arr.length - 1; i >= 0; i--) {
21
21
  if (isBreak) {
@@ -31,9 +31,8 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
31
31
  }
32
32
  // @ts-ignore
33
33
  if (arr[i] && Array.isArray(arr[i][children])) {
34
- ++level;
35
34
  // @ts-ignore
36
- walk(arr[i][children], arr[i]);
35
+ walk(arr[i][children], arr[i], level + 1);
37
36
  }
38
37
  }
39
38
  }
@@ -52,9 +51,8 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
52
51
  }
53
52
  // @ts-ignore
54
53
  if (arr[i] && Array.isArray(arr[i][children])) {
55
- ++level;
56
54
  // @ts-ignore
57
- walk(arr[i][children], arr[i]);
55
+ walk(arr[i][children], arr[i], level + 1);
58
56
  }
59
57
  }
60
58
  }
@@ -70,9 +68,9 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
70
68
  * @returns {any[]} 新的一棵树
71
69
  */
72
70
  function forEachMap(tree, iterator, children = 'children', isReverse = false) {
73
- let level = 0, isBreak = false;
71
+ let isBreak = false;
74
72
  const newTree = [];
75
- const walk = (arr, parent, newTree) => {
73
+ const walk = (arr, parent, newTree, level = 0) => {
76
74
  if (isReverse) {
77
75
  for (let i = arr.length - 1; i >= 0; i--) {
78
76
  if (isBreak) {
@@ -89,10 +87,9 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
89
87
  newTree.push(re);
90
88
  // @ts-ignore
91
89
  if (arr[i] && Array.isArray(arr[i][children])) {
92
- ++level;
93
90
  newTree[newTree.length - 1][children] = [];
94
91
  // @ts-ignore
95
- walk(arr[i][children], arr[i], newTree[newTree.length - 1][children]);
92
+ walk(arr[i][children], arr[i], newTree[newTree.length - 1][children], level + 1);
96
93
  }
97
94
  else {
98
95
  // children非有效数组时,移除该属性字段
@@ -116,10 +113,9 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
116
113
  newTree.push(re);
117
114
  // @ts-ignore
118
115
  if (arr[i] && Array.isArray(arr[i][children])) {
119
- ++level;
120
116
  newTree[newTree.length - 1][children] = [];
121
117
  // @ts-ignore
122
- walk(arr[i][children], arr[i], newTree[newTree.length - 1][children]);
118
+ walk(arr[i][children], arr[i], newTree[newTree.length - 1][children], level + 1);
123
119
  }
124
120
  else {
125
121
  // children非有效数组时,移除该属性字段
package/lib/es/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/index.d.ts CHANGED
@@ -160,20 +160,21 @@ declare function dateToEnd(value: DateValue): Date;
160
160
  declare function formatDate(value: DateValue, format?: string): string;
161
161
  /**
162
162
  * 计算向前或向后N天的具体日期
163
- * @param {string} strDate - 参考日期
163
+ * @param {DateValue} originDate - 参考日期
164
164
  * @param {number} n - 正数:向后推算;负数:向前推算
165
165
  * @param {string} sep - 日期格式的分隔符
166
166
  * @returns {string} 计算后的目标日期
167
167
  */
168
- declare function calculateDate(strDate: string, n: number, sep?: string): string;
168
+ declare function calculateDate(originDate: DateValue, n: number, sep?: string): string;
169
169
  /**
170
- * 计算向前或向后N天的具体时间日期
170
+ * 计算向前或向后N天的具体日期时间
171
+ * @param {DateValue} originDateTime - 参考日期时间
171
172
  * @param {number} n - 正数:向后推算;负数:向前推算
172
173
  * @param {string} dateSep - 日期分隔符
173
174
  * @param {string} timeSep - 时间分隔符
174
175
  * @returns {string} 转换后的目标日期时间
175
176
  */
176
- declare function calculateDateTime(n: number, dateSep?: string, timeSep?: string): string;
177
+ declare function calculateDateTime(originDateTime: DateValue, n: number, dateSep?: string, timeSep?: string): string;
177
178
 
178
179
  type EasingName = 'ease' | 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out' | string;
179
180
 
package/lib/umd/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.3.0
2
+ * core v1.3.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -7,7 +7,7 @@
7
7
  (function (global, factory) {
8
8
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('bezier-easing')) :
9
9
  typeof define === 'function' && define.amd ? define(['exports', 'bezier-easing'], factory) :
10
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.sculpJs = {}, global.bezier));
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.core = {}, global.bezier));
11
11
  })(this, (function (exports, bezier) { 'use strict';
12
12
 
13
13
  /**
@@ -913,64 +913,50 @@
913
913
  }
914
914
  /**
915
915
  * 计算向前或向后N天的具体日期
916
- * @param {string} strDate - 参考日期
916
+ * @param {DateValue} originDate - 参考日期
917
917
  * @param {number} n - 正数:向后推算;负数:向前推算
918
918
  * @param {string} sep - 日期格式的分隔符
919
919
  * @returns {string} 计算后的目标日期
920
920
  */
921
- function calculateDate(strDate, n, sep = '-') {
922
- //strDate 为字符串日期 如:'2019-01-01' n为你要传入的参数,当前为0,前一天为-1,后一天为1
923
- const dateArr = strDate.split(sep); //这边给定一个特定时间
924
- const newDate = new Date(+dateArr[0], +dateArr[1] - 1, +dateArr[2]);
925
- const befminuts = newDate.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
926
- const beforeDat = new Date();
927
- beforeDat.setTime(befminuts);
928
- const befMonth = beforeDat.getMonth() + 1;
929
- const mon = befMonth >= 10 ? befMonth : '0' + befMonth;
930
- const befDate = beforeDat.getDate();
931
- const da = befDate >= 10 ? befDate : '0' + befDate;
932
- const finalNewDate = beforeDat.getFullYear() + '-' + mon + '-' + da;
921
+ function calculateDate(originDate, n, sep = '-') {
922
+ //originDate 为字符串日期 如:'2019-01-01' n为你要传入的参数,当前为0,前一天为-1,后一天为1
923
+ const date = new Date(originDate); //这边给定一个特定时间
924
+ const newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
925
+ const millisecondGap = newDate.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
926
+ const targetDate = new Date(millisecondGap);
927
+ const finalNewDate = targetDate.getFullYear() +
928
+ sep +
929
+ String(targetDate.getMonth() + 1).padStart(2, '0') +
930
+ '-' +
931
+ String(targetDate.getDate()).padStart(2, '0');
933
932
  return finalNewDate;
934
933
  }
935
934
  /**
936
- * 计算向前或向后N天的具体时间日期
935
+ * 计算向前或向后N天的具体日期时间
936
+ * @param {DateValue} originDateTime - 参考日期时间
937
937
  * @param {number} n - 正数:向后推算;负数:向前推算
938
938
  * @param {string} dateSep - 日期分隔符
939
939
  * @param {string} timeSep - 时间分隔符
940
940
  * @returns {string} 转换后的目标日期时间
941
941
  */
942
- function calculateDateTime(n, dateSep = '-', timeSep = ':') {
943
- const date = new Date();
944
- const separator1 = '-';
945
- const separator2 = ':';
946
- let year = date.getFullYear();
947
- let month = date.getMonth() + 1;
948
- let strDate = date.getDate() + n;
949
- if (strDate > new Date(year, month, 0).getDate()) {
950
- month += 1;
951
- strDate -= new Date(year, month, 0).getDate();
952
- if (month > 12) {
953
- year += 1;
954
- month = 1;
955
- }
956
- }
957
- if (month >= 1 && month <= 9) {
958
- month = '0' + month;
959
- }
960
- if (strDate >= 0 && strDate <= 9) {
961
- strDate = '0' + strDate;
962
- }
963
- return (year +
942
+ function calculateDateTime(originDateTime, n, dateSep = '-', timeSep = ':') {
943
+ const date = new Date(originDateTime);
944
+ const separator1 = dateSep;
945
+ const separator2 = timeSep;
946
+ const dateTime = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
947
+ const millisecondGap = dateTime.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
948
+ const targetDateTime = new Date(millisecondGap);
949
+ return (targetDateTime.getFullYear() +
964
950
  separator1 +
965
- month +
951
+ String(targetDateTime.getMonth() + 1).padStart(2, '0') +
966
952
  separator1 +
967
- strDate +
953
+ String(targetDateTime.getDate()).padStart(2, '0') +
968
954
  ' ' +
969
- date.getHours() +
955
+ String(targetDateTime.getHours()).padStart(2, '0') +
970
956
  separator2 +
971
- date.getMinutes() +
957
+ String(targetDateTime.getMinutes()).padStart(2, '0') +
972
958
  separator2 +
973
- date.getSeconds());
959
+ String(targetDateTime.getSeconds()).padStart(2, '0'));
974
960
  }
975
961
 
976
962
  /**
@@ -2052,8 +2038,8 @@
2052
2038
  * @returns {*}
2053
2039
  */
2054
2040
  function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
2055
- let level = 0, isBreak = false;
2056
- const walk = (arr, parent) => {
2041
+ let isBreak = false;
2042
+ const walk = (arr, parent, level = 0) => {
2057
2043
  if (isReverse) {
2058
2044
  for (let i = arr.length - 1; i >= 0; i--) {
2059
2045
  if (isBreak) {
@@ -2069,9 +2055,8 @@
2069
2055
  }
2070
2056
  // @ts-ignore
2071
2057
  if (arr[i] && Array.isArray(arr[i][children])) {
2072
- ++level;
2073
2058
  // @ts-ignore
2074
- walk(arr[i][children], arr[i]);
2059
+ walk(arr[i][children], arr[i], level + 1);
2075
2060
  }
2076
2061
  }
2077
2062
  }
@@ -2090,9 +2075,8 @@
2090
2075
  }
2091
2076
  // @ts-ignore
2092
2077
  if (arr[i] && Array.isArray(arr[i][children])) {
2093
- ++level;
2094
2078
  // @ts-ignore
2095
- walk(arr[i][children], arr[i]);
2079
+ walk(arr[i][children], arr[i], level + 1);
2096
2080
  }
2097
2081
  }
2098
2082
  }
@@ -2108,9 +2092,9 @@
2108
2092
  * @returns {any[]} 新的一棵树
2109
2093
  */
2110
2094
  function forEachMap(tree, iterator, children = 'children', isReverse = false) {
2111
- let level = 0, isBreak = false;
2095
+ let isBreak = false;
2112
2096
  const newTree = [];
2113
- const walk = (arr, parent, newTree) => {
2097
+ const walk = (arr, parent, newTree, level = 0) => {
2114
2098
  if (isReverse) {
2115
2099
  for (let i = arr.length - 1; i >= 0; i--) {
2116
2100
  if (isBreak) {
@@ -2127,10 +2111,9 @@
2127
2111
  newTree.push(re);
2128
2112
  // @ts-ignore
2129
2113
  if (arr[i] && Array.isArray(arr[i][children])) {
2130
- ++level;
2131
2114
  newTree[newTree.length - 1][children] = [];
2132
2115
  // @ts-ignore
2133
- walk(arr[i][children], arr[i], newTree[newTree.length - 1][children]);
2116
+ walk(arr[i][children], arr[i], newTree[newTree.length - 1][children], level + 1);
2134
2117
  }
2135
2118
  else {
2136
2119
  // children非有效数组时,移除该属性字段
@@ -2154,10 +2137,9 @@
2154
2137
  newTree.push(re);
2155
2138
  // @ts-ignore
2156
2139
  if (arr[i] && Array.isArray(arr[i][children])) {
2157
- ++level;
2158
2140
  newTree[newTree.length - 1][children] = [];
2159
2141
  // @ts-ignore
2160
- walk(arr[i][children], arr[i], newTree[newTree.length - 1][children]);
2142
+ walk(arr[i][children], arr[i], newTree[newTree.length - 1][children], level + 1);
2161
2143
  }
2162
2144
  else {
2163
2145
  // children非有效数组时,移除该属性字段
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "sculp-js",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "packageManager": "npm@8.19.2",
5
5
  "description": "js工具库",
6
6
  "scripts": {
7
7
  "prepare": "husky install",
8
8
  "build": "rollup --bundleConfigAsCjs --config rollup.config.js",
9
+ "build:core": "BUILD_TARGET=core rollup --bundleConfigAsCjs --config rollup.config.js",
9
10
  "build:terser": "node scripts/build.js",
10
11
  "test:unit": "jest",
11
12
  "test": "jest --coverage",