@ceale/util 1.12.4 → 1.13.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 CHANGED
@@ -40,4 +40,6 @@
40
40
  - class `QuadraticBezier`
41
41
  - class `CubicBezier`
42
42
  - `error.ts`
43
- - tryCatch()
43
+ - tryCatch()
44
+ - `type.ts`
45
+ - assert()
package/dist/cjs/index.js CHANGED
@@ -1,20 +1,7 @@
1
- var __create = Object.create;
2
- var __getProtoOf = Object.getPrototypeOf;
3
1
  var __defProp = Object.defineProperty;
4
2
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __toESM = (mod, isNodeMode, target) => {
8
- target = mod != null ? __create(__getProtoOf(mod)) : {};
9
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
- for (let key of __getOwnPropNames(mod))
11
- if (!__hasOwnProp.call(to, key))
12
- __defProp(to, key, {
13
- get: () => mod[key],
14
- enumerable: true
15
- });
16
- return to;
17
- };
18
5
  var __moduleCache = /* @__PURE__ */ new WeakMap;
19
6
  var __toCommonJS = (from) => {
20
7
  var entry = __moduleCache.get(from), desc;
@@ -53,6 +40,7 @@ __export(exports_src, {
53
40
  debounce: () => debounce,
54
41
  cubicCurve: () => cubicCurve,
55
42
  css: () => css,
43
+ assert: () => assert,
56
44
  QuadraticBezier: () => QuadraticBezier,
57
45
  CubicBezier: () => CubicBezier
58
46
  });
@@ -268,12 +256,6 @@ var throttle = (func, delay) => {
268
256
  };
269
257
  };
270
258
  // src/bezier.ts
271
- class BezierError extends Error {
272
- constructor(message) {
273
- super(message);
274
- this.name = "BezierError";
275
- }
276
- }
277
259
  var quadraticCurve;
