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.
- package/README.md +7 -6
- package/lib/cjs/array.js +1 -1
- package/lib/cjs/async.js +1 -1
- package/lib/cjs/clipboard.js +1 -1
- package/lib/cjs/cookie.js +1 -1
- package/lib/cjs/date.js +28 -42
- package/lib/cjs/dom.js +1 -1
- package/lib/cjs/download.js +1 -1
- package/lib/cjs/easing.js +1 -1
- package/lib/cjs/file.js +1 -1
- package/lib/cjs/func.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/number.js +1 -1
- package/lib/cjs/object.js +1 -1
- package/lib/cjs/path.js +1 -1
- package/lib/cjs/qs.js +1 -1
- package/lib/cjs/random.js +1 -1
- package/lib/cjs/string.js +1 -1
- package/lib/cjs/tooltip.js +1 -1
- package/lib/cjs/tree.js +9 -13
- package/lib/cjs/type.js +1 -1
- package/lib/cjs/unique.js +1 -1
- package/lib/cjs/url.js +1 -1
- package/lib/cjs/watermark.js +1 -1
- package/lib/cjs/we-decode.js +1 -1
- package/lib/es/array.js +1 -1
- package/lib/es/async.js +1 -1
- package/lib/es/clipboard.js +1 -1
- package/lib/es/cookie.js +1 -1
- package/lib/es/date.js +28 -42
- package/lib/es/dom.js +1 -1
- package/lib/es/download.js +1 -1
- package/lib/es/easing.js +1 -1
- package/lib/es/file.js +1 -1
- package/lib/es/func.js +1 -1
- package/lib/es/index.js +1 -1
- package/lib/es/number.js +1 -1
- package/lib/es/object.js +1 -1
- package/lib/es/path.js +1 -1
- package/lib/es/qs.js +1 -1
- package/lib/es/random.js +1 -1
- package/lib/es/string.js +1 -1
- package/lib/es/tooltip.js +1 -1
- package/lib/es/tree.js +9 -13
- package/lib/es/type.js +1 -1
- package/lib/es/unique.js +1 -1
- package/lib/es/url.js +1 -1
- package/lib/es/watermark.js +1 -1
- package/lib/es/we-decode.js +1 -1
- package/lib/index.d.ts +5 -4
- package/lib/umd/index.js +37 -55
- 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
package/lib/cjs/async.js
CHANGED
package/lib/cjs/clipboard.js
CHANGED
package/lib/cjs/cookie.js
CHANGED
package/lib/cjs/date.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
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 {
|
|
166
|
+
* @param {DateValue} originDate - 参考日期
|
|
167
167
|
* @param {number} n - 正数:向后推算;负数:向前推算
|
|
168
168
|
* @param {string} sep - 日期格式的分隔符
|
|
169
169
|
* @returns {string} 计算后的目标日期
|
|
170
170
|
*/
|
|
171
|
-
function calculateDate(
|
|
172
|
-
//
|
|
173
|
-
const
|
|
174
|
-
const newDate = new Date(
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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
|
-
|
|
201
|
+
String(targetDateTime.getMonth() + 1).padStart(2, '0') +
|
|
216
202
|
separator1 +
|
|
217
|
-
|
|
203
|
+
String(targetDateTime.getDate()).padStart(2, '0') +
|
|
218
204
|
' ' +
|
|
219
|
-
|
|
205
|
+
String(targetDateTime.getHours()).padStart(2, '0') +
|
|
220
206
|
separator2 +
|
|
221
|
-
|
|
207
|
+
String(targetDateTime.getMinutes()).padStart(2, '0') +
|
|
222
208
|
separator2 +
|
|
223
|
-
|
|
209
|
+
String(targetDateTime.getSeconds()).padStart(2, '0'));
|
|
224
210
|
}
|
|
225
211
|
|
|
226
212
|
exports.calculateDate = calculateDate;
|
package/lib/cjs/dom.js
CHANGED
package/lib/cjs/download.js
CHANGED
package/lib/cjs/easing.js
CHANGED
package/lib/cjs/file.js
CHANGED
package/lib/cjs/func.js
CHANGED
package/lib/cjs/index.js
CHANGED
package/lib/cjs/number.js
CHANGED
package/lib/cjs/object.js
CHANGED
package/lib/cjs/path.js
CHANGED
package/lib/cjs/qs.js
CHANGED
package/lib/cjs/random.js
CHANGED
package/lib/cjs/string.js
CHANGED
package/lib/cjs/tooltip.js
CHANGED
package/lib/cjs/tree.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
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
|
|
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
|
|
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
package/lib/cjs/unique.js
CHANGED
package/lib/cjs/url.js
CHANGED
package/lib/cjs/watermark.js
CHANGED
package/lib/cjs/we-decode.js
CHANGED
package/lib/es/array.js
CHANGED
package/lib/es/async.js
CHANGED
package/lib/es/clipboard.js
CHANGED
package/lib/es/cookie.js
CHANGED
package/lib/es/date.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
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 {
|
|
164
|
+
* @param {DateValue} originDate - 参考日期
|
|
165
165
|
* @param {number} n - 正数:向后推算;负数:向前推算
|
|
166
166
|
* @param {string} sep - 日期格式的分隔符
|
|
167
167
|
* @returns {string} 计算后的目标日期
|
|
168
168
|
*/
|
|
169
|
-
function calculateDate(
|
|
170
|
-
//
|
|
171
|
-
const
|
|
172
|
-
const newDate = new Date(
|
|
173
|
-
const
|
|
174
|
-
const
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
199
|
+
String(targetDateTime.getMonth() + 1).padStart(2, '0') +
|
|
214
200
|
separator1 +
|
|
215
|
-
|
|
201
|
+
String(targetDateTime.getDate()).padStart(2, '0') +
|
|
216
202
|
' ' +
|
|
217
|
-
|
|
203
|
+
String(targetDateTime.getHours()).padStart(2, '0') +
|
|
218
204
|
separator2 +
|
|
219
|
-
|
|
205
|
+
String(targetDateTime.getMinutes()).padStart(2, '0') +
|
|
220
206
|
separator2 +
|
|
221
|
-
|
|
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
package/lib/es/download.js
CHANGED
package/lib/es/easing.js
CHANGED
package/lib/es/file.js
CHANGED
package/lib/es/func.js
CHANGED
package/lib/es/index.js
CHANGED
package/lib/es/number.js
CHANGED
package/lib/es/object.js
CHANGED
package/lib/es/path.js
CHANGED
package/lib/es/qs.js
CHANGED
package/lib/es/random.js
CHANGED
package/lib/es/string.js
CHANGED
package/lib/es/tooltip.js
CHANGED
package/lib/es/tree.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
*
|
|
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
|
|
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
|
|
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
package/lib/es/unique.js
CHANGED
package/lib/es/url.js
CHANGED
package/lib/es/watermark.js
CHANGED
package/lib/es/we-decode.js
CHANGED
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 {
|
|
163
|
+
* @param {DateValue} originDate - 参考日期
|
|
164
164
|
* @param {number} n - 正数:向后推算;负数:向前推算
|
|
165
165
|
* @param {string} sep - 日期格式的分隔符
|
|
166
166
|
* @returns {string} 计算后的目标日期
|
|
167
167
|
*/
|
|
168
|
-
declare function calculateDate(
|
|
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
|
-
*
|
|
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.
|
|
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 {
|
|
916
|
+
* @param {DateValue} originDate - 参考日期
|
|
917
917
|
* @param {number} n - 正数:向后推算;负数:向前推算
|
|
918
918
|
* @param {string} sep - 日期格式的分隔符
|
|
919
919
|
* @returns {string} 计算后的目标日期
|
|
920
920
|
*/
|
|
921
|
-
function calculateDate(
|
|
922
|
-
//
|
|
923
|
-
const
|
|
924
|
-
const newDate = new Date(
|
|
925
|
-
const
|
|
926
|
-
const
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
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
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
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
|
-
|
|
951
|
+
String(targetDateTime.getMonth() + 1).padStart(2, '0') +
|
|
966
952
|
separator1 +
|
|
967
|
-
|
|
953
|
+
String(targetDateTime.getDate()).padStart(2, '0') +
|
|
968
954
|
' ' +
|
|
969
|
-
|
|
955
|
+
String(targetDateTime.getHours()).padStart(2, '0') +
|
|
970
956
|
separator2 +
|
|
971
|
-
|
|
957
|
+
String(targetDateTime.getMinutes()).padStart(2, '0') +
|
|
972
958
|
separator2 +
|
|
973
|
-
|
|
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
|
|
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
|
|
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.
|
|
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",
|