@pawover/kit 0.0.0-alpha.3 → 0.0.0-alpha.5

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.
@@ -1,5 +1,13 @@
1
- import { isEqual } from "radashi";
2
1
  import { useRef } from "react";
2
+ import { isEqual } from "src/utils";
3
+ /**
4
+ * useCreation
5
+ * @reference https://ahooks.js.org/zh-CN/hooks/use-creation
6
+ *
7
+ * @template T
8
+ * @param {() => T} factory
9
+ * @param {DependencyList} deps
10
+ */
3
11
  export function useCreation(factory, deps) {
4
12
  const { current } = useRef({ deps, result: undefined, isInitialized: false });
5
13
  if (current.isInitialized === false || !isEqual(current.deps, deps)) {
@@ -1,4 +1,11 @@
1
1
  import { useRef } from "react";
2
+ /**
3
+ * 返回当前最新值的 Hook
4
+ * @reference https://ahooks.js.org/zh-CN/hooks/use-latest
5
+ *
6
+ * @template T
7
+ * @param {T} value
8
+ */
2
9
  export function useLatest(value) {
3
10
  const ref = useRef(value);
4
11
  ref.current = value;
@@ -3,6 +3,7 @@ import { isFunction } from "src/utils";
3
3
  import { useLatest } from "./useLatest";
4
4
  /**
5
5
  * 在组件卸载时执行的 Hook
6
+ * @reference https://ahooks.js.org/zh-CN/hooks/use-unmount
6
7
  *
7
8
  * @param {Func} effect 副作用函数
8
9
  */
@@ -0,0 +1 @@
1
+ export * from "./react/index";
@@ -1,2 +1,10 @@
1
1
  import { type DependencyList } from "react";
2
+ /**
3
+ * useCreation
4
+ * @reference https://ahooks.js.org/zh-CN/hooks/use-creation
5
+ *
6
+ * @template T
7
+ * @param {() => T} factory
8
+ * @param {DependencyList} deps
9
+ */
2
10
  export declare function useCreation<T>(factory: () => T, deps: DependencyList): T;
@@ -1 +1,8 @@
1
+ /**
2
+ * 返回当前最新值的 Hook
3
+ * @reference https://ahooks.js.org/zh-CN/hooks/use-latest
4
+ *
5
+ * @template T
6
+ * @param {T} value
7
+ */
1
8
  export declare function useLatest<T>(value: T): import("react").RefObject<T>;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * 在组件卸载时执行的 Hook
3
+ * @reference https://ahooks.js.org/zh-CN/hooks/use-unmount
3
4
  *
4
5
  * @param {Func} effect 副作用函数
5
6
  */
@@ -0,0 +1 @@
1
+ export * from "./react/index";
@@ -27,3 +27,11 @@ export declare function isURLSearchParams<T extends Window>(value: unknown): val
27
27
  export declare function isClass<T extends Class<AnyObject>>(value: unknown): value is T;
28
28
  export declare function isInteger<T extends number>(value: unknown): value is T;
29
29
  export declare function isIterable<T extends Iterable<unknown>>(value: unknown): value is T;
30
+ /**
31
+ * 判断给定的值是否相等
32
+ * @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
33
+ *
34
+ * @param {T} x
35
+ * @param {T} y
36
+ */
37
+ export declare function isEqual<T>(x: T, y: T): boolean;
@@ -112,3 +112,38 @@ export function isInteger(value) {
112
112
  export function isIterable(value) {
113
113
  return isObject(value) && Symbol.iterator in value;
114
114
  }
115
+ /**
116
+ * 判断给定的值是否相等
117
+ * @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
118
+ *
119
+ * @param {T} x
120
+ * @param {T} y
121
+ */
122
+ export function isEqual(x, y) {
123
+ if (Object.is(x, y)) {
124
+ return true;
125
+ }
126
+ if (x instanceof Date && y instanceof Date) {
127
+ return x.getTime() === y.getTime();
128
+ }
129
+ if (x instanceof RegExp && y instanceof RegExp) {
130
+ return x.toString() === y.toString();
131
+ }
132
+ if (typeof x !== "object" || x === null || typeof y !== "object" || y === null) {
133
+ return false;
134
+ }
135
+ const keysX = Reflect.ownKeys(x);
136
+ const keysY = Reflect.ownKeys(y);
137
+ if (keysX.length !== keysY.length) {
138
+ return false;
139
+ }
140
+ for (const key of keysX) {
141
+ if (!Reflect.has(y, key)) {
142
+ return false;
143
+ }
144
+ if (!isEqual(x[key], y[key])) {
145
+ return false;
146
+ }
147
+ }
148
+ return true;
149
+ }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "pawover's kit",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
- "version": "0.0.0-alpha.3",
7
+ "version": "0.0.0-alpha.5",
8
8
  "packageManager": "pnpm@10.20.0",
9
9
  "engines": {
10
10
  "node": ">=22.20.0"
@@ -27,11 +27,13 @@
27
27
  "exports": {
28
28
  ".": {
29
29
  "types": "./dist/types/index.d.ts",
30
- "import": "./dist/index.js"
30
+ "import": "./dist/index.js",
31
+ "default": "./dist/index.js"
31
32
  },
32
- "./hooks/react": {
33
- "types": "./dist/types/hooks/react/index.d.ts",
34
- "import": "./dist/hooks/react/index.js"
33
+ "./hooks/react/*": {
34
+ "types": "./dist/types/hooks/react/*.d.ts",
35
+ "import": "./dist/hooks/react/*.js",
36
+ "default": "./dist/hooks/react/*.js"
35
37
  }
36
38
  },
37
39
  "scripts": {
@@ -59,7 +61,6 @@
59
61
  "eslint-plugin-antfu": "^3.1.1",
60
62
  "globals": "^16.5.0",
61
63
  "prettier": "^3.6.2",
62
- "radashi": "^12.7.0",
63
64
  "react": "^19.2.0",
64
65
  "rimraf": "^6.1.0",
65
66
  "taze": "^19.9.0",
@@ -70,7 +71,6 @@
70
71
  },
71
72
  "peerDependencies": {
72
73
  "ahooks": ">=3.9.6",
73
- "radashi": ">=12.7.0",
74
74
  "react": ">=19.2.0",
75
75
  "vue": ">=3.5.24"
76
76
  },