@ceale/util 1.16.0 → 1.18.0
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 +2 -0
- package/dist/cjs/index.js +130 -123
- package/dist/esm/index.js +115 -99
- package/dist/types/class.d.ts +1 -1
- package/dist/types/error.d.ts +19 -7
- package/dist/types/type.d.ts +10 -0
- package/package.json +11 -14
package/README.md
CHANGED
package/dist/cjs/index.js
CHANGED
|
@@ -1,53 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __moduleCache = /* @__PURE__ */ new WeakMap;
|
|
6
|
-
var __toCommonJS = (from) => {
|
|
7
|
-
var entry = __moduleCache.get(from), desc;
|
|
8
|
-
if (entry)
|
|
9
|
-
return entry;
|
|
10
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
12
|
-
__getOwnPropNames(from).map((key) => !__hasOwnProp.call(entry, key) && __defProp(entry, key, {
|
|
13
|
-
get: () => from[key],
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
}));
|
|
16
|
-
__moduleCache.set(from, entry);
|
|
17
|
-
return entry;
|
|
18
|
-
};
|
|
19
6
|
var __export = (target, all) => {
|
|
20
7
|
for (var name in all)
|
|
21
|
-
__defProp(target, name, {
|
|
22
|
-
get: all[name],
|
|
23
|
-
enumerable: true,
|
|
24
|
-
configurable: true,
|
|
25
|
-
set: (newValue) => all[name] = () => newValue
|
|
26
|
-
});
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
9
|
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
19
|
|
|
29
20
|
// src/index.ts
|
|
30
|
-
var
|
|
31
|
-
__export(
|
|
32
|
-
|
|
33
|
-
wait: () => wait,
|
|
34
|
-
uri: () => uri,
|
|
35
|
-
tryCatch: () => tryCatch,
|
|
36
|
-
throttle: () => throttle,
|
|
37
|
-
sleepAsync: () => sleepAsync,
|
|
38
|
-
sleep: () => sleep,
|
|
39
|
-
quadraticCurve: () => quadraticCurve,
|
|
40
|
-
expand: () => expand,
|
|
41
|
-
defineEnum: () => defineEnum,
|
|
42
|
-
debounce: () => debounce,
|
|
43
|
-
cubicCurve: () => cubicCurve,
|
|
44
|
-
css: () => css,
|
|
45
|
-
assert: () => assert,
|
|
46
|
-
QuadraticBezier: () => QuadraticBezier,
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
CubicBezier: () => CubicBezier,
|
|
47
24
|
Enum: () => Enum,
|
|
48
|
-
|
|
25
|
+
QuadraticBezier: () => QuadraticBezier,
|
|
26
|
+
assert: () => assert,
|
|
27
|
+
css: () => css,
|
|
28
|
+
cubicCurve: () => cubicCurve,
|
|
29
|
+
debounce: () => debounce,
|
|
30
|
+
defineEnum: () => defineEnum,
|
|
31
|
+
expand: () => expand,
|
|
32
|
+
quadraticCurve: () => quadraticCurve,
|
|
33
|
+
sleep: () => sleep,
|
|
34
|
+
sleepAsync: () => sleepAsync,
|
|
35
|
+
throttle: () => throttle,
|
|
36
|
+
tryCatch: () => tryCatch,
|
|
37
|
+
uri: () => uri,
|
|
38
|
+
wait: () => wait,
|
|
39
|
+
waitSync: () => waitSync
|
|
49
40
|
});
|
|
50
|
-
module.exports = __toCommonJS(
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
51
42
|
|
|
52
43
|
// src/string.ts
|
|
53
44
|
Object.defineProperty(String.prototype, "removePrefix", {
|
|
@@ -68,8 +59,7 @@ Object.defineProperty(String.prototype, "removeSuffix", {
|
|
|
68
59
|
});
|
|
69
60
|
Object.defineProperty(String.prototype, "removeAllPrefixes", {
|
|
70
61
|
value: function(prefix) {
|
|
71
|
-
if (prefix.length === 0)
|
|
72
|
-
return this;
|
|
62
|
+
if (prefix.length === 0) return this;
|
|
73
63
|
let str = this;
|
|
74
64
|
while (str.startsWith(prefix)) {
|
|
75
65
|
str = str.slice(prefix.length);
|
|
@@ -82,8 +72,7 @@ Object.defineProperty(String.prototype, "removeAllPrefixes", {
|
|
|
82
72
|
});
|
|
83
73
|
Object.defineProperty(String.prototype, "removeAllSuffixes", {
|
|
84
74
|
value: function(suffix) {
|
|
85
|
-
if (suffix.length === 0)
|
|
86
|
-
return this;
|
|
75
|
+
if (suffix.length === 0) return this;
|
|
87
76
|
let str = this;
|
|
88
77
|
while (str.endsWith(suffix)) {
|
|
89
78
|
str = str.slice(0, -suffix.length);
|
|
@@ -110,13 +99,14 @@ Object.defineProperty(String.prototype, "toKebabCase", {
|
|
|
110
99
|
configurable: true,
|
|
111
100
|
enumerable: false
|
|
112
101
|
});
|
|
102
|
+
|
|
113
103
|
// src/uri.ts
|
|
114
104
|
var uri;
|
|
115
|
-
((
|
|
105
|
+
((uri2) => {
|
|
116
106
|
const leftSlash = /^\/(?=[^\/])/g;
|
|
117
107
|
const rightSlash = /(?<=[^\/])\/$/g;
|
|
118
108
|
const innerSlash = /(?<=[^\/])\/(?=[^\/])/g;
|
|
119
|
-
|
|
109
|
+
uri2.join = (...path) => {
|
|
120
110
|
return path.filter((path2) => path2.length > 0).map((path2, index, pathArray) => {
|
|
121
111
|
if (index === 0) {
|
|
122
112
|
return path2.replace(rightSlash, "").split(innerSlash);
|
|
@@ -145,7 +135,8 @@ var uri;
|
|
|
145
135
|
}
|
|
146
136
|
}, "");
|
|
147
137
|
};
|
|
148
|
-
})(uri
|
|
138
|
+
})(uri || (uri = {}));
|
|
139
|
+
|
|
149
140
|
// src/class.ts
|
|
150
141
|
Object.defineProperty(Function.prototype, "isDirectSubclass", {
|
|
151
142
|
value: function(potentialChild) {
|
|
@@ -169,8 +160,7 @@ Object.defineProperty(Function.prototype, "isSubclass", {
|
|
|
169
160
|
return true;
|
|
170
161
|
}
|
|
171
162
|
current = Object.getPrototypeOf(current);
|
|
172
|
-
if (current === Function.prototype)
|
|
173
|
-
break;
|
|
163
|
+
if (current === Function.prototype) break;
|
|
174
164
|
}
|
|
175
165
|
return false;
|
|
176
166
|
},
|
|
@@ -197,24 +187,24 @@ Object.defineProperty(Function.prototype, "isInstance", {
|
|
|
197
187
|
configurable: true,
|
|
198
188
|
enumerable: false
|
|
199
189
|
});
|
|
190
|
+
|
|
200
191
|
// src/css.ts
|
|
201
192
|
var css;
|
|
202
|
-
((
|
|
203
|
-
|
|
204
|
-
return Object.entries(rule2).map(([key, value]) => `${key.toKebabCase()}: ${value};`).join(
|
|
205
|
-
`);
|
|
193
|
+
((css2) => {
|
|
194
|
+
css2.rule = (rule2) => {
|
|
195
|
+
return Object.entries(rule2).map(([key, value]) => `${key.toKebabCase()}: ${value};`).join("\n");
|
|
206
196
|
};
|
|
207
|
-
|
|
197
|
+
css2.selector = (selector2, rule2) => {
|
|
208
198
|
return selector2 + "{" + rule2 + "}";
|
|
209
199
|
};
|
|
210
|
-
|
|
200
|
+
css2.at = (identifier, rule2) => {
|
|
211
201
|
return identifier + (rule2 ? "{" + rule2 + "}" : "");
|
|
212
202
|
};
|
|
213
|
-
|
|
214
|
-
return rules.join(
|
|
215
|
-
`);
|
|
203
|
+
css2.join = (...rules) => {
|
|
204
|
+
return rules.join("\n");
|
|
216
205
|
};
|
|
217
|
-
})(css
|
|
206
|
+
})(css || (css = {}));
|
|
207
|
+
|
|
218
208
|
// src/time.ts
|
|
219
209
|
var wait = async (time) => {
|
|
220
210
|
return new Promise((resolve) => setTimeout(resolve, time));
|
|
@@ -222,11 +212,10 @@ var wait = async (time) => {
|
|
|
222
212
|
var sleepAsync = wait;
|
|
223
213
|
var sleep = (time) => {
|
|
224
214
|
const start = Date.now();
|
|
225
|
-
while (true)
|
|
226
|
-
if (Date.now() - start >= time)
|
|
227
|
-
return;
|
|
215
|
+
while (true) if (Date.now() - start >= time) return;
|
|
228
216
|
};
|
|
229
217
|
var waitSync = sleep;
|
|
218
|
+
|
|
230
219
|
// src/task.ts
|
|
231
220
|
var debounce = (func, delay) => {
|
|
232
221
|
let timer = null;
|
|
@@ -258,30 +247,29 @@ var throttle = (func, delay) => {
|
|
|
258
247
|
}, delay);
|
|
259
248
|
};
|
|
260
249
|
};
|
|
250
|
+
|
|
261
251
|
// src/bezier.ts
|
|
262
252
|
var quadraticCurve;
|
|
263
|
-
((
|
|
264
|
-
|
|
253
|
+
((quadraticCurve2) => {
|
|
254
|
+
quadraticCurve2.solveX = (p1, t) => {
|
|
265
255
|
const [p1x, p1y] = p1;
|
|
266
256
|
const oneMinusT = 1 - t;
|
|
267
257
|
return 2 * oneMinusT * t * p1x + t * t;
|
|
268
258
|
};
|
|
269
|
-
|
|
259
|
+
quadraticCurve2.solveY = (p1, t) => {
|
|
270
260
|
const [p1x, p1y] = p1;
|
|
271
261
|
const oneMinusT = 1 - t;
|
|
272
262
|
return 2 * oneMinusT * t * p1y + t * t;
|
|
273
263
|
};
|
|
274
|
-
|
|
275
|
-
if (x <= 0)
|
|
276
|
-
|
|
277
|
-
if (x >= 1)
|
|
278
|
-
return 1;
|
|
264
|
+
quadraticCurve2.solveTForX = (p1, x, iterations = 15) => {
|
|
265
|
+
if (x <= 0) return 0;
|
|
266
|
+
if (x >= 1) return 1;
|
|
279
267
|
let tMin = 0;
|
|
280
268
|
let tMax = 1;
|
|
281
269
|
let tGuess;
|
|
282
|
-
for (let i = 0;i < iterations; i++) {
|
|
270
|
+
for (let i = 0; i < iterations; i++) {
|
|
283
271
|
tGuess = (tMin + tMax) / 2;
|
|
284
|
-
const xGuess =
|
|
272
|
+
const xGuess = (0, quadraticCurve2.solveX)(p1, tGuess);
|
|
285
273
|
if (xGuess < x) {
|
|
286
274
|
tMin = tGuess;
|
|
287
275
|
} else {
|
|
@@ -290,38 +278,36 @@ var quadraticCurve;
|
|
|
290
278
|
}
|
|
291
279
|
return (tMin + tMax) / 2;
|
|
292
280
|
};
|
|
293
|
-
|
|
294
|
-
const t =
|
|
295
|
-
return
|
|
281
|
+
quadraticCurve2.solveYForX = (p1, x, iterations = 15) => {
|
|
282
|
+
const t = (0, quadraticCurve2.solveTForX)(p1, x, iterations);
|
|
283
|
+
return (0, quadraticCurve2.solveY)(p1, t);
|
|
296
284
|
};
|
|
297
|
-
})(quadraticCurve
|
|
285
|
+
})(quadraticCurve || (quadraticCurve = {}));
|
|
298
286
|
var cubicCurve;
|
|
299
|
-
((
|
|
300
|
-
|
|
287
|
+
((cubicCurve2) => {
|
|
288
|
+
cubicCurve2.solveX = ([p1, p2], t) => {
|
|
301
289
|
const [p1x, p1y] = p1;
|
|
302
290
|
const [p2x, p2y] = p2;
|
|
303
291
|
const oneMinusT = 1 - t;
|
|
304
292
|
const t2 = t * t;
|
|
305
293
|
return 3 * oneMinusT * oneMinusT * t * p1x + 3 * oneMinusT * t2 * p2x + t2 * t;
|
|
306
294
|
};
|
|
307
|
-
|
|
295
|
+
cubicCurve2.solveY = ([p1, p2], t) => {
|
|
308
296
|
const [p1x, p1y] = p1;
|
|
309
297
|
const [p2x, p2y] = p2;
|
|
310
298
|
const oneMinusT = 1 - t;
|
|
311
299
|
const t2 = t * t;
|
|
312
300
|
return 3 * oneMinusT * oneMinusT * t * p1y + 3 * oneMinusT * t2 * p2y + t2 * t;
|
|
313
301
|
};
|
|
314
|
-
|
|
315
|
-
if (x <= 0)
|
|
316
|
-
|
|
317
|
-
if (x >= 1)
|
|
318
|
-
return 1;
|
|
302
|
+
cubicCurve2.solveTForX = ([p1, p2], x, iterations = 20) => {
|
|
303
|
+
if (x <= 0) return 0;
|
|
304
|
+
if (x >= 1) return 1;
|
|
319
305
|
let tMin = 0;
|
|
320
306
|
let tMax = 1;
|
|
321
307
|
let tGuess;
|
|
322
|
-
for (let i = 0;i < iterations; i++) {
|
|
308
|
+
for (let i = 0; i < iterations; i++) {
|
|
323
309
|
tGuess = (tMin + tMax) / 2;
|
|
324
|
-
const xGuess =
|
|
310
|
+
const xGuess = (0, cubicCurve2.solveX)([p1, p2], tGuess);
|
|
325
311
|
if (xGuess < x) {
|
|
326
312
|
tMin = tGuess;
|
|
327
313
|
} else {
|
|
@@ -330,35 +316,44 @@ var cubicCurve;
|
|
|
330
316
|
}
|
|
331
317
|
return (tMin + tMax) / 2;
|
|
332
318
|
};
|
|
333
|
-
|
|
334
|
-
const t =
|
|
335
|
-
return
|
|
319
|
+
cubicCurve2.solveYForX = ([p1, p2], x, iterations = 20) => {
|
|
320
|
+
const t = (0, cubicCurve2.solveTForX)([p1, p2], x, iterations);
|
|
321
|
+
return (0, cubicCurve2.solveY)([p1, p2], t);
|
|
336
322
|
};
|
|
337
|
-
})(cubicCurve
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
323
|
+
})(cubicCurve || (cubicCurve = {}));
|
|
324
|
+
var QuadraticBezier = class {
|
|
325
|
+
/**
|
|
326
|
+
* @param p1 控制点 P1
|
|
327
|
+
* @param accuracy 缓存精度(`10^-accuracy`),默认为`4`,`-1`则表示不缓存
|
|
328
|
+
*/
|
|
343
329
|
constructor(p1, accuracy = 4) {
|
|
344
330
|
this.p1 = p1;
|
|
345
331
|
this.accuracy = accuracy;
|
|
346
332
|
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
347
|
-
throw new TypeError("
|
|
333
|
+
throw new TypeError("\u63A7\u5236\u70B9P1\u7684x\u5750\u6807\u5FC5\u987B\u5728[0, 1]\u4E4B\u95F4");
|
|
348
334
|
}
|
|
349
335
|
if (accuracy !== -1) {
|
|
350
336
|
this.accuracy = 10 ** accuracy;
|
|
351
337
|
}
|
|
352
338
|
}
|
|
339
|
+
cache = /* @__PURE__ */ new Map();
|
|
340
|
+
/**
|
|
341
|
+
* 根据时间 t [0, 1],计算 x 坐标
|
|
342
|
+
*/
|
|
353
343
|
solveX(t) {
|
|
354
344
|
return quadraticCurve.solveX(this.p1, t);
|
|
355
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* 根据时间 t [0, 1],计算 y 坐标
|
|
348
|
+
*/
|
|
356
349
|
solveY(t) {
|
|
357
350
|
return quadraticCurve.solveY(this.p1, t);
|
|
358
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* 根据 x 坐标 [0, 1],计算 y 坐标
|
|
354
|
+
*/
|
|
359
355
|
solveYForX(x) {
|
|
360
|
-
if (this.accuracy === -1)
|
|
361
|
-
return quadraticCurve.solveYForX(this.p1, x);
|
|
356
|
+
if (this.accuracy === -1) return quadraticCurve.solveYForX(this.p1, x);
|
|
362
357
|
else {
|
|
363
358
|
const roughX = Math.round(x * this.accuracy);
|
|
364
359
|
return this.cache.get(roughX) ?? (() => {
|
|
@@ -368,36 +363,45 @@ class QuadraticBezier {
|
|
|
368
363
|
})();
|
|
369
364
|
}
|
|
370
365
|
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
366
|
+
};
|
|
367
|
+
var CubicBezier = class {
|
|
368
|
+
/**
|
|
369
|
+
* @param p1 控制点 P1
|
|
370
|
+
* @param p2 控制点 P2
|
|
371
|
+
* @param accuracy 缓存精度(`10^-accuracy`),默认为`4`,`-1`则表示不缓存
|
|
372
|
+
*/
|
|
378
373
|
constructor(p1, p2, accuracy = 4) {
|
|
379
374
|
this.p1 = p1;
|
|
380
375
|
this.p2 = p2;
|
|
381
376
|
this.accuracy = accuracy;
|
|
382
377
|
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
383
|
-
throw new TypeError("
|
|
378
|
+
throw new TypeError("\u63A7\u5236\u70B9P1\u7684x\u5750\u6807\u5FC5\u987B\u5728[0, 1]\u4E4B\u95F4");
|
|
384
379
|
}
|
|
385
380
|
if (this.p2[0] < 0 || this.p2[0] > 1) {
|
|
386
|
-
throw new TypeError("
|
|
381
|
+
throw new TypeError("\u63A7\u5236\u70B9P2\u7684x\u5750\u6807\u5FC5\u987B\u5728[0, 1]\u4E4B\u95F4");
|
|
387
382
|
}
|
|
388
383
|
if (accuracy !== -1) {
|
|
389
384
|
this.accuracy = 10 ** accuracy;
|
|
390
385
|
}
|
|
391
386
|
}
|
|
387
|
+
cache = /* @__PURE__ */ new Map();
|
|
388
|
+
/**
|
|
389
|
+
* 根据时间 t [0, 1],计算 x 坐标
|
|
390
|
+
*/
|
|
392
391
|
solveX(t) {
|
|
393
392
|
return cubicCurve.solveX([this.p1, this.p2], t);
|
|
394
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* 根据时间 t [0, 1],计算 y 坐标
|
|
396
|
+
*/
|
|
395
397
|
solveY(t) {
|
|
396
398
|
return cubicCurve.solveY([this.p1, this.p2], t);
|
|
397
399
|
}
|
|
400
|
+
/**
|
|
401
|
+
* 根据 x 坐标 [0, 1],计算 y 坐标
|
|
402
|
+
*/
|
|
398
403
|
solveYForX(x) {
|
|
399
|
-
if (this.accuracy === -1)
|
|
400
|
-
return cubicCurve.solveYForX([this.p1, this.p2], x);
|
|
404
|
+
if (this.accuracy === -1) return cubicCurve.solveYForX([this.p1, this.p2], x);
|
|
401
405
|
else {
|
|
402
406
|
const roughX = Math.round(x * this.accuracy);
|
|
403
407
|
return this.cache.get(roughX) ?? (() => {
|
|
@@ -407,22 +411,26 @@ class CubicBezier {
|
|
|
407
411
|
})();
|
|
408
412
|
}
|
|
409
413
|
}
|
|
410
|
-
}
|
|
414
|
+
};
|
|
415
|
+
|
|
411
416
|
// src/error.ts
|
|
412
|
-
var tryCatch = (
|
|
413
|
-
if (typeof
|
|
414
|
-
return parameter.then((data) => Object.assign([data, null], { data, error: null })).catch((error) => Object.assign([null, error], { data: null, error }));
|
|
415
|
-
}
|
|
416
|
-
if (typeof parameter === "function") {
|
|
417
|
+
var tryCatch = (func, catchClass) => {
|
|
418
|
+
if (typeof func === "function") {
|
|
417
419
|
try {
|
|
418
|
-
const data =
|
|
420
|
+
const data = func();
|
|
419
421
|
return Object.assign([data, null], { data, error: null });
|
|
420
422
|
} catch (error) {
|
|
421
|
-
return Object.assign([null, error], { data: null, error });
|
|
423
|
+
if (!catchClass || error instanceof catchClass) return Object.assign([null, error], { data: null, error });
|
|
424
|
+
throw error;
|
|
422
425
|
}
|
|
426
|
+
} else {
|
|
427
|
+
return func.then((data) => Object.assign([data, null], { data, error: null })).catch((error) => {
|
|
428
|
+
if (!catchClass || error instanceof catchClass) return Object.assign([null, error], { data: null, error });
|
|
429
|
+
throw error;
|
|
430
|
+
});
|
|
423
431
|
}
|
|
424
|
-
throw new TypeError("参数类型错误,应为 Promise 或函数");
|
|
425
432
|
};
|
|
433
|
+
|
|
426
434
|
// src/type.ts
|
|
427
435
|
var assert = (variable) => variable;
|
|
428
436
|
var expand = (variable) => variable;
|
|
@@ -434,11 +442,11 @@ var Enum = (keys) => ({
|
|
|
434
442
|
keys: () => Object.keys(keys),
|
|
435
443
|
includes: (key) => Object.keys(keys).includes(key)
|
|
436
444
|
});
|
|
445
|
+
|
|
437
446
|
// src/object.ts
|
|
438
447
|
Object.defineProperty(Object.prototype, "hasKeys", {
|
|
439
448
|
value: function(...keys) {
|
|
440
|
-
if (keys.length === 0)
|
|
441
|
-
return false;
|
|
449
|
+
if (keys.length === 0) return false;
|
|
442
450
|
return keys.every((key) => this.hasOwnProperty(key));
|
|
443
451
|
},
|
|
444
452
|
enumerable: false,
|
|
@@ -447,9 +455,8 @@ Object.defineProperty(Object.prototype, "hasKeys", {
|
|
|
447
455
|
});
|
|
448
456
|
Object.defineProperty(Object.prototype, "inKeys", {
|
|
449
457
|
value: function(...keys) {
|
|
450
|
-
if (keys.length === 0)
|
|
451
|
-
|
|
452
|
-
return keys.every((key) => (key in this));
|
|
458
|
+
if (keys.length === 0) return false;
|
|
459
|
+
return keys.every((key) => key in this);
|
|
453
460
|
},
|
|
454
461
|
enumerable: false,
|
|
455
462
|
writable: true,
|
package/dist/esm/index.js
CHANGED
|
@@ -17,8 +17,7 @@ Object.defineProperty(String.prototype, "removeSuffix", {
|
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(String.prototype, "removeAllPrefixes", {
|
|
19
19
|
value: function(prefix) {
|
|
20
|
-
if (prefix.length === 0)
|
|
21
|
-
return this;
|
|
20
|
+
if (prefix.length === 0) return this;
|
|
22
21
|
let str = this;
|
|
23
22
|
while (str.startsWith(prefix)) {
|
|
24
23
|
str = str.slice(prefix.length);
|
|
@@ -31,8 +30,7 @@ Object.defineProperty(String.prototype, "removeAllPrefixes", {
|
|
|
31
30
|
});
|
|
32
31
|
Object.defineProperty(String.prototype, "removeAllSuffixes", {
|
|
33
32
|
value: function(suffix) {
|
|
34
|
-
if (suffix.length === 0)
|
|
35
|
-
return this;
|
|
33
|
+
if (suffix.length === 0) return this;
|
|
36
34
|
let str = this;
|
|
37
35
|
while (str.endsWith(suffix)) {
|
|
38
36
|
str = str.slice(0, -suffix.length);
|
|
@@ -59,13 +57,14 @@ Object.defineProperty(String.prototype, "toKebabCase", {
|
|
|
59
57
|
configurable: true,
|
|
60
58
|
enumerable: false
|
|
61
59
|
});
|
|
60
|
+
|
|
62
61
|
// src/uri.ts
|
|
63
62
|
var uri;
|
|
64
|
-
((
|
|
63
|
+
((uri2) => {
|
|
65
64
|
const leftSlash = /^\/(?=[^\/])/g;
|
|
66
65
|
const rightSlash = /(?<=[^\/])\/$/g;
|
|
67
66
|
const innerSlash = /(?<=[^\/])\/(?=[^\/])/g;
|
|
68
|
-
|
|
67
|
+
uri2.join = (...path) => {
|
|
69
68
|
return path.filter((path2) => path2.length > 0).map((path2, index, pathArray) => {
|
|
70
69
|
if (index === 0) {
|
|
71
70
|
return path2.replace(rightSlash, "").split(innerSlash);
|
|
@@ -94,7 +93,8 @@ var uri;
|
|
|
94
93
|
}
|
|
95
94
|
}, "");
|
|
96
95
|
};
|
|
97
|
-
})(uri
|
|
96
|
+
})(uri || (uri = {}));
|
|
97
|
+
|
|
98
98
|
// src/class.ts
|
|
99
99
|
Object.defineProperty(Function.prototype, "isDirectSubclass", {
|
|
100
100
|
value: function(potentialChild) {
|
|
@@ -118,8 +118,7 @@ Object.defineProperty(Function.prototype, "isSubclass", {
|
|
|
118
118
|
return true;
|
|
119
119
|
}
|
|
120
120
|
current = Object.getPrototypeOf(current);
|
|
121
|
-
if (current === Function.prototype)
|
|
122
|
-
break;
|
|
121
|
+
if (current === Function.prototype) break;
|
|
123
122
|
}
|
|
124
123
|
return false;
|
|
125
124
|
},
|
|
@@ -146,24 +145,24 @@ Object.defineProperty(Function.prototype, "isInstance", {
|
|
|
146
145
|
configurable: true,
|
|
147
146
|
enumerable: false
|
|
148
147
|
});
|
|
148
|
+
|
|
149
149
|
// src/css.ts
|
|
150
150
|
var css;
|
|
151
|
-
((
|
|
152
|
-
|
|
153
|
-
return Object.entries(rule2).map(([key, value]) => `${key.toKebabCase()}: ${value};`).join(
|
|
154
|
-
`);
|
|
151
|
+
((css2) => {
|
|
152
|
+
css2.rule = (rule2) => {
|
|
153
|
+
return Object.entries(rule2).map(([key, value]) => `${key.toKebabCase()}: ${value};`).join("\n");
|
|
155
154
|
};
|
|
156
|
-
|
|
155
|
+
css2.selector = (selector2, rule2) => {
|
|
157
156
|
return selector2 + "{" + rule2 + "}";
|
|
158
157
|
};
|
|
159
|
-
|
|
158
|
+
css2.at = (identifier, rule2) => {
|
|
160
159
|
return identifier + (rule2 ? "{" + rule2 + "}" : "");
|
|
161
160
|
};
|
|
162
|
-
|
|
163
|
-
return rules.join(
|
|
164
|
-
`);
|
|
161
|
+
css2.join = (...rules) => {
|
|
162
|
+
return rules.join("\n");
|
|
165
163
|
};
|
|
166
|
-
})(css
|
|
164
|
+
})(css || (css = {}));
|
|
165
|
+
|
|
167
166
|
// src/time.ts
|
|
168
167
|
var wait = async (time) => {
|
|
169
168
|
return new Promise((resolve) => setTimeout(resolve, time));
|
|
@@ -171,11 +170,10 @@ var wait = async (time) => {
|
|
|
171
170
|
var sleepAsync = wait;
|
|
172
171
|
var sleep = (time) => {
|
|
173
172
|
const start = Date.now();
|
|
174
|
-
while (true)
|
|
175
|
-
if (Date.now() - start >= time)
|
|
176
|
-
return;
|
|
173
|
+
while (true) if (Date.now() - start >= time) return;
|
|
177
174
|
};
|
|
178
175
|
var waitSync = sleep;
|
|
176
|
+
|
|
179
177
|
// src/task.ts
|
|
180
178
|
var debounce = (func, delay) => {
|
|
181
179
|
let timer = null;
|
|
@@ -207,30 +205,29 @@ var throttle = (func, delay) => {
|
|
|
207
205
|
}, delay);
|
|
208
206
|
};
|
|
209
207
|
};
|
|
208
|
+
|
|
210
209
|
// src/bezier.ts
|
|
211
210
|
var quadraticCurve;
|
|
212
|
-
((
|
|
213
|
-
|
|
211
|
+
((quadraticCurve2) => {
|
|
212
|
+
quadraticCurve2.solveX = (p1, t) => {
|
|
214
213
|
const [p1x, p1y] = p1;
|
|
215
214
|
const oneMinusT = 1 - t;
|
|
216
215
|
return 2 * oneMinusT * t * p1x + t * t;
|
|
217
216
|
};
|
|
218
|
-
|
|
217
|
+
quadraticCurve2.solveY = (p1, t) => {
|
|
219
218
|
const [p1x, p1y] = p1;
|
|
220
219
|
const oneMinusT = 1 - t;
|
|
221
220
|
return 2 * oneMinusT * t * p1y + t * t;
|
|
222
221
|
};
|
|
223
|
-
|
|
224
|
-
if (x <= 0)
|
|
225
|
-
|
|
226
|
-
if (x >= 1)
|
|
227
|
-
return 1;
|
|
222
|
+
quadraticCurve2.solveTForX = (p1, x, iterations = 15) => {
|
|
223
|
+
if (x <= 0) return 0;
|
|
224
|
+
if (x >= 1) return 1;
|
|
228
225
|
let tMin = 0;
|
|
229
226
|
let tMax = 1;
|
|
230
227
|
let tGuess;
|
|
231
|
-
for (let i = 0;i < iterations; i++) {
|
|
228
|
+
for (let i = 0; i < iterations; i++) {
|
|
232
229
|
tGuess = (tMin + tMax) / 2;
|
|
233
|
-
const xGuess =
|
|
230
|
+
const xGuess = (0, quadraticCurve2.solveX)(p1, tGuess);
|
|
234
231
|
if (xGuess < x) {
|
|
235
232
|
tMin = tGuess;
|
|
236
233
|
} else {
|
|
@@ -239,38 +236,36 @@ var quadraticCurve;
|
|
|
239
236
|
}
|
|
240
237
|
return (tMin + tMax) / 2;
|
|
241
238
|
};
|
|
242
|
-
|
|
243
|
-
const t =
|
|
244
|
-
return
|
|
239
|
+
quadraticCurve2.solveYForX = (p1, x, iterations = 15) => {
|
|
240
|
+
const t = (0, quadraticCurve2.solveTForX)(p1, x, iterations);
|
|
241
|
+
return (0, quadraticCurve2.solveY)(p1, t);
|
|
245
242
|
};
|
|
246
|
-
})(quadraticCurve
|
|
243
|
+
})(quadraticCurve || (quadraticCurve = {}));
|
|
247
244
|
var cubicCurve;
|
|
248
|
-
((
|
|
249
|
-
|
|
245
|
+
((cubicCurve2) => {
|
|
246
|
+
cubicCurve2.solveX = ([p1, p2], t) => {
|
|
250
247
|
const [p1x, p1y] = p1;
|
|
251
248
|
const [p2x, p2y] = p2;
|
|
252
249
|
const oneMinusT = 1 - t;
|
|
253
250
|
const t2 = t * t;
|
|
254
251
|
return 3 * oneMinusT * oneMinusT * t * p1x + 3 * oneMinusT * t2 * p2x + t2 * t;
|
|
255
252
|
};
|
|
256
|
-
|
|
253
|
+
cubicCurve2.solveY = ([p1, p2], t) => {
|
|
257
254
|
const [p1x, p1y] = p1;
|
|
258
255
|
const [p2x, p2y] = p2;
|
|
259
256
|
const oneMinusT = 1 - t;
|
|
260
257
|
const t2 = t * t;
|
|
261
258
|
return 3 * oneMinusT * oneMinusT * t * p1y + 3 * oneMinusT * t2 * p2y + t2 * t;
|
|
262
259
|
};
|
|
263
|
-
|
|
264
|
-
if (x <= 0)
|
|
265
|
-
|
|
266
|
-
if (x >= 1)
|
|
267
|
-
return 1;
|
|
260
|
+
cubicCurve2.solveTForX = ([p1, p2], x, iterations = 20) => {
|
|
261
|
+
if (x <= 0) return 0;
|
|
262
|
+
if (x >= 1) return 1;
|
|
268
263
|
let tMin = 0;
|
|
269
264
|
let tMax = 1;
|
|
270
265
|
let tGuess;
|
|
271
|
-
for (let i = 0;i < iterations; i++) {
|
|
266
|
+
for (let i = 0; i < iterations; i++) {
|
|
272
267
|
tGuess = (tMin + tMax) / 2;
|
|
273
|
-
const xGuess =
|
|
268
|
+
const xGuess = (0, cubicCurve2.solveX)([p1, p2], tGuess);
|
|
274
269
|
if (xGuess < x) {
|
|
275
270
|
tMin = tGuess;
|
|
276
271
|
} else {
|
|
@@ -279,35 +274,44 @@ var cubicCurve;
|
|
|
279
274
|
}
|
|
280
275
|
return (tMin + tMax) / 2;
|
|
281
276
|
};
|
|
282
|
-
|
|
283
|
-
const t =
|
|
284
|
-
return
|
|
277
|
+
cubicCurve2.solveYForX = ([p1, p2], x, iterations = 20) => {
|
|
278
|
+
const t = (0, cubicCurve2.solveTForX)([p1, p2], x, iterations);
|
|
279
|
+
return (0, cubicCurve2.solveY)([p1, p2], t);
|
|
285
280
|
};
|
|
286
|
-
})(cubicCurve
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
281
|
+
})(cubicCurve || (cubicCurve = {}));
|
|
282
|
+
var QuadraticBezier = class {
|
|
283
|
+
/**
|
|
284
|
+
* @param p1 控制点 P1
|
|
285
|
+
* @param accuracy 缓存精度(`10^-accuracy`),默认为`4`,`-1`则表示不缓存
|
|
286
|
+
*/
|
|
292
287
|
constructor(p1, accuracy = 4) {
|
|
293
288
|
this.p1 = p1;
|
|
294
289
|
this.accuracy = accuracy;
|
|
295
290
|
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
296
|
-
throw new TypeError("
|
|
291
|
+
throw new TypeError("\u63A7\u5236\u70B9P1\u7684x\u5750\u6807\u5FC5\u987B\u5728[0, 1]\u4E4B\u95F4");
|
|
297
292
|
}
|
|
298
293
|
if (accuracy !== -1) {
|
|
299
294
|
this.accuracy = 10 ** accuracy;
|
|
300
295
|
}
|
|
301
296
|
}
|
|
297
|
+
cache = /* @__PURE__ */ new Map();
|
|
298
|
+
/**
|
|
299
|
+
* 根据时间 t [0, 1],计算 x 坐标
|
|
300
|
+
*/
|
|
302
301
|
solveX(t) {
|
|
303
302
|
return quadraticCurve.solveX(this.p1, t);
|
|
304
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* 根据时间 t [0, 1],计算 y 坐标
|
|
306
|
+
*/
|
|
305
307
|
solveY(t) {
|
|
306
308
|
return quadraticCurve.solveY(this.p1, t);
|
|
307
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* 根据 x 坐标 [0, 1],计算 y 坐标
|
|
312
|
+
*/
|
|
308
313
|
solveYForX(x) {
|
|
309
|
-
if (this.accuracy === -1)
|
|
310
|
-
return quadraticCurve.solveYForX(this.p1, x);
|
|
314
|
+
if (this.accuracy === -1) return quadraticCurve.solveYForX(this.p1, x);
|
|
311
315
|
else {
|
|
312
316
|
const roughX = Math.round(x * this.accuracy);
|
|
313
317
|
return this.cache.get(roughX) ?? (() => {
|
|
@@ -317,36 +321,45 @@ class QuadraticBezier {
|
|
|
317
321
|
})();
|
|
318
322
|
}
|
|
319
323
|
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
324
|
+
};
|
|
325
|
+
var CubicBezier = class {
|
|
326
|
+
/**
|
|
327
|
+
* @param p1 控制点 P1
|
|
328
|
+
* @param p2 控制点 P2
|
|
329
|
+
* @param accuracy 缓存精度(`10^-accuracy`),默认为`4`,`-1`则表示不缓存
|
|
330
|
+
*/
|
|
327
331
|
constructor(p1, p2, accuracy = 4) {
|
|
328
332
|
this.p1 = p1;
|
|
329
333
|
this.p2 = p2;
|
|
330
334
|
this.accuracy = accuracy;
|
|
331
335
|
if (this.p1[0] < 0 || this.p1[0] > 1) {
|
|
332
|
-
throw new TypeError("
|
|
336
|
+
throw new TypeError("\u63A7\u5236\u70B9P1\u7684x\u5750\u6807\u5FC5\u987B\u5728[0, 1]\u4E4B\u95F4");
|
|
333
337
|
}
|
|
334
338
|
if (this.p2[0] < 0 || this.p2[0] > 1) {
|
|
335
|
-
throw new TypeError("
|
|
339
|
+
throw new TypeError("\u63A7\u5236\u70B9P2\u7684x\u5750\u6807\u5FC5\u987B\u5728[0, 1]\u4E4B\u95F4");
|
|
336
340
|
}
|
|
337
341
|
if (accuracy !== -1) {
|
|
338
342
|
this.accuracy = 10 ** accuracy;
|
|
339
343
|
}
|
|
340
344
|
}
|
|
345
|
+
cache = /* @__PURE__ */ new Map();
|
|
346
|
+
/**
|
|
347
|
+
* 根据时间 t [0, 1],计算 x 坐标
|
|
348
|
+
*/
|
|
341
349
|
solveX(t) {
|
|
342
350
|
return cubicCurve.solveX([this.p1, this.p2], t);
|
|
343
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* 根据时间 t [0, 1],计算 y 坐标
|
|
354
|
+
*/
|
|
344
355
|
solveY(t) {
|
|
345
356
|
return cubicCurve.solveY([this.p1, this.p2], t);
|
|
346
357
|
}
|
|
358
|
+
/**
|
|
359
|
+
* 根据 x 坐标 [0, 1],计算 y 坐标
|
|
360
|
+
*/
|
|
347
361
|
solveYForX(x) {
|
|
348
|
-
if (this.accuracy === -1)
|
|
349
|
-
return cubicCurve.solveYForX([this.p1, this.p2], x);
|
|
362
|
+
if (this.accuracy === -1) return cubicCurve.solveYForX([this.p1, this.p2], x);
|
|
350
363
|
else {
|
|
351
364
|
const roughX = Math.round(x * this.accuracy);
|
|
352
365
|
return this.cache.get(roughX) ?? (() => {
|
|
@@ -356,22 +369,26 @@ class CubicBezier {
|
|
|
356
369
|
})();
|
|
357
370
|
}
|
|
358
371
|
}
|
|
359
|
-
}
|
|
372
|
+
};
|
|
373
|
+
|
|
360
374
|
// src/error.ts
|
|
361
|
-
var tryCatch = (
|
|
362
|
-
if (typeof
|
|
363
|
-
return parameter.then((data) => Object.assign([data, null], { data, error: null })).catch((error) => Object.assign([null, error], { data: null, error }));
|
|
364
|
-
}
|
|
365
|
-
if (typeof parameter === "function") {
|
|
375
|
+
var tryCatch = (func, catchClass) => {
|
|
376
|
+
if (typeof func === "function") {
|
|
366
377
|
try {
|
|
367
|
-
const data =
|
|
378
|
+
const data = func();
|
|
368
379
|
return Object.assign([data, null], { data, error: null });
|
|
369
380
|
} catch (error) {
|
|
370
|
-
return Object.assign([null, error], { data: null, error });
|
|
381
|
+
if (!catchClass || error instanceof catchClass) return Object.assign([null, error], { data: null, error });
|
|
382
|
+
throw error;
|
|
371
383
|
}
|
|
384
|
+
} else {
|
|
385
|
+
return func.then((data) => Object.assign([data, null], { data, error: null })).catch((error) => {
|
|
386
|
+
if (!catchClass || error instanceof catchClass) return Object.assign([null, error], { data: null, error });
|
|
387
|
+
throw error;
|
|
388
|
+
});
|
|
372
389
|
}
|
|
373
|
-
throw new TypeError("参数类型错误,应为 Promise 或函数");
|
|
374
390
|
};
|
|
391
|
+
|
|
375
392
|
// src/type.ts
|
|
376
393
|
var assert = (variable) => variable;
|
|
377
394
|
var expand = (variable) => variable;
|
|
@@ -383,11 +400,11 @@ var Enum = (keys) => ({
|
|
|
383
400
|
keys: () => Object.keys(keys),
|
|
384
401
|
includes: (key) => Object.keys(keys).includes(key)
|
|
385
402
|
});
|
|
403
|
+
|
|
386
404
|
// src/object.ts
|
|
387
405
|
Object.defineProperty(Object.prototype, "hasKeys", {
|
|
388
406
|
value: function(...keys) {
|
|
389
|
-
if (keys.length === 0)
|
|
390
|
-
return false;
|
|
407
|
+
if (keys.length === 0) return false;
|
|
391
408
|
return keys.every((key) => this.hasOwnProperty(key));
|
|
392
409
|
},
|
|
393
410
|
enumerable: false,
|
|
@@ -396,30 +413,29 @@ Object.defineProperty(Object.prototype, "hasKeys", {
|
|
|
396
413
|
});
|
|
397
414
|
Object.defineProperty(Object.prototype, "inKeys", {
|
|
398
415
|
value: function(...keys) {
|
|
399
|
-
if (keys.length === 0)
|
|
400
|
-
|
|
401
|
-
return keys.every((key) => (key in this));
|
|
416
|
+
if (keys.length === 0) return false;
|
|
417
|
+
return keys.every((key) => key in this);
|
|
402
418
|
},
|
|
403
419
|
enumerable: false,
|
|
404
420
|
writable: true,
|
|
405
421
|
configurable: true
|
|
406
422
|
});
|
|
407
423
|
export {
|
|
408
|
-
|
|
409
|
-
wait,
|
|
410
|
-
uri,
|
|
411
|
-
tryCatch,
|
|
412
|
-
throttle,
|
|
413
|
-
sleepAsync,
|
|
414
|
-
sleep,
|
|
415
|
-
quadraticCurve,
|
|
416
|
-
expand,
|
|
417
|
-
defineEnum,
|
|
418
|
-
debounce,
|
|
419
|
-
cubicCurve,
|
|
420
|
-
css,
|
|
421
|
-
assert,
|
|
422
|
-
QuadraticBezier,
|
|
424
|
+
CubicBezier,
|
|
423
425
|
Enum,
|
|
424
|
-
|
|
426
|
+
QuadraticBezier,
|
|
427
|
+
assert,
|
|
428
|
+
css,
|
|
429
|
+
cubicCurve,
|
|
430
|
+
debounce,
|
|
431
|
+
defineEnum,
|
|
432
|
+
expand,
|
|
433
|
+
quadraticCurve,
|
|
434
|
+
sleep,
|
|
435
|
+
sleepAsync,
|
|
436
|
+
throttle,
|
|
437
|
+
tryCatch,
|
|
438
|
+
uri,
|
|
439
|
+
wait,
|
|
440
|
+
waitSync
|
|
425
441
|
};
|
package/dist/types/class.d.ts
CHANGED
package/dist/types/error.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AnyClass } from "./type";
|
|
1
2
|
type Success<T> = {
|
|
2
3
|
data: T;
|
|
3
4
|
error: null;
|
|
@@ -12,28 +13,39 @@ type Failure<E> = {
|
|
|
12
13
|
data: null,
|
|
13
14
|
error: E
|
|
14
15
|
];
|
|
15
|
-
type Result<T, E
|
|
16
|
+
type Result<T, E = any> = Success<T> | Failure<E>;
|
|
16
17
|
interface tryCatch {
|
|
17
|
-
|
|
18
|
-
<
|
|
18
|
+
/** 捕获所有 */
|
|
19
|
+
<T>(func: (() => T)): Result<T>;
|
|
20
|
+
<T>(asyncFunc: Promise<T>): Promise<Result<T>>;
|
|
21
|
+
/** 捕获指定 */
|
|
22
|
+
<T, E extends AnyClass>(func: (() => T), catchClass: E): Result<T, InstanceType<E>>;
|
|
23
|
+
<T, E extends AnyClass>(func: Promise<T>, catchClass: E): Promise<Result<T, InstanceType<E>>>;
|
|
19
24
|
}
|
|
20
25
|
/**
|
|
21
|
-
* 尝试执行一个函数或Promise
|
|
26
|
+
* 尝试执行一个函数或Promise,返回一个对象,其中包含执行结果或被捕获的错误
|
|
22
27
|
*
|
|
23
28
|
* 该对象同时支持对象属性访问(.data/.error)和数组索引访问([0]/[1])两种方式
|
|
24
29
|
*
|
|
25
|
-
* @param
|
|
26
|
-
* @
|
|
30
|
+
* @param func 一个函数或者Promise对象
|
|
31
|
+
* @param catchClass 要捕获的错误类型(含子类),如果不指定,则捕获所有错误;如指定,则为被捕获的错误将继续上抛
|
|
32
|
+
* @returns 返回一个如后方例的对象`{ data, error } & [ data, error ]`
|
|
27
33
|
*
|
|
28
34
|
* @example
|
|
29
35
|
* tryCatch(() => func(...))
|
|
30
36
|
* // => [data, error] & {data, error}
|
|
31
37
|
* // data: func的返回值,error:函数执行过程中发生的错误
|
|
32
38
|
*
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* tryCatch(() => func(...), TypeError)
|
|
42
|
+
* // => [data, error] & {data, error}
|
|
43
|
+
* // data: func的返回值,error:函数执行过程中,发生的TypeError或其子类错误
|
|
44
|
+
*
|
|
33
45
|
* @example
|
|
34
46
|
* await tryCatch(asyncFunc(...))
|
|
35
47
|
* // => [data, error] & {data, error}
|
|
36
|
-
* // data: asyncFunc的返回值,error:asyncFunc执行过程中发生的错误
|
|
48
|
+
* // data: 异步函数asyncFunc的返回值,error:asyncFunc执行过程中发生的错误
|
|
37
49
|
*/
|
|
38
50
|
export declare const tryCatch: tryCatch;
|
|
39
51
|
export {};
|
package/dist/types/type.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一种介于 `any` 与 `object` 之间的类型
|
|
3
|
+
* - 与 `any` 类似,可以任意访问属性
|
|
4
|
+
* - 与 `object` 类似,排除了原始类型
|
|
5
|
+
*/
|
|
6
|
+
export type anyobject = Record<any, any>;
|
|
7
|
+
/**
|
|
8
|
+
* 表示任意的类或构造函数
|
|
9
|
+
*/
|
|
10
|
+
export type AnyClass = new (...args: any[]) => any;
|
|
1
11
|
/**
|
|
2
12
|
* 就地断言一个变量为指定类型
|
|
3
13
|
* @template Type 断言的类型,默认为`any`
|
package/package.json
CHANGED
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ceale/util",
|
|
3
|
-
"version": "1.
|
|
4
|
-
|
|
3
|
+
"version": "1.18.0",
|
|
5
4
|
"author": "Ceale",
|
|
6
5
|
"description": "小工具集",
|
|
7
6
|
"repository": {
|
|
8
7
|
"url": "git+https://github.com/Ceale/ts-util.git"
|
|
9
8
|
},
|
|
10
|
-
|
|
11
9
|
"license": "Unlicense or CC0 or WTFPL",
|
|
12
|
-
"keywords": [
|
|
13
|
-
|
|
10
|
+
"keywords": ["util"],
|
|
14
11
|
"type": "module",
|
|
15
|
-
"module": "index.ts",
|
|
16
|
-
"main": "dist/
|
|
12
|
+
"module": "dist/esm/index.ts",
|
|
13
|
+
"main": "dist/cjs/index.js",
|
|
17
14
|
"types": "dist/types/index.d.ts",
|
|
18
15
|
"files": ["dist"],
|
|
19
16
|
"exports": {
|
|
20
17
|
".": {
|
|
18
|
+
"types": "./dist/types/index.d.ts",
|
|
21
19
|
"import": "./dist/esm/index.js",
|
|
22
|
-
"require": "./dist/cjs/index.js"
|
|
23
|
-
"types": "./dist/types/index.d.ts"
|
|
20
|
+
"require": "./dist/cjs/index.js"
|
|
24
21
|
},
|
|
25
22
|
"./package.json": "./package.json"
|
|
26
23
|
},
|
|
27
|
-
|
|
28
24
|
"scripts": {
|
|
29
25
|
"build": "bun run build:esm && bun run build:cjs && bun run build:ts",
|
|
30
|
-
"build:esm": "
|
|
31
|
-
"build:cjs": "
|
|
26
|
+
"build:esm": "esbuild --outdir=dist/esm/ --format=esm --target=esnext --bundle --packages=external src/index.ts",
|
|
27
|
+
"build:cjs": "esbuild --outdir=dist/cjs/ --format=cjs --target=esnext --bundle --packages=external src/index.ts",
|
|
32
28
|
"build:ts": "tsc --project tsconfig.build.json"
|
|
33
29
|
},
|
|
34
30
|
"devDependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
31
|
+
"@types/bun": "latest",
|
|
32
|
+
"esbuild": "^0.27.0",
|
|
33
|
+
"typescript": "^5"
|
|
37
34
|
},
|
|
38
35
|
"dependencies": {
|
|
39
36
|
"csstype": "^3.1.3"
|