@cloudcome/utils-core 1.9.0 → 1.9.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/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const VERSION = "1.8.0";
3
+ const VERSION = "1.9.1";
4
4
  exports.VERSION = VERSION;
5
5
  //# sourceMappingURL=index.cjs.map
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- const VERSION = "1.8.0";
1
+ const VERSION = "1.9.1";
2
2
  export {
3
3
  VERSION
4
4
  };
package/dist/types.d.ts CHANGED
@@ -17,6 +17,27 @@ export type KeysOf<T> = {
17
17
  * 任意数组
18
18
  */
19
19
  export type AnyArray = Array<unknown>;
20
+ /**
21
+ * 原始值类型
22
+ * @description 包含 JavaScript 中的所有原始类型,包括 string、number、boolean、bigint、symbol、null、undefined,以及 void 和 never
23
+ * @example
24
+ * ```typescript
25
+ * type Primitive = PrimitiveValue;
26
+ * // string | number | boolean | bigint | symbol | null | undefined | void | never
27
+ * ```
28
+ */
29
+ export type PrimitiveValue = string | number | boolean | bigint | symbol | null | undefined | void | never;
30
+ /**
31
+ * 引用类型值
32
+ * @description 表示所有非原始类型的值,即除了 PrimitiveValue 之外的所有类型
33
+ * @example
34
+ * ```typescript
35
+ * const obj: ReferenceValue = { a: 1 };
36
+ * const arr: ReferenceValue = [1, 2, 3];
37
+ * const func: ReferenceValue = () => {};
38
+ * ```
39
+ */
40
+ export type ReferenceValue = object;
20
41
  /**
21
42
  * 任意函数
22
43
  */
@@ -35,10 +56,25 @@ export type MaybePromise<T> = T | Promise<T>;
35
56
  export type MaybeCallable<T> = T | (() => T);
36
57
  /**
37
58
  * 深度部分类型
59
+ * @example
60
+ * ```typescript
61
+ * type PartialObj = DeepPartial<{ a: 1, b: { c: 2 } }>;
62
+ * // { a?: 1 | undefined, b?: { c?: 2 | undefined } | undefined }
63
+ * ```
38
64
  */
39
65
  export type DeepPartial<T> = T extends object ? {
40
66
  [P in keyof T]?: DeepPartial<T[P]>;
41
67
  } : T;
68
+ /**
69
+ * 将联合类型转换为交叉类型
70
+ * @ref https://juejin.cn/post/6994102811218673700#heading-24
71
+ * @template T - 联合类型
72
+ * @example
73
+ * ```typescript
74
+ * type Result = UnionToIntersection<{ a: 1 } | { b: 2 }>;
75
+ * // { a: 1 } & { b: 2 }
76
+ * ```
77
+ */
42
78
  export type UnionToIntersection<T> = (T extends any ? (arg: T) => void : never) extends (arg: infer U) => void ? U : never;
43
79
  /**
44
80
  * 从联合类型中提取最后一个类型
@@ -49,8 +85,22 @@ type _UnionLast<U> = UnionToIntersection<U extends U ? (x: U) => 0 : never> exte
49
85
  * 将联合类型转换为元组类型
50
86
  * @template U - 联合类型
51
87
  * @template Last - 联合类型中的最后一个类型
88
+ * @example
89
+ * ```ts
90
+ * type T3 = UnionToTuple<'a' | 'b' | 'c' | 'd'>;
91
+ * // ['a', 'b', 'c', 'd']
92
+ * ```
52
93
  */
53
94
  export type UnionToTuple<U, Last = _UnionLast<U>> = [U] extends [never] ? [] : [...UnionToTuple<Exclude<U, Last>>, Last];
95
+ /**
96
+ * 将交叉类型合并为一个对象类型
97
+ * @template A - 交叉类型
98
+ * @example
99
+ * ```typescript
100
+ * type Merged = MergeIntersection<{ a: string } & { b: number }>;
101
+ * // { a: string; b: number }
102
+ * ```
103
+ */
54
104
  export type MergeIntersection<A> = A extends infer T ? {
55
105
  [Key in keyof T]: T[Key];
56
106
  } : never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudcome/utils-core",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "cloudcome core utils",
5
5
  "engines": {
6
6
  "node": ">=22"