278
260
  ((quadraticCurve) => {
279
261
  quadraticCurve.solveX = (p1, t) => {
@@ -359,7 +341,7 @@ class QuadraticBezier {
359
341
  this.p1 = p1;
360
342
  this.accuracy = accuracy;
361
343
  if (this.p1[0] < 0 || this.p1[0] > 1) {
362
- throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
344
+ throw new TypeError("控制点P1的x坐标必须在[0, 1]之间");
363
345
  }
364
346
  if (accuracy !== -1) {
365
347
  this.accuracy = 10 ** accuracy;
@@ -395,10 +377,10 @@ class CubicBezier {
395
377
  this.p2 = p2;
396
378
  this.accuracy = accuracy;
397
379
  if (this.p1[0] < 0 || this.p1[0] > 1) {
398
- throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
380
+ throw new TypeError("控制点P1的x坐标必须在[0, 1]之间");
399
381
  }
400
382
  if (this.p2[0] < 0 || this.p2[0] > 1) {
401
- throw new BezierError("控制点P2的x坐标必须在[0, 1]之间");
383
+ throw new TypeError("控制点P2的x坐标必须在[0, 1]之间");
402
384
  }
403
385
  if (accuracy !== -1) {
404
386
  this.accuracy = 10 ** accuracy;
@@ -424,7 +406,6 @@ class CubicBezier {
424
406
  }
425
407
  }
426
408
  // src/error.ts
427
- var import_promises = __toESM(require("node:fs/promises"));
428
409
  var tryCatch = (parameter) => {
429
410
  if (typeof parameter === "object") {
430
411
  return parameter.then((data) => Object.assign([data, null], { data, error: null })).catch((error) => Object.assign([null, error], { data: null, error }));
@@ -439,7 +420,5 @@ var tryCatch = (parameter) => {
439
420
  }
440
421
  throw new TypeError("参数类型错误,应为 Promise 或函数");
441
422
  };
442
- (async () => {
443
- const a = await tryCatch(import_promises.default.stat("a.txt"));
444
- console.log(typeof a);
445
- })();
423
+ // src/type.ts
424
+ var assert = (v) => {};
package/dist/esm/index.js CHANGED
@@ -208,12 +208,6 @@ var throttle = (func, delay) => {
208
208
  };
209
209
  };
210
210
  // src/bezier.ts
211
- class BezierError extends Error {
212
- constructor(message) {
213
- super(message);
214
- this.name = "BezierError";
215
- }
216
- }
217
211
  var quadraticCurve;
218
212
  ((quadraticCurve) => {
219
213
  quadraticCurve.solveX = (p1, t) => {
@@ -299,7 +293,7 @@ class QuadraticBezier {
299
293
  this.p1 = p1;
300
294
  this.accuracy = accuracy;
301
295
  if (this.p1[0] < 0 || this.p1[0] > 1) {
302
- throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
296
+ throw new TypeError("控制点P1的x坐标必须在[0, 1]之间");
303
297
  }
304
298
  if (accuracy !== -1) {
305
299
  this.accuracy = 10 ** accuracy;
@@ -335,10 +329,10 @@ class CubicBezier {
335
329
  this.p2 = p2;
336
330
  this.accuracy = accuracy;
337
331
  if (this.p1[0] < 0 || this.p1[0] > 1) {
338
- throw new BezierError("控制点P1的x坐标必须在[0, 1]之间");
332
+ throw new TypeError("控制点P1的x坐标必须在[0, 1]之间");
339
333
  }
340
334
  if (this.p2[0] < 0 || this.p2[0] > 1) {
341
- throw new BezierError("控制点P2的x坐标必须在[0, 1]之间");
335
+ throw new TypeError("控制点P2的x坐标必须在[0, 1]之间");
342
336
  }
343
337
  if (accuracy !== -1) {
344
338
  this.accuracy = 10 ** accuracy;
@@ -364,7 +358,6 @@ class CubicBezier {
364
358
  }
365
359
  }
366
360
  // src/error.ts
367
- import fs from "node:fs/promises";
368
361
  var tryCatch = (parameter) => {
369
362
  if (typeof parameter === "object") {
370
363
  return parameter.then((data) => Object.assign([data, null], { data, error: null })).catch((error) => Object.assign([null, error], { data: null, error }));
@@ -379,10 +372,8 @@ var tryCatch = (parameter) => {
379
372
  }
380
373
  throw new TypeError("参数类型错误,应为 Promise 或函数");
381
374
  };
382
- (async () => {
383
- const a = await tryCatch(fs.stat("a.txt"));
384
- console.log(typeof a);
385
- })();
375
+ // src/type.ts
376
+ var assert = (v) => {};
386
377
  export {
387
378
  waitSync,
388
379
  wait,
@@ -395,6 +386,7 @@ export {
395
386
  debounce,
396
387
  cubicCurve,
397
388
  css,
389
+ assert,
398
390
  QuadraticBezier,
399
391
  CubicBezier
400
392
  };
@@ -6,3 +6,4 @@ export * from "./time";
6
6
  export * from "./task";
7
7
  export * from "./bezier";
8
8
  export * from "./error";
9
+ export * from "./type";
@@ -0,0 +1,34 @@
1
+ declare global {
2
+ interface Object {
3
+ deepAssign<T, U>(target: T, source: U, options?: DeepAssignOptions): T & U;
4
+ deepAssign<T, U, V>(target: T, source1: U, source2: V, options?: DeepAssignOptions): T & U & V;
5
+ deepAssign<T, U, V, W>(target: T, source1: U, source2: V, source3: W, options?: DeepAssignOptions): T & U & V & W;
6
+ deepAssign(target: any, ...sources: any[]): any;
7
+ }
8
+ }
9
+ interface DeepAssignOptions {
10
+ /**
11
+ * 合并深度:
12
+ * - true: 无限深度
13
+ * - false: 浅层合并 (等同于 Object.assign)
14
+ * - number: 指定最大深度
15
+ * @default true
16
+ */
17
+ deep?: boolean | number;
18
+ /**
19
+ * 是否覆盖目标对象属性:
20
+ * - true: 源对象属性覆盖目标对象
21
+ * - false: 只合并目标对象没有的属性
22
+ * @default true
23
+ */
24
+ overwrite?: boolean;
25
+ /**
26
+ * 数组合并策略:
27
+ * - 'merge': (默认)合并数组项 (递归合并数组元素)
28
+ * - 'concat': 连接数组
29
+ * - 'replace': 替换整个数组
30
+ * @default 'replace'
31
+ */
32
+ arrayStrategy?: 'replace' | 'merge' | 'concat';
33
+ }
34
+ export {};
@@ -0,0 +1 @@
1
+ export declare const assert: <T = any>(v: any) => asserts v is T;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ceale/util",
3
3
  "author": "Ceale",
4
- "version": "1.12.4",
4
+ "version": "1.13.0",
5
5
  "module": "index.ts",
6
6
  "type": "module",
7
7
  "main": "dist/esm/index.js",