@allkit/shared 0.0.4 → 0.0.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.
- package/package.json +21 -26
- package/dist/README.md +0 -1
- package/dist/package.json +0 -21
- package/dist/skills/shared/SKILL.md +0 -240
- package/dist/skills/shared/examples/usage.ts +0 -88
- package/dist/skills/shared/references/clipboard.md +0 -39
- package/dist/skills/shared/references/cloneDeep.md +0 -60
- package/dist/skills/shared/references/cookie.md +0 -56
- package/dist/skills/shared/references/date.md +0 -466
- package/dist/skills/shared/references/device.md +0 -138
- package/dist/skills/shared/references/element.md +0 -99
- package/dist/skills/shared/references/is.md +0 -415
- package/dist/skills/shared/references/lodash.md +0 -472
- package/dist/skills/shared/references/number.md +0 -248
- package/dist/skills/shared/references/storage.md +0 -113
- package/dist/skills/shared/references/string.md +0 -126
- package/dist/skills/shared/references/timer.md +0 -78
- package/eslint.config.js +0 -10
- package/scripts/build.mjs +0 -95
- package/src/clipboard/index.ts +0 -26
- package/src/cloneDeep/__test__/cloneDeep.test.ts +0 -92
- package/src/cloneDeep/index.ts +0 -168
- package/src/constants.ts +0 -27
- package/src/cookie/index.ts +0 -44
- package/src/date/__test__/date-diff.test.ts +0 -23
- package/src/date/__test__/date-duration.test.ts +0 -140
- package/src/date/__test__/date-from.test.ts +0 -64
- package/src/date/__test__/date.test.ts +0 -67
- package/src/date/index.ts +0 -331
- package/src/device/__test__/device.test.ts +0 -138
- package/src/device/index.ts +0 -125
- package/src/element/index.ts +0 -100
- package/src/index.ts +0 -14
- package/src/is/__test__/is.test.ts +0 -320
- package/src/is/index.ts +0 -293
- package/src/lodash/__test__/lodash.test.ts +0 -111
- package/src/lodash/__test__/obj-string.test.ts +0 -107
- package/src/lodash/__test__/uniqueId.test.ts +0 -40
- package/src/lodash/index.ts +0 -396
- package/src/number/__test__/number.test.ts +0 -137
- package/src/number/index.ts +0 -161
- package/src/storage/__test__/storage.test.ts +0 -44
- package/src/storage/index.ts +0 -185
- package/src/string/__test__/string.test.ts +0 -24
- package/src/string/index.ts +0 -49
- package/src/timer/index.ts +0 -15
- package/tsconfig.json +0 -25
- package/types/global.d.ts +0 -13
- package/vite.config.ts +0 -16
- package/vitest.config.ts +0 -28
- /package/{dist/clipboard → clipboard}/index.d.ts +0 -0
- /package/{dist/cloneDeep → cloneDeep}/index.d.ts +0 -0
- /package/{dist/constants.d.ts → constants.d.ts} +0 -0
- /package/{dist/cookie → cookie}/index.d.ts +0 -0
- /package/{dist/date → date}/index.d.ts +0 -0
- /package/{dist/device → device}/index.d.ts +0 -0
- /package/{dist/element → element}/index.d.ts +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/is → is}/index.d.ts +0 -0
- /package/{dist/lodash → lodash}/index.d.ts +0 -0
- /package/{dist/number → number}/index.d.ts +0 -0
- /package/{dist/shared.es.d.ts → shared.es.d.ts} +0 -0
- /package/{dist/shared.es.js → shared.es.js} +0 -0
- /package/{dist/shared.umd.js → shared.umd.js} +0 -0
- /package/{dist/storage → storage}/index.d.ts +0 -0
- /package/{dist/string → string}/index.d.ts +0 -0
- /package/{dist/timer → timer}/index.d.ts +0 -0
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import { getSession, setSession } from '../'
|
|
3
|
-
|
|
4
|
-
describe('session.ts', () => {
|
|
5
|
-
test('session - param is boolean', () => {
|
|
6
|
-
const isTest = true
|
|
7
|
-
const key = 'session-boolean-key'
|
|
8
|
-
setSession(key, isTest)
|
|
9
|
-
const value = getSession(key)
|
|
10
|
-
expect(isTest).toEqual(value)
|
|
11
|
-
expect(typeof value).toEqual('boolean')
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
test('session - param is string', () => {
|
|
15
|
-
const isTest = '123456'
|
|
16
|
-
const key = 'session-string-key'
|
|
17
|
-
setSession(key, isTest)
|
|
18
|
-
const value = getSession(key)
|
|
19
|
-
expect(isTest).toEqual(value)
|
|
20
|
-
expect(typeof value).toEqual('string')
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
test('session - param is number', () => {
|
|
24
|
-
const isTest = 0
|
|
25
|
-
const key = 'session-number-key'
|
|
26
|
-
setSession(key, isTest)
|
|
27
|
-
const value = getSession(key)
|
|
28
|
-
expect(isTest).toEqual(value)
|
|
29
|
-
expect(typeof value).toEqual('number')
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
test('session - param is plain object', () => {
|
|
33
|
-
const isTest = {
|
|
34
|
-
name: 'test',
|
|
35
|
-
age: 11,
|
|
36
|
-
}
|
|
37
|
-
const key = 'session-plain-key'
|
|
38
|
-
setSession(key, isTest)
|
|
39
|
-
const value = getSession(key)
|
|
40
|
-
expect(isTest).toEqual(value)
|
|
41
|
-
expect(isTest).not.toBe(value)
|
|
42
|
-
expect(typeof value).toEqual('object')
|
|
43
|
-
})
|
|
44
|
-
})
|
package/src/storage/index.ts
DELETED
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { isUnDef } from '../is'
|
|
2
|
-
|
|
3
|
-
interface Store {
|
|
4
|
-
[key: string]: any
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 存储类型
|
|
9
|
-
*/
|
|
10
|
-
type StoreType = Store | string | number | boolean
|
|
11
|
-
|
|
12
|
-
export const EnumStoreType = {
|
|
13
|
-
/**
|
|
14
|
-
* localStorage
|
|
15
|
-
*/
|
|
16
|
-
LOCAl: 'localStorage',
|
|
17
|
-
/**
|
|
18
|
-
* sessionStorage
|
|
19
|
-
*/
|
|
20
|
-
SESSION: 'sessionStorage',
|
|
21
|
-
} as const
|
|
22
|
-
|
|
23
|
-
export type EnumStoreType = (typeof EnumStoreType)[keyof typeof EnumStoreType]
|
|
24
|
-
|
|
25
|
-
/* ****************************** 包装方法 ******************************* */
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 设置本地存储, 默认`type` 为`localStorage`
|
|
29
|
-
* @param key - 字符串唯一key
|
|
30
|
-
* @param value - 需要存储的内容
|
|
31
|
-
* @param type - 存储类型 {@link EnumStoreType}
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* let value = { name: '张三', age: 18 }
|
|
35
|
-
* // localStorage
|
|
36
|
-
* setStore('userInfo', value)
|
|
37
|
-
* // sessionStorage
|
|
38
|
-
* setStore('userInfo', value, EnumStoreType.SESSION)
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export function setStore(key: string, value: StoreType, type: EnumStoreType = EnumStoreType.LOCAl) {
|
|
42
|
-
if (isUnDef(value)) return
|
|
43
|
-
const content = JSON.stringify({ _value_: value })
|
|
44
|
-
window[type].setItem(key, content)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 获取本地存储, 默认`type` 为`localStorage`
|
|
49
|
-
* @param key - 字符串key
|
|
50
|
-
* @param type - 存储类型 {@link EnumStoreType}
|
|
51
|
-
* @returns 获取到的内容
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* // localStorage
|
|
56
|
-
* const value = getStore('token')
|
|
57
|
-
* // sessionStorage
|
|
58
|
-
* const value = getStore('token', EnumStoreType.SESSION)
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export function getStore<T = any>(
|
|
62
|
-
key: string,
|
|
63
|
-
type: EnumStoreType = EnumStoreType.LOCAl,
|
|
64
|
-
): T | null {
|
|
65
|
-
const info = window[type].getItem(key)
|
|
66
|
-
if (!info) return null
|
|
67
|
-
try {
|
|
68
|
-
const content = JSON.parse(info)
|
|
69
|
-
if (Object.hasOwnProperty.call(content, '_value_')) {
|
|
70
|
-
return content._value_ as T
|
|
71
|
-
}
|
|
72
|
-
return content as T
|
|
73
|
-
} catch (error) {
|
|
74
|
-
return info as string as T
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* 删除指定key的Local
|
|
80
|
-
* @param key - 字符串key
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```ts
|
|
84
|
-
* // localStorage
|
|
85
|
-
* const value = removeStore('token')
|
|
86
|
-
* // sessionStorage
|
|
87
|
-
* const value = removeStore('token', EnumStoreType.SESSION)
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
export function removeStore(key: string, type: EnumStoreType = EnumStoreType.LOCAl) {
|
|
91
|
-
window[type].removeItem(key)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 清空所有Local
|
|
96
|
-
*/
|
|
97
|
-
export function clearStore(type: EnumStoreType = EnumStoreType.LOCAl) {
|
|
98
|
-
window[type].clear()
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 设置LocalStorage
|
|
103
|
-
* @param key - 字符串唯一key
|
|
104
|
-
* @param content - 需要存储的内容
|
|
105
|
-
* @returns void
|
|
106
|
-
* @example
|
|
107
|
-
* ```ts
|
|
108
|
-
* // localStorage
|
|
109
|
-
* setLocal('token','123')
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
export const setLocal = (key: string, content: StoreType) => setStore(key, content)
|
|
113
|
-
/**
|
|
114
|
-
* 获取LocalStorage
|
|
115
|
-
* @param key - 字符串key
|
|
116
|
-
* @returns 获取到的内容
|
|
117
|
-
* @example
|
|
118
|
-
* ```ts
|
|
119
|
-
* const value = getLocal('token')
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
export const getLocal = <T = any>(key: string) => getStore<T>(key)
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* 删除指定key的LocalStorage
|
|
126
|
-
* @param key - 字符串key
|
|
127
|
-
* @returns void
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* removeLocal('token')
|
|
131
|
-
* ```
|
|
132
|
-
*/
|
|
133
|
-
export const removeLocal = (key: string) => removeStore(key)
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* 清除所有LocalStorage
|
|
137
|
-
* @example
|
|
138
|
-
* ```ts
|
|
139
|
-
* clearLocal()
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
export const clearLocal = () => clearStore()
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* 设置sessionStorage
|
|
146
|
-
* @param key - 字符串唯一key
|
|
147
|
-
* @param content - 需要存储的内容
|
|
148
|
-
* @returns void
|
|
149
|
-
* @example
|
|
150
|
-
* ```ts
|
|
151
|
-
* setSession('token','123')
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
export const setSession = (key: string, content: StoreType) =>
|
|
155
|
-
setStore(key, content, EnumStoreType.SESSION)
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* 获取sessionStorage
|
|
159
|
-
* @param key - 字符串key
|
|
160
|
-
* @returns - 获取到的内容
|
|
161
|
-
* @example
|
|
162
|
-
* ```ts
|
|
163
|
-
* const value = getSession('token')
|
|
164
|
-
* ```
|
|
165
|
-
*/
|
|
166
|
-
export const getSession = <T = any>(key: string) => getStore<T>(key, EnumStoreType.SESSION)
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* 删除指定key的sessionStorage
|
|
170
|
-
* @param key - 字符串key
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* const value = removeSession('token')
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
export const removeSession = (key: string) => removeStore(key, EnumStoreType.SESSION)
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* 清除所有sessionStorage
|
|
180
|
-
* @example
|
|
181
|
-
* ```ts
|
|
182
|
-
* const value = clearSession()
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
export const clearSession = () => clearStore(EnumStoreType.SESSION)
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest'
|
|
2
|
-
import { camelize, kebabCase, snakeCase, lowerFirst } from '../'
|
|
3
|
-
|
|
4
|
-
describe('string.ts', () => {
|
|
5
|
-
test('camelize - param is a-b-c', () => {
|
|
6
|
-
const str = 'a-b-c'
|
|
7
|
-
expect(camelize(str)).toBe('aBC')
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
test('kebabCase - param is aBC', () => {
|
|
11
|
-
const str = 'aBC'
|
|
12
|
-
expect(kebabCase(str)).toBe('a-b-c')
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
test('snakeCase - param is aBC', () => {
|
|
16
|
-
const str = 'aBC'
|
|
17
|
-
expect(snakeCase(str)).toBe('a_b_c')
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
test('lowerFirst - param is ABC', () => {
|
|
21
|
-
const str = 'ABC'
|
|
22
|
-
expect(lowerFirst(str)).toBe('aBC')
|
|
23
|
-
})
|
|
24
|
-
})
|
package/src/string/index.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 中划线转小驼峰
|
|
3
|
-
* @param str - 字符串
|
|
4
|
-
* @returns 驼峰字符串
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* let result=camelize('user-info')
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
export const camelize = (str: string): string => str.replace(/-(\w)/g, (_, c) => c.toUpperCase())
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* 驼峰转中划线
|
|
14
|
-
* @param str - 字符串
|
|
15
|
-
* @returns 中划线字符串
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* let result=kebabCase('userInfo')
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export const kebabCase = (str: string) =>
|
|
22
|
-
str
|
|
23
|
-
.replace(/([A-Z])/g, '-$1')
|
|
24
|
-
.toLowerCase()
|
|
25
|
-
.replace(/^-/, '')
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* 驼峰转下划线
|
|
29
|
-
* @param str - 字符串
|
|
30
|
-
* @returns 下划线字符串
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* let result=snakeCase('userInfo')
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export const snakeCase = (str: string) => str.replace(/([A-Z])/g, '_$1').toLowerCase()
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 首字母小写
|
|
40
|
-
* @param str - 字符串
|
|
41
|
-
* @returns 首字母小写的字符串
|
|
42
|
-
* @example
|
|
43
|
-
* ```ts
|
|
44
|
-
* let result=lowerFirst('ABC')
|
|
45
|
-
* ```
|
|
46
|
-
*/
|
|
47
|
-
export const lowerFirst = (str: string): string => {
|
|
48
|
-
return str.charAt(0).toLowerCase() + str.slice(1)
|
|
49
|
-
}
|
package/src/timer/index.ts
DELETED
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@allkit/tsconfig",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"baseUrl": "./",
|
|
5
|
-
"paths": {
|
|
6
|
-
"@/*": [
|
|
7
|
-
"src/*"
|
|
8
|
-
],
|
|
9
|
-
"~/*": [
|
|
10
|
-
"src/*"
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
"types": [
|
|
14
|
-
"@types/big.js"
|
|
15
|
-
]
|
|
16
|
-
},
|
|
17
|
-
"include": [
|
|
18
|
-
"src/**/*.ts",
|
|
19
|
-
"src/**/*.d.ts",
|
|
20
|
-
"src/**/*.tsx",
|
|
21
|
-
"src/**/*.vue",
|
|
22
|
-
"types/*.d.ts",
|
|
23
|
-
"../../types/"
|
|
24
|
-
]
|
|
25
|
-
}
|
package/types/global.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
type DeepPartial<T> = {
|
|
3
|
-
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Utility type to extract the value type from an object
|
|
8
|
-
* Usage: ValueOf<typeof MyObject> instead of typeof MyObject[keyof typeof MyObject]
|
|
9
|
-
*/
|
|
10
|
-
type ValueOf<T> = T[keyof T]
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export {}
|
package/vite.config.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type ConfigEnv, defineConfig } from 'vite'
|
|
2
|
-
import { viteLibConfig } from '@allkit/vite-config'
|
|
3
|
-
|
|
4
|
-
export default ({ mode }) => {
|
|
5
|
-
const config = viteLibConfig({
|
|
6
|
-
mode,
|
|
7
|
-
build: {
|
|
8
|
-
lib: {
|
|
9
|
-
entry: './src/index.ts',
|
|
10
|
-
name: 'shared',
|
|
11
|
-
fileName: (format) => `shared.${format}.js`,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
})
|
|
15
|
-
return config
|
|
16
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { defineConfig, mergeConfig } from 'vitest/config'
|
|
2
|
-
import viteConfig from './vite.config'
|
|
3
|
-
import { UserConfig } from 'vite'
|
|
4
|
-
|
|
5
|
-
export default mergeConfig(
|
|
6
|
-
viteConfig({
|
|
7
|
-
mode: 'test',
|
|
8
|
-
}) as UserConfig,
|
|
9
|
-
defineConfig({
|
|
10
|
-
test: {
|
|
11
|
-
environment: 'jsdom',
|
|
12
|
-
coverage: {
|
|
13
|
-
provider: 'istanbul',
|
|
14
|
-
include: ['src/**/*.[jt]s?(x)'],
|
|
15
|
-
exclude: [
|
|
16
|
-
'**/example/**',
|
|
17
|
-
'**/__tests__/**',
|
|
18
|
-
'docs/**',
|
|
19
|
-
'coverage/**',
|
|
20
|
-
'types/**',
|
|
21
|
-
'shims/**',
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
restoreMocks: true,
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|