kk-vue-hooks 1.0.2 → 1.0.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kk-vue-hooks",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "type": "module",
5
5
  "description": "自定义 Vue/React Hooks 集合",
6
6
  "main": "dist/index.cjs.js",
@@ -8,8 +8,8 @@
8
8
  "types": "dist/types/index.d.ts",
9
9
  "files": [
10
10
  "dist",
11
- "src",
12
- "README.md"
11
+ "README.md",
12
+ "LICENSE"
13
13
  ],
14
14
  "keywords": [
15
15
  "vue-hooks",
@@ -1,2 +0,0 @@
1
- // src/hooks/index.ts
2
- export * from './useStorage'
@@ -1,46 +0,0 @@
1
- // src/hooks/useStorage.ts
2
- /**
3
- * 本地存储 Hook(localStorage 封装)
4
- * @param key 存储键名
5
- * @param defaultValue 默认值
6
- * @returns 获取值、设置值、删除值的方法
7
- */
8
- export function useStorage<T>(key: string, defaultValue: T) {
9
- // 获取存储值
10
- const getStorage = (): T => {
11
- try {
12
- const value = localStorage.getItem(key)
13
- return value ? JSON.parse(value) : defaultValue
14
- }
15
- catch (error) {
16
- console.error('获取本地存储失败:', error)
17
- return defaultValue
18
- }
19
- }
20
-
21
- // 设置存储值
22
- const setStorage = (value: T) => {
23
- try {
24
- localStorage.setItem(key, JSON.stringify(value))
25
- }
26
- catch (error) {
27
- console.error('设置本地存储失败:', error)
28
- }
29
- }
30
-
31
- // 删除存储值
32
- const removeStorage = () => {
33
- try {
34
- localStorage.removeItem(key)
35
- }
36
- catch (error) {
37
- console.error('删除本地存储失败:', error)
38
- }
39
- }
40
-
41
- return {
42
- value: getStorage(),
43
- setStorage,
44
- removeStorage,
45
- }
46
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- // src/index.ts
2
- export * from './hooks'