@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
package/src/is/index.ts DELETED
@@ -1,293 +0,0 @@
1
- const toString = Object.prototype.toString
2
-
3
- export function is(val: unknown, type: string) {
4
- return toString.call(val) === `[object ${type}]`
5
- }
6
- /**
7
- * 判断不是undefined
8
- * @param val -内容
9
- * @example
10
- * ```ts
11
- * let result= isDef('test')
12
- * ```
13
- */
14
- export function isDef<T = unknown>(val?: T): val is T {
15
- return typeof val !== 'undefined'
16
- }
17
- /**
18
- * 判断是undefined
19
- * @param val -内容
20
- * @example
21
- * ```ts
22
- * let result= isUnDef('test')
23
- * ```
24
- */
25
- export function isUnDef<T = unknown>(val?: T): val is T {
26
- return !isDef(val)
27
- }
28
-
29
- /**
30
- * 判断是Object,包含数组
31
- * @param val -内容
32
- * @example
33
- * ```ts
34
- * let result= isObject({name:1})
35
- * ```
36
- */
37
- export function isObject(val: any): val is Record<any, any> {
38
- return val !== null && typeof val === 'object'
39
- }
40
-
41
- /**
42
- * 判断是原始Object,不包含数组
43
- * @param val -内容
44
- * @example
45
- * ```ts
46
- * let result= isPlainObject({name:1})
47
- * ```
48
- */
49
- export function isPlainObject(val: unknown): val is Record<string, unknown> {
50
- return is(val, 'Object')
51
- }
52
-
53
- /**
54
- * 检测当前类型是否是空对象
55
- * @param obj - 检测当前类型
56
- * @returns 如果为空的对象则返回true、否则返回false
57
- */
58
- export const isEmptyObject = (obj: any): boolean => {
59
- return isPlainObject(obj) && Object.keys(obj).length === 0
60
- }
61
-
62
- /**
63
- * 检测当前类型是否空(空string|undefined|null)
64
- * @param val - 检测当前类型
65
- * @returns 如果为空的对象则返回true、否则返回false
66
- */
67
- export const isEmptyValue = (val: string | number | null | undefined): boolean => {
68
- if (isNullOrUnDef(val)) return true
69
- if (val === '') return true
70
- return false
71
- }
72
-
73
- /**
74
- * 判断是空,包括空数组,空对象,空Map
75
- * @param val -内容
76
- * @example
77
- * ```ts
78
- * let result= isEmpty({name:1})
79
- * ```
80
- */
81
- export function isEmpty<T = unknown>(val: T): val is T {
82
- if (isArray(val) || isString(val)) {
83
- return val.length === 0
84
- }
85
-
86
- if (val instanceof Map || val instanceof Set) {
87
- return val.size === 0
88
- }
89
-
90
- if (isObject(val)) {
91
- return Object.keys(val).length === 0
92
- }
93
-
94
- return false
95
- }
96
-
97
- /**
98
- * 判断是日期对象
99
- * @param val -内容
100
- * @example
101
- * ```ts
102
- * let result= isDate(new Date())
103
- * ```
104
- */
105
- export function isDate(val: unknown): val is Date {
106
- return is(val, 'Date')
107
- }
108
-
109
- /**
110
- * 判断是否为null
111
- * @param val - 任意值
112
- * @returns boolean
113
- */
114
- export function isNull(val: unknown): val is null {
115
- return val === null
116
- }
117
-
118
- /**
119
- * 判断是null和undefined
120
- * @param val -内容
121
- * @example
122
- * ```ts
123
- * let result= isNullAndUnDef('')
124
- * ```
125
- */
126
- export function isNullAndUnDef(val: unknown): val is null | undefined {
127
- return isUnDef(val) && isNull(val)
128
- }
129
-
130
- /**
131
- * 判断是null或undefined
132
- * @param val -内容
133
- * @example
134
- * ```ts
135
- * let result= isNullOrUnDef('')
136
- * ```
137
- */
138
- export function isNullOrUnDef(val: unknown): val is null | undefined {
139
- return isUnDef(val) || isNull(val)
140
- }
141
-
142
- /**
143
- * 是否是number
144
- * @param val -内容
145
- * @example
146
- * ```ts
147
- * let result= isNumber('test')
148
- * ```
149
- */
150
- export function isNumber(val: unknown): val is number {
151
- return is(val, 'Number')
152
- }
153
-
154
- /**
155
- * 是否是Promise
156
- * @param val -内容
157
- * @example
158
- * ```ts
159
- * let result= isPromise('test')
160
- * ```
161
- */
162
- export function isPromise<T = any>(val: any): val is Promise<T> {
163
- return is(val, 'Promise') && isFunction(val.then) && isFunction(val.catch)
164
- }
165
-
166
- export function isString(val: unknown): val is string {
167
- return is(val, 'String')
168
- }
169
-
170
- /**
171
- * 是否是函数
172
- * @param val -内容
173
- * @example
174
- * ```ts
175
- * let result= isFunction('test')
176
- * ```
177
- */
178
-
179
- export function isFunction(val: unknown): val is Function {
180
- return typeof val === 'function'
181
- }
182
-
183
- export function isBoolean(val: unknown): val is boolean {
184
- return is(val, 'Boolean')
185
- }
186
-
187
- /**
188
- * 是否是正则
189
- * @param val -内容
190
- * @example
191
- * ```ts
192
- * let result= isRegExp(window)
193
- * ```
194
- */
195
- export function isRegExp(val: unknown): val is RegExp {
196
- return is(val, 'RegExp')
197
- }
198
- /**
199
- * 是否是数组
200
- * @param val -内容
201
- * @example
202
- * ```ts
203
- * let result= isArray(window)
204
- * ```
205
- */
206
- export function isArray(val: any): val is Array<any> {
207
- return val && Array.isArray(val)
208
- }
209
-
210
- /**
211
- * 是否是Window
212
- * @param val -内容
213
- * @example
214
- * ```ts
215
- * let result= isWindow(window)
216
- * ```
217
- */
218
- export function isWindow(val: any): val is Window {
219
- return typeof window !== 'undefined' && is(val, 'Window')
220
- }
221
-
222
- export function isElement(val: unknown): val is Element {
223
- return isObject(val) && !!val.tagName
224
- }
225
-
226
- /**
227
- * 是否是Map
228
- * @param val -内容
229
- * @example
230
- * ```ts
231
- * let result= isMap(window)
232
- * ```
233
- */
234
- export function isMap(val: unknown): val is Map<any, any> {
235
- return is(val, 'Map')
236
- }
237
-
238
- export function isSet(val: unknown): val is Set<any> {
239
- return is(val, 'Set')
240
- }
241
-
242
- export const isServer = typeof window === 'undefined'
243
-
244
- export const isClient = !isServer
245
-
246
- /**
247
- * 是否是isUrl
248
- * @param val -内容
249
- * @example
250
- * ```ts
251
- * let result= isUrl('http://www.baidu.com')
252
- * ```
253
- */
254
- export function isUrl(path: string): boolean {
255
- const reg =
256
- // eslint-disable-next-line no-useless-escape
257
- /(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+(?::\d+)?|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/
258
- return reg.test(path)
259
- }
260
-
261
- /**
262
- * 判断是否为整数
263
- * @param val - 任意值
264
- * @returns 如果是整数则返回true,否则返回false
265
- */
266
- export function isInteger(val: unknown): boolean {
267
- if (typeof val === 'number') {
268
- return Number.isInteger(val) && !Number.isNaN(val) && Number.isFinite(val)
269
- }
270
- if (typeof val === 'string') {
271
- // 不使用 trim(),直接判断字符串是否为有效的整数格式
272
- const integerRegex = /^-?[1-9]\d*$|^0$/
273
- return integerRegex.test(val)
274
- }
275
- return false
276
- }
277
-
278
- /**
279
- * 判断是否为数字(整数或浮点数)
280
- * @param val - 任意值
281
- * @returns 如果是数字则返回true,否则返回false
282
- */
283
- export function isNumeric(val: unknown): boolean {
284
- if (typeof val === 'number') {
285
- return !Number.isNaN(val) && Number.isFinite(val)
286
- }
287
- if (typeof val === 'string') {
288
- // 不使用 trim(),直接判断字符串是否为有效的数字格式
289
- const numericRegex = /^-?[1-9]\d*(\.\d+)?$|^0(\.\d+)?$|^-?0\.\d+$/
290
- return numericRegex.test(val)
291
- }
292
- return false
293
- }
@@ -1,111 +0,0 @@
1
- import { describe, expect, test } from 'vitest'
2
- import { deepClone, omit, omitBy, pick, pickBy } from '../'
3
-
4
- describe('lodash.ts', () => {
5
- test('deepClone - param is a plain object', () => {
6
- const obj = {
7
- a: 1,
8
- b: {
9
- c: 2,
10
- d: {
11
- e: 3,
12
- },
13
- },
14
- }
15
- const cloneObj = deepClone(obj)
16
- expect(cloneObj).toEqual(obj)
17
- expect(cloneObj).not.toBe(obj)
18
- })
19
-
20
- test('deepClone - param is an array', () => {
21
- const arr = [
22
- 1,
23
- {
24
- a: 1,
25
- },
26
- 3,
27
- 4,
28
- { b: 2 },
29
- ]
30
- const cloneObj = deepClone(arr)
31
- expect(cloneObj).toEqual(arr)
32
- expect(cloneObj).not.toBe(arr)
33
- })
34
-
35
- test('pick - param set to default', () => {
36
- const obj = {
37
- a: 1,
38
- b: {
39
- c: 2,
40
- d: {
41
- e: 3,
42
- },
43
- },
44
- }
45
- const cloneObj = pick(obj, ['b'])
46
- expect(cloneObj).toEqual({ b: { c: 2, d: { e: 3 } } })
47
- expect(cloneObj).not.toBe(obj)
48
- })
49
-
50
- test('pickBy - param set to true', () => {
51
- const obj = {
52
- a: 1,
53
- b: {
54
- c: 2,
55
- d: {
56
- e: 3,
57
- },
58
- },
59
- c: '',
60
- d: undefined,
61
- }
62
- const cloneObj = pickBy(obj, (value) => !!value)
63
- const result = pick(obj, ['a', 'b'])
64
- expect(cloneObj).toEqual(result)
65
- expect(cloneObj).not.toBe(result)
66
- })
67
-
68
- test('omit - param is default', () => {
69
- const obj = {
70
- a: 1,
71
- b: {
72
- c: 2,
73
- d: {
74
- e: 3,
75
- },
76
- },
77
- c: '',
78
- d: undefined,
79
- }
80
- const cloneObj = omit(obj, ['a'])
81
- const result = {
82
- b: {
83
- c: 2,
84
- d: {
85
- e: 3,
86
- },
87
- },
88
- c: '',
89
- }
90
- expect(cloneObj).toEqual(result)
91
- expect(cloneObj).not.toBe(result)
92
- })
93
-
94
- test('omitBy - param set to false', () => {
95
- const obj = {
96
- a: 1,
97
- b: {
98
- c: 2,
99
- d: {
100
- e: 3,
101
- },
102
- },
103
- c: '',
104
- d: undefined,
105
- }
106
- const cloneObj = omitBy(obj, (value) => !value)
107
- const result = omit(obj, ['c'])
108
- expect(cloneObj).toEqual(result)
109
- expect(cloneObj).not.toBe(result)
110
- })
111
- })
@@ -1,107 +0,0 @@
1
- import { describe, expect, test } from 'vitest'
2
- import { objToQString, qStringToObj } from '../'
3
-
4
- describe('lodash.ts objToQString', () => {
5
- test('objToQString - param simple object', () => {
6
- const obj = {
7
- a: 1,
8
- b: 2,
9
- }
10
- const qString = objToQString(obj)
11
- expect(qString).toEqual('a=1&b=2')
12
- })
13
-
14
- test('objToQString - param object with array', () => {
15
- const obj = {
16
- a: 1,
17
- b: [2, 3],
18
- }
19
- const qString = objToQString(obj)
20
- expect(qString).toEqual('a=1&b=%5B2%2C3%5D')
21
- })
22
-
23
- test('objToQString - param object with object', () => {
24
- const obj = {
25
- a: 1,
26
- b: {
27
- c: 2,
28
- },
29
- }
30
- const qString = objToQString(obj)
31
- expect(qString).toEqual('a=1&b=%7B%22c%22%3A2%7D')
32
- })
33
-
34
- test('objToQString - param object with array and object', () => {
35
- const obj = {
36
- a: 1,
37
- b: [2, { c: 3 }],
38
- }
39
- const qString = objToQString(obj)
40
- expect(qString).toEqual('a=1&b=%5B2%2C%7B%22c%22%3A3%7D%5D')
41
- })
42
-
43
- test('objToQString - param is empty object', () => {
44
- const obj = {}
45
- const qString = objToQString(obj)
46
- expect(qString).toEqual('')
47
- })
48
-
49
- test('objToQString - param is null', () => {
50
- const obj = null
51
- // @ts-ignore
52
- const qString = objToQString(obj)
53
- expect(qString).toEqual('')
54
- })
55
-
56
- test('qStringToObj - param is simple string', () => {
57
- const qString = 'a=1&b=2&c=a'
58
- const obj = qStringToObj(qString)
59
- expect(obj).toEqual({ a: 1, b: 2, c: 'a' })
60
- })
61
-
62
- test('qStringToObj - param is string with array', () => {
63
- const qString = 'a=1&b=%5B2%2C3%5D'
64
- const obj = qStringToObj(qString)
65
- expect(obj).toEqual({ a: 1, b: [2, 3] })
66
- })
67
-
68
- test('qStringToObj - param is string with object', () => {
69
- const qString = 'a=1&b=%7B%22c%22%3A2%7D'
70
- const obj = qStringToObj(qString)
71
- expect(obj).toEqual({ a: 1, b: { c: 2 } })
72
- })
73
-
74
- test('qStringToObj - param is string with array and object', () => {
75
- const qString = 'a=1&b=%5B2%2C%7B%22c%22%3A3%7D%5D'
76
- const obj = qStringToObj(qString)
77
- expect(obj).toEqual({ a: 1, b: [2, { c: 3 }] })
78
- })
79
-
80
- test('qStringToObj - param is null', () => {
81
- const qString = null
82
- // @ts-ignore
83
- const obj = qStringToObj(qString)
84
- expect(obj).toEqual({})
85
- })
86
-
87
- test('qStringToObj - param is empty string', () => {
88
- const qString = ''
89
- const obj = qStringToObj(qString)
90
- expect(obj).toEqual({})
91
- })
92
- test('qStringToObj - param is url', () => {
93
- const qString = 'https://example.com/path/to/page'
94
- const obj = qStringToObj(qString)
95
- expect(obj).toEqual({})
96
- })
97
- test('qStringToObj - param is url with token', () => {
98
- const qString = 'https://example.com/path/to/page?token=abc123'
99
- const obj = qStringToObj(qString)
100
- expect(obj).toEqual({ token: 'abc123' })
101
- })
102
- test('qStringToObj - param is url arg 2', () => {
103
- const qString = 'https://example.com/path/to/page?token=abc123&name=test'
104
- const obj = qStringToObj(qString)
105
- expect(obj).toEqual({ token: 'abc123', name: 'test' })
106
- })
107
- })
@@ -1,40 +0,0 @@
1
- import { describe, expect, test } from 'vitest'
2
- import { uniqueId } from '../'
3
-
4
- describe('lodash.ts', () => {
5
- test('uniqueId 11 length', () => {
6
- const length = 11
7
- const _uid = uniqueId(length)
8
- const _uid1 = uniqueId(length)
9
- expect(_uid.length).toEqual(length)
10
- expect(_uid1.length).toEqual(length)
11
- expect(_uid).not.toEqual(_uid1)
12
- })
13
-
14
- test('uniqueId 16 length', () => {
15
- const length = 16
16
- const _uid = uniqueId(length)
17
- const _uid1 = uniqueId(length)
18
- expect(_uid.length).toEqual(length)
19
- expect(_uid1.length).toEqual(length)
20
- expect(_uid).not.toEqual(_uid1)
21
- })
22
-
23
- test('uniqueId 19 length', () => {
24
- const length = 19
25
- const _uid = uniqueId(length)
26
- const _uid1 = uniqueId(length)
27
- expect(_uid.length).toEqual(length)
28
- expect(_uid1.length).toEqual(length)
29
- expect(_uid).not.toEqual(_uid1)
30
- })
31
-
32
- test('uniqueId 32 length', () => {
33
- const length = 32
34
- const _uid = uniqueId(length)
35
- const _uid1 = uniqueId(length)
36
- expect(_uid.length).toEqual(length)
37
- expect(_uid1.length).toEqual(length)
38
- expect(_uid).not.toEqual(_uid1)
39
- })
40
- })