@allkit/shared 0.0.2 → 0.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.
@@ -0,0 +1,113 @@
1
+ # storage
2
+
3
+ 本地存储工具函数,自动处理 JSON 序列化,支持 TypeScript 类型推断
4
+
5
+ ## Functions
6
+
7
+ ### setLocal
8
+
9
+ 设置 LocalStorage
10
+
11
+ ```ts
12
+ function setLocal<T>(key: string, content: T): void
13
+ ```
14
+
15
+ ### getLocal
16
+
17
+ 获取 LocalStorage
18
+
19
+ ```ts
20
+ function getLocal<T>(key: string): T
21
+ ```
22
+
23
+ ### removeLocal
24
+
25
+ 删除 LocalStorage
26
+
27
+ ```ts
28
+ function removeLocal(key: string): void
29
+ ```
30
+
31
+ ### clearLocal
32
+
33
+ 清空 LocalStorage
34
+
35
+ ```ts
36
+ function clearLocal(): void
37
+ ```
38
+
39
+ ### setSession
40
+
41
+ 设置 SessionStorage
42
+
43
+ ```ts
44
+ function setSession<T>(key: string, content: T): void
45
+ ```
46
+
47
+ ### getSession
48
+
49
+ 获取 SessionStorage
50
+
51
+ ```ts
52
+ function getSession<T>(key: string): T
53
+ ```
54
+
55
+ ### removeSession
56
+
57
+ 删除 SessionStorage
58
+
59
+ ```ts
60
+ function removeSession(key: string): void
61
+ ```
62
+
63
+ ### clearSession
64
+
65
+ 清空 SessionStorage
66
+
67
+ ```ts
68
+ function clearSession(): void
69
+ ```
70
+
71
+ ### setStore
72
+
73
+ 设置本地存储
74
+
75
+ ```ts
76
+ function setStore<T>(key: string, value: T, type?: 'local' | 'session'): void
77
+ ```
78
+
79
+ ### getStore
80
+
81
+ 获取本地存储
82
+
83
+ ```ts
84
+ function getStore<T>(key: string, type?: 'local' | 'session'): T
85
+ ```
86
+
87
+ ### removeStore
88
+
89
+ 删除本地存储
90
+
91
+ ```ts
92
+ function removeStore(key: string, type?: 'local' | 'session'): void
93
+ ```
94
+
95
+ ## Example
96
+
97
+ ```ts
98
+ import { setLocal, getLocal, setSession, getSession } from '@allkit/shared'
99
+
100
+ // LocalStorage
101
+ setLocal('token', '123')
102
+ const token = getLocal<string>('token') // '123'
103
+ removeLocal('token')
104
+
105
+ // SessionStorage
106
+ setSession('userInfo', { name: '张三', age: 18 })
107
+ const userInfo = getSession<{ name: string; age: number }>('userInfo')
108
+ removeSession('userInfo')
109
+
110
+ // 通用方法
111
+ setStore('token', '123', 'local')
112
+ const token2 = getStore<string>('token', 'local')
113
+ ```
@@ -0,0 +1,126 @@
1
+ # string
2
+
3
+ 字符串操作工具函数
4
+
5
+ ## Functions
6
+
7
+ ### camelize
8
+
9
+ 中划线转小驼峰
10
+
11
+ ```ts
12
+ function camelize(str: string): string
13
+ ```
14
+
15
+ **Example**
16
+
17
+ ```ts
18
+ camelize('user-info') // 'userInfo'
19
+ camelize('hello-world-test') // 'helloWorldTest'
20
+ ```
21
+
22
+ ### kebabCase
23
+
24
+ 驼峰转中划线
25
+
26
+ ```ts
27
+ function kebabCase(str: string): string
28
+ ```
29
+
30
+ **Example**
31
+
32
+ ```ts
33
+ kebabCase('userInfo') // 'user-info'
34
+ kebabCase('helloWorldTest') // 'hello-world-test'
35
+ ```
36
+
37
+ ### snakeCase
38
+
39
+ 驼峰转下划线
40
+
41
+ ```ts
42
+ function snakeCase(str: string): string
43
+ ```
44
+
45
+ **Example**
46
+
47
+ ```ts
48
+ snakeCase('userInfo') // 'user_info'
49
+ snakeCase('helloWorldTest') // 'hello_world_test'
50
+ ```
51
+
52
+ ### lowerFirst
53
+
54
+ 首字母转小写
55
+
56
+ ```ts
57
+ function lowerFirst(str: string): string
58
+ ```
59
+
60
+ **Example**
61
+
62
+ ```ts
63
+ lowerFirst('UserInfo') // 'userInfo'
64
+ lowerFirst('Hello') // 'hello'
65
+ ```
66
+
67
+ ### upperFirst
68
+
69
+ 首字母转大写
70
+
71
+ ```ts
72
+ function upperFirst(str: string): string
73
+ ```
74
+
75
+ **Example**
76
+
77
+ ```ts
78
+ upperFirst('userInfo') // 'UserInfo'
79
+ upperFirst('hello') // 'Hello'
80
+ ```
81
+
82
+ ### trim
83
+
84
+ 去除字符串首尾空白
85
+
86
+ ```ts
87
+ function trim(str: string, chars?: string): string
88
+ ```
89
+
90
+ **Example**
91
+
92
+ ```ts
93
+ trim(' hello ') // 'hello'
94
+ trim('--hello--', '-') // 'hello'
95
+ ```
96
+
97
+ ### repeat
98
+
99
+ 重复字符串
100
+
101
+ ```ts
102
+ function repeat(str: string, count: number): string
103
+ ```
104
+
105
+ **Example**
106
+
107
+ ```ts
108
+ repeat('a', 3) // 'aaa'
109
+ repeat('ab', 2) // 'abab'
110
+ ```
111
+
112
+ ### padStart / padEnd
113
+
114
+ 字符串补全
115
+
116
+ ```ts
117
+ function padStart(str: string, length: number, chars?: string): string
118
+ function padEnd(str: string, length: number, chars?: string): string
119
+ ```
120
+
121
+ **Example**
122
+
123
+ ```ts
124
+ padStart('5', 2, '0') // '05'
125
+ padEnd('hi', 4, '!') // 'hi!!'
126
+ ```
@@ -0,0 +1,78 @@
1
+ # timer
2
+
3
+ 定时器工具函数
4
+
5
+ ## Functions
6
+
7
+ ### sleep
8
+
9
+ 睡眠函数
10
+
11
+ ```ts
12
+ function sleep(timer: number): Promise<void>
13
+ ```
14
+
15
+ **Example**
16
+
17
+ ```ts
18
+ await sleep(1000) // 等待 1 秒
19
+ ```
20
+
21
+ ### raf
22
+
23
+ 监听下一动画帧(Promise)
24
+
25
+ ```ts
26
+ function raf(): Promise<void>
27
+ ```
28
+
29
+ **Example**
30
+
31
+ ```ts
32
+ raf().then(() => {
33
+ console.log('执行下一帧')
34
+ })
35
+ ```
36
+
37
+ ### doubleRaf
38
+
39
+ 监听双帧动画帧(Promise)
40
+
41
+ ```ts
42
+ function doubleRaf(): Promise<void>
43
+ ```
44
+
45
+ **Example**
46
+
47
+ ```ts
48
+ doubleRaf().then(() => {
49
+ console.log('执行双帧后')
50
+ })
51
+ ```
52
+
53
+ ### clearTimer
54
+
55
+ 清除定时器
56
+
57
+ ```ts
58
+ function clearTimer(timerId: number | undefined): void
59
+ ```
60
+
61
+ ## Usage
62
+
63
+ ```ts
64
+ import { sleep, raf, doubleRaf } from '@allkit/shared'
65
+
66
+ // 睡眠
67
+ await sleep(100)
68
+
69
+ // 下一帧
70
+ raf().then(() => {
71
+ console.log('执行下一帧')
72
+ })
73
+
74
+ // 双帧
75
+ doubleRaf().then(() => {
76
+ console.log('执行双帧后')
77
+ })
78
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allkit/shared",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "this is a shared package",
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
package/scripts/build.mjs CHANGED
@@ -7,7 +7,7 @@ import fse from 'fs-extra'
7
7
  import { build } from 'vite'
8
8
  import { viteLibConfig } from '@allkit/vite-config'
9
9
 
10
- const { outputFile } = fse
10
+ const { outputFile, copy } = fse
11
11
 
12
12
  const require = createRequire(import.meta.url)
13
13
 
@@ -79,14 +79,17 @@ const buildAll = async () => {
79
79
  // copy文件
80
80
  // README.md
81
81
  // 样式 index.css
82
- const copyFiles = () => {
82
+ // skills 目录
83
+ const copyFiles = async () => {
83
84
  const markdown = createReadStream(resolve(__dirname, '../README.md'))
84
85
  markdown.pipe(createWriteStream(resolve(__dirname, '../dist/README.md')))
86
+
87
+ await copy(resolve(__dirname, '../skills'), resolve(__dirname, '../dist/skills'))
85
88
  }
86
89
 
87
90
  const buildLib = async () => {
88
91
  await buildAll()
89
- copyFiles()
92
+ await copyFiles()
90
93
  }
91
94
 
92
95
  buildLib()