@allkit/shared 0.0.3 → 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.
Files changed (81) hide show
  1. package/package.json +21 -26
  2. package/dist/README.md +0 -1
  3. package/dist/package.json +0 -21
  4. package/eslint.config.js +0 -10
  5. package/scripts/build.mjs +0 -95
  6. package/skills/SKILL.md +0 -240
  7. package/skills/examples/usage.ts +0 -88
  8. package/skills/references/clipboard.md +0 -39
  9. package/skills/references/cloneDeep.md +0 -60
  10. package/skills/references/cookie.md +0 -56
  11. package/skills/references/date.md +0 -466
  12. package/skills/references/device.md +0 -138
  13. package/skills/references/element.md +0 -99
  14. package/skills/references/is.md +0 -415
  15. package/skills/references/lodash.md +0 -472
  16. package/skills/references/number.md +0 -248
  17. package/skills/references/storage.md +0 -113
  18. package/skills/references/string.md +0 -126
  19. package/skills/references/timer.md +0 -78
  20. package/src/clipboard/index.ts +0 -26
  21. package/src/cloneDeep/__test__/cloneDeep.test.ts +0 -92
  22. package/src/cloneDeep/index.ts +0 -168
  23. package/src/constants.ts +0 -27
  24. package/src/cookie/index.ts +0 -44
  25. package/src/date/__test__/date-diff.test.ts +0 -23
  26. package/src/date/__test__/date-duration.test.ts +0 -140
  27. package/src/date/__test__/date-from.test.ts +0 -64
  28. package/src/date/__test__/date.test.ts +0 -67
  29. package/src/date/index.ts +0 -331
  30. package/src/device/__test__/device.test.ts +0 -138
  31. package/src/device/index.ts +0 -125
  32. package/src/element/index.ts +0 -100
  33. package/src/index.ts +0 -14
  34. package/src/is/__test__/is.test.ts +0 -320
  35. package/src/is/index.ts +0 -293
  36. package/src/lodash/__test__/lodash.test.ts +0 -111
  37. package/src/lodash/__test__/obj-string.test.ts +0 -107
  38. package/src/lodash/__test__/uniqueId.test.ts +0 -40
  39. package/src/lodash/index.ts +0 -396
  40. package/src/number/__test__/number.test.ts +0 -137
  41. package/src/number/index.ts +0 -161
  42. package/src/storage/__test__/storage.test.ts +0 -44
  43. package/src/storage/index.ts +0 -185
  44. package/src/string/__test__/string.test.ts +0 -24
  45. package/src/string/index.ts +0 -49
  46. package/src/timer/index.ts +0 -15
  47. package/tsconfig.json +0 -25
  48. package/types/global.d.ts +0 -13
  49. package/vite.config.ts +0 -16
  50. package/vitest.config.ts +0 -28
  51. /package/{dist/clipboard → clipboard}/index.d.ts +0 -0
  52. /package/{dist/cloneDeep → cloneDeep}/index.d.ts +0 -0
  53. /package/{dist/constants.d.ts → constants.d.ts} +0 -0
  54. /package/{dist/cookie → cookie}/index.d.ts +0 -0
  55. /package/{dist/date → date}/index.d.ts +0 -0
  56. /package/{dist/device → device}/index.d.ts +0 -0
  57. /package/{dist/element → element}/index.d.ts +0 -0
  58. /package/{dist/index.d.ts → index.d.ts} +0 -0
  59. /package/{dist/is → is}/index.d.ts +0 -0
  60. /package/{dist/lodash → lodash}/index.d.ts +0 -0
  61. /package/{dist/number → number}/index.d.ts +0 -0
  62. /package/{dist/shared.es.d.ts → shared.es.d.ts} +0 -0
  63. /package/{dist/shared.es.js → shared.es.js} +0 -0
  64. /package/{dist/shared.umd.js → shared.umd.js} +0 -0
  65. /package/{dist/skills → skills/shared}/SKILL.md +0 -0
  66. /package/{dist/skills → skills/shared}/examples/usage.ts +0 -0
  67. /package/{dist/skills → skills/shared}/references/clipboard.md +0 -0
  68. /package/{dist/skills → skills/shared}/references/cloneDeep.md +0 -0
  69. /package/{dist/skills → skills/shared}/references/cookie.md +0 -0
  70. /package/{dist/skills → skills/shared}/references/date.md +0 -0
  71. /package/{dist/skills → skills/shared}/references/device.md +0 -0
  72. /package/{dist/skills → skills/shared}/references/element.md +0 -0
  73. /package/{dist/skills → skills/shared}/references/is.md +0 -0
  74. /package/{dist/skills → skills/shared}/references/lodash.md +0 -0
  75. /package/{dist/skills → skills/shared}/references/number.md +0 -0
  76. /package/{dist/skills → skills/shared}/references/storage.md +0 -0
  77. /package/{dist/skills → skills/shared}/references/string.md +0 -0
  78. /package/{dist/skills → skills/shared}/references/timer.md +0 -0
  79. /package/{dist/storage → storage}/index.d.ts +0 -0
  80. /package/{dist/string → string}/index.d.ts +0 -0
  81. /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
- })
@@ -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
- })
@@ -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
- }
@@ -1,15 +0,0 @@
1
- /**
2
- * 睡眠函数
3
- * @param timer - 睡眠时间(ms)
4
- * @example
5
- * ```ts
6
- * await sleep(100)
7
- * ```
8
- */
9
- export function sleep(timer: number): Promise<void> {
10
- return new Promise((resolve) => {
11
- setTimeout(() => {
12
- resolve()
13
- }, timer)
14
- })
15
- }
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
File without changes
File without changes