sculp-js 1.3.1 → 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 +5 -7
  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 +5 -7
  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 +33 -49
  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
  */
@@ -70,9 +70,9 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
70
70
  * @returns {any[]} 新的一棵树
71
71
  */
72
72
  function forEachMap(tree, iterator, children = 'children', isReverse = false) {
73
- let level = 0, isBreak = false;
73
+ let isBreak = false;
74
74
  const newTree = [];
75
- const walk = (arr, parent, newTree) => {
75
+ const walk = (arr, parent, newTree, level = 0) => {
76
76
  if (isReverse) {
77
77
  for (let i = arr.length - 1; i >= 0; i--) {
78
78
  if (isBreak) {
@@ -89,10 +89,9 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
89
89
  newTree.push(re);
90
90
  // @ts-ignore
91
91
  if (arr[i] && Array.isArray(arr[i][children])) {
92
- ++level;
93
92
  newTree[newTree.length - 1][children] = [];
94
93
  // @ts-ignore
95
- 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);
96
95
  }
97
96
  else {
98
97
  // children非有效数组时,移除该属性字段
@@ -116,10 +115,9 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
116
115
  newTree.push(re);
117
116
  // @ts-ignore
118
117
  if (arr[i] && Array.isArray(arr[i][children])) {
119
- ++level;
120
118
  newTree[newTree.length - 1][children] = [];
121
119
  // @ts-ignore
122
- 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);
123
121
  }
124
122
  else {
125
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
  */
@@ -68,9 +68,9 @@ function forEachDeep(tree, iterator, children = 'children', isReverse = false) {
68
68
  * @returns {any[]} 新的一棵树
69
69
  */
70
70
  function forEachMap(tree, iterator, children = 'children', isReverse = false) {
71
- let level = 0, isBreak = false;
71
+ let isBreak = false;
72
72
  const newTree = [];
73
- const walk = (arr, parent, newTree) => {
73
+ const walk = (arr, parent, newTree, level = 0) => {
74
74
  if (isReverse) {
75
75
  for (let i = arr.length - 1; i >= 0; i--) {
76
76
  if (isBreak) {
@@ -87,10 +87,9 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
87
87
  newTree.push(re);
88
88
  // @ts-ignore
89
89
  if (arr[i] && Array.isArray(arr[i][children])) {
90
- ++level;
91
90
  newTree[newTree.length - 1][children] = [];
92
91
  // @ts-ignore
93
- 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);
94
93
  }
95
94
  else {
96
95
  // children非有效数组时,移除该属性字段
@@ -114,10 +113,9 @@ function forEachMap(tree, iterator, children = 'children', isReverse = false) {
114
113
  newTree.push(re);
115
114
  // @ts-ignore
116
115
  if (arr[i] && Array.isArray(arr[i][children])) {
117
- ++level;
118
116
  newTree[newTree.length - 1][children] = [];
119
117
  // @ts-ignore
120
- 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);
121
119
  }
122
120
  else {
123
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
  /**
@@ -2106,9 +2092,9 @@
2106
2092
  * @returns {any[]} 新的一棵树
2107
2093
  */
2108
2094
  function forEachMap(tree, iterator, children = 'children', isReverse = false) {
2109
- let level = 0, isBreak = false;
2095
+ let isBreak = false;
2110
2096
  const newTree = [];
2111
- const walk = (arr, parent, newTree) => {
2097
+ const walk = (arr, parent, newTree, level = 0) => {
2112
2098
  if (isReverse) {
2113
2099
  for (let i = arr.length - 1; i >= 0; i--) {
2114
2100
  if (isBreak) {
@@ -2125,10 +2111,9 @@
2125
2111
  newTree.push(re);
2126
2112
  // @ts-ignore
2127
2113
  if (arr[i] && Array.isArray(arr[i][children])) {
2128
- ++level;
2129
2114
  newTree[newTree.length - 1][children] = [];
2130
2115
  // @ts-ignore
2131
- 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);
2132
2117
  }
2133
2118
  else {
2134
2119
  // children非有效数组时,移除该属性字段
@@ -2152,10 +2137,9 @@
2152
2137
  newTree.push(re);
2153
2138
  // @ts-ignore
2154
2139
  if (arr[i] && Array.isArray(arr[i][children])) {
2155
- ++level;
2156
2140
  newTree[newTree.length - 1][children] = [];
2157
2141
  // @ts-ignore
2158
- 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);
2159
2143
  }
2160
2144
  else {
2161
2145
  // children非有效数组时,移除该属性字段
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "sculp-js",
3
- "version": "1.3.1",
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",