@cloudcome/utils-core 1.1.1 → 1.2.0

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 (291) hide show
  1. package/dist/array.cjs +129 -0
  2. package/dist/array.cjs.map +1 -0
  3. package/dist/array.d.ts +171 -0
  4. package/dist/array.mjs +129 -0
  5. package/dist/array.mjs.map +1 -0
  6. package/dist/async.cjs +219 -0
  7. package/dist/async.cjs.map +1 -0
  8. package/dist/async.d.ts +137 -0
  9. package/dist/async.mjs +219 -0
  10. package/dist/async.mjs.map +1 -0
  11. package/dist/base64.cjs +16 -0
  12. package/dist/base64.cjs.map +1 -0
  13. package/dist/base64.d.ts +7 -0
  14. package/dist/base64.mjs +16 -0
  15. package/dist/base64.mjs.map +1 -0
  16. package/dist/cache.cjs +79 -0
  17. package/dist/cache.cjs.map +1 -0
  18. package/dist/cache.d.ts +90 -0
  19. package/dist/cache.mjs +79 -0
  20. package/dist/cache.mjs.map +1 -0
  21. package/{src/color/contrast.ts → dist/color/contrast.d.ts} +2 -12
  22. package/dist/color/distance.d.ts +8 -0
  23. package/dist/color/helpers.d.ts +2 -0
  24. package/dist/color/hex-hsl.d.ts +3 -0
  25. package/{src/color/hex-hsv.ts → dist/color/hex-hsv.d.ts} +3 -11
  26. package/{src/color/hex-hwb.ts → dist/color/hex-hwb.d.ts} +3 -11
  27. package/dist/color/hex-rgb.d.ts +18 -0
  28. package/{src/color/hsl-lighten.ts → dist/color/hsl-lighten.d.ts} +2 -7
  29. package/{src/color/hsv-brighten.ts → dist/color/hsv-brighten.d.ts} +2 -7
  30. package/{src/color/luminance.ts → dist/color/luminance.d.ts} +2 -9
  31. package/{src/color/mix.ts → dist/color/mix.d.ts} +2 -10
  32. package/dist/color/rgb-hsl.d.ts +23 -0
  33. package/{src/color/rgb-hsv.ts → dist/color/rgb-hsv.d.ts} +3 -30
  34. package/dist/color/rgb-hwb.d.ts +29 -0
  35. package/{src/color/rgb-lab.ts → dist/color/rgb-lab.d.ts} +3 -11
  36. package/dist/color/rgb-whiter.d.ts +12 -0
  37. package/dist/color/rgb-xyz.d.ts +22 -0
  38. package/{src/color/types.ts → dist/color/types.d.ts} +30 -12
  39. package/{src/color/xyz-lab.ts → dist/color/xyz-lab.d.ts} +3 -32
  40. package/dist/color.cjs +250 -0
  41. package/dist/color.cjs.map +1 -0
  42. package/dist/color.mjs +250 -0
  43. package/dist/color.mjs.map +1 -0
  44. package/dist/const.cjs +14 -0
  45. package/dist/const.cjs.map +1 -0
  46. package/dist/const.mjs +15 -0
  47. package/dist/const.mjs.map +1 -0
  48. package/dist/core.cjs +250 -0
  49. package/dist/core.cjs.map +1 -0
  50. package/dist/core.mjs +251 -0
  51. package/dist/core.mjs.map +1 -0
  52. package/dist/crypto/md5.d.mts +1 -0
  53. package/dist/crypto/sha1.d.mts +1 -0
  54. package/dist/crypto/sha256.d.mts +1 -0
  55. package/dist/crypto/sha512.d.mts +1 -0
  56. package/dist/crypto.cjs +812 -0
  57. package/dist/crypto.cjs.map +1 -0
  58. package/{src/crypto.ts → dist/crypto.d.ts} +4 -20
  59. package/dist/crypto.mjs +812 -0
  60. package/dist/crypto.mjs.map +1 -0
  61. package/dist/date/const.d.ts +6 -0
  62. package/dist/date/core.d.ts +52 -0
  63. package/dist/date/days.d.ts +23 -0
  64. package/{src/date/is.ts → dist/date/is.d.ts} +8 -102
  65. package/dist/date/relative.d.ts +44 -0
  66. package/dist/date/start-end.d.ts +73 -0
  67. package/dist/date/timezone.d.ts +67 -0
  68. package/dist/date/weeks.d.ts +72 -0
  69. package/dist/date.cjs +239 -0
  70. package/dist/date.cjs.map +1 -0
  71. package/dist/date.mjs +241 -0
  72. package/dist/date.mjs.map +1 -0
  73. package/dist/dict.cjs +2 -0
  74. package/dist/dict.cjs.map +1 -0
  75. package/dist/dict.mjs +2 -0
  76. package/dist/dict.mjs.map +1 -0
  77. package/dist/each.cjs +18 -0
  78. package/dist/each.cjs.map +1 -0
  79. package/dist/each.mjs +19 -0
  80. package/dist/each.mjs.map +1 -0
  81. package/dist/easing.cjs +151 -0
  82. package/dist/easing.cjs.map +1 -0
  83. package/dist/easing.d.ts +46 -0
  84. package/dist/easing.mjs +151 -0
  85. package/dist/easing.mjs.map +1 -0
  86. package/dist/emitter.cjs +94 -0
  87. package/dist/emitter.cjs.map +1 -0
  88. package/dist/emitter.d.ts +68 -0
  89. package/dist/emitter.mjs +94 -0
  90. package/dist/emitter.mjs.map +1 -0
  91. package/dist/enum.cjs +58 -0
  92. package/dist/enum.cjs.map +1 -0
  93. package/dist/enum.d.ts +68 -0
  94. package/dist/enum.mjs +58 -0
  95. package/dist/enum.mjs.map +1 -0
  96. package/dist/env.cjs +28 -0
  97. package/dist/env.cjs.map +1 -0
  98. package/{src/env.ts → dist/env.d.ts} +6 -30
  99. package/dist/env.mjs +28 -0
  100. package/dist/env.mjs.map +1 -0
  101. package/dist/error.cjs +12 -0
  102. package/dist/error.cjs.map +1 -0
  103. package/{src/error.ts → dist/error.d.ts} +3 -12
  104. package/dist/error.mjs +12 -0
  105. package/dist/error.mjs.map +1 -0
  106. package/dist/exception.cjs +22 -0
  107. package/dist/exception.cjs.map +1 -0
  108. package/dist/exception.d.ts +31 -0
  109. package/dist/exception.mjs +22 -0
  110. package/dist/exception.mjs.map +1 -0
  111. package/dist/fn.cjs +76 -0
  112. package/dist/fn.cjs.map +1 -0
  113. package/dist/fn.d.ts +102 -0
  114. package/dist/fn.mjs +76 -0
  115. package/dist/fn.mjs.map +1 -0
  116. package/dist/index.cjs +5 -0
  117. package/dist/index.cjs.map +1 -0
  118. package/dist/index.d.ts +1 -0
  119. package/dist/index.mjs +5 -0
  120. package/dist/index.mjs.map +1 -0
  121. package/dist/merge.cjs +87 -0
  122. package/dist/merge.cjs.map +1 -0
  123. package/dist/merge.mjs +88 -0
  124. package/dist/merge.mjs.map +1 -0
  125. package/dist/number.cjs +14 -0
  126. package/dist/number.cjs.map +1 -0
  127. package/dist/number.d.ts +153 -0
  128. package/dist/number.mjs +14 -0
  129. package/dist/number.mjs.map +1 -0
  130. package/{src/object/each.ts → dist/object/each.d.ts} +3 -23
  131. package/dist/object/get-set.d.ts +111 -0
  132. package/dist/object/is.d.ts +32 -0
  133. package/dist/object/merge.d.ts +72 -0
  134. package/{src/object/process.ts → dist/object/process.d.ts} +4 -38
  135. package/dist/object.cjs +130 -0
  136. package/dist/object.cjs.map +1 -0
  137. package/dist/object.mjs +130 -0
  138. package/dist/object.mjs.map +1 -0
  139. package/dist/path.cjs +77 -0
  140. package/dist/path.cjs.map +1 -0
  141. package/dist/path.d.ts +82 -0
  142. package/dist/path.mjs +77 -0
  143. package/dist/path.mjs.map +1 -0
  144. package/dist/promise.cjs +62 -0
  145. package/dist/promise.cjs.map +1 -0
  146. package/{src/promise.ts → dist/promise.d.ts} +6 -67
  147. package/dist/promise.mjs +62 -0
  148. package/dist/promise.mjs.map +1 -0
  149. package/dist/qs.cjs +47 -0
  150. package/dist/qs.cjs.map +1 -0
  151. package/{src/qs.ts → dist/qs.d.ts} +3 -60
  152. package/dist/qs.mjs +47 -0
  153. package/dist/qs.mjs.map +1 -0
  154. package/dist/regexp.cjs +66 -0
  155. package/dist/regexp.cjs.map +1 -0
  156. package/dist/regexp.d.ts +65 -0
  157. package/dist/regexp.mjs +66 -0
  158. package/dist/regexp.mjs.map +1 -0
  159. package/dist/string.cjs +16 -0
  160. package/dist/string.cjs.map +1 -0
  161. package/dist/string.d.ts +80 -0
  162. package/dist/string.mjs +16 -0
  163. package/dist/string.mjs.map +1 -0
  164. package/dist/string2.cjs +157 -0
  165. package/dist/string2.cjs.map +1 -0
  166. package/dist/string2.mjs +158 -0
  167. package/dist/string2.mjs.map +1 -0
  168. package/dist/time/from.d.ts +14 -0
  169. package/dist/time/to.d.ts +38 -0
  170. package/dist/time.cjs +82 -0
  171. package/dist/time.cjs.map +1 -0
  172. package/dist/time.mjs +82 -0
  173. package/dist/time.mjs.map +1 -0
  174. package/dist/timer.cjs +119 -0
  175. package/dist/timer.cjs.map +1 -0
  176. package/dist/timer.d.ts +96 -0
  177. package/{src/timer.ts → dist/timer.mjs} +17 -124
  178. package/dist/timer.mjs.map +1 -0
  179. package/dist/tree.cjs +125 -0
  180. package/dist/tree.cjs.map +1 -0
  181. package/{src/tree.ts → dist/tree.d.ts} +41 -225
  182. package/dist/tree.mjs +125 -0
  183. package/dist/tree.mjs.map +1 -0
  184. package/dist/type.cjs +78 -0
  185. package/dist/type.cjs.map +1 -0
  186. package/{src/type.ts → dist/type.d.ts} +20 -96
  187. package/dist/type.mjs +78 -0
  188. package/dist/type.mjs.map +1 -0
  189. package/dist/types.cjs +2 -0
  190. package/dist/types.cjs.map +1 -0
  191. package/{src/types.ts → dist/types.d.ts} +12 -33
  192. package/dist/types.mjs +2 -0
  193. package/dist/types.mjs.map +1 -0
  194. package/dist/unique.cjs +46 -0
  195. package/dist/unique.cjs.map +1 -0
  196. package/dist/unique.d.ts +22 -0
  197. package/dist/unique.mjs +46 -0
  198. package/dist/unique.mjs.map +1 -0
  199. package/dist/url.cjs +37 -0
  200. package/dist/url.cjs.map +1 -0
  201. package/dist/url.d.ts +53 -0
  202. package/dist/url.mjs +37 -0
  203. package/dist/url.mjs.map +1 -0
  204. package/dist/version.cjs +33 -0
  205. package/dist/version.cjs.map +1 -0
  206. package/dist/version.d.ts +32 -0
  207. package/dist/version.mjs +33 -0
  208. package/dist/version.mjs.map +1 -0
  209. package/package.json +8 -2
  210. package/CHANGELOG.md +0 -52
  211. package/src/array.ts +0 -312
  212. package/src/async.ts +0 -379
  213. package/src/base64.ts +0 -20
  214. package/src/cache.ts +0 -146
  215. package/src/color/distance.ts +0 -28
  216. package/src/color/helpers.ts +0 -23
  217. package/src/color/hex-hsl.ts +0 -11
  218. package/src/color/hex-rgb.ts +0 -39
  219. package/src/color/rgb-hsl.ts +0 -53
  220. package/src/color/rgb-hwb.ts +0 -56
  221. package/src/color/rgb-whiter.ts +0 -22
  222. package/src/color/rgb-xyz.ts +0 -62
  223. package/src/crypto/md5.mjs +0 -357
  224. package/src/crypto/sha1.mjs +0 -300
  225. package/src/crypto/sha256.mjs +0 -310
  226. package/src/crypto/sha512.mjs +0 -459
  227. package/src/date/const.ts +0 -6
  228. package/src/date/core.ts +0 -162
  229. package/src/date/days.ts +0 -51
  230. package/src/date/relative.ts +0 -92
  231. package/src/date/start-end.ts +0 -246
  232. package/src/date/timezone.ts +0 -220
  233. package/src/date/weeks.ts +0 -100
  234. package/src/dts/global.d.ts +0 -27
  235. package/src/easing.ts +0 -166
  236. package/src/emitter.ts +0 -117
  237. package/src/enum.ts +0 -171
  238. package/src/exception.ts +0 -68
  239. package/src/fn.ts +0 -197
  240. package/src/index.ts +0 -1
  241. package/src/number.ts +0 -236
  242. package/src/object/get-set.ts +0 -273
  243. package/src/object/is.ts +0 -128
  244. package/src/object/merge.ts +0 -180
  245. package/src/path.ts +0 -188
  246. package/src/regexp.ts +0 -156
  247. package/src/string.ts +0 -146
  248. package/src/time/from.ts +0 -57
  249. package/src/time/to.ts +0 -106
  250. package/src/unique.ts +0 -77
  251. package/src/url.ts +0 -93
  252. package/src/version.ts +0 -71
  253. package/test/array.test.ts +0 -332
  254. package/test/async-real.test.ts +0 -39
  255. package/test/async.test.ts +0 -375
  256. package/test/base64.test.ts +0 -32
  257. package/test/cache.test.ts +0 -83
  258. package/test/color.test.ts +0 -163
  259. package/test/crypto.test.ts +0 -34
  260. package/test/date-tz.test.ts +0 -206
  261. package/test/date.test.ts +0 -353
  262. package/test/easing.test.ts +0 -33
  263. package/test/emitter.test.ts +0 -71
  264. package/test/enum.test.ts +0 -113
  265. package/test/env.test.ts +0 -69
  266. package/test/error.test.ts +0 -58
  267. package/test/exception.test.ts +0 -43
  268. package/test/fn.test.ts +0 -263
  269. package/test/helpers.ts +0 -23
  270. package/test/index.test.ts +0 -6
  271. package/test/number.test.ts +0 -213
  272. package/test/object.test.ts +0 -309
  273. package/test/path.test.ts +0 -156
  274. package/test/promise.test.ts +0 -199
  275. package/test/qs.test.ts +0 -79
  276. package/test/regexp.test.ts +0 -97
  277. package/test/string.test.ts +0 -150
  278. package/test/time.test.ts +0 -214
  279. package/test/timer.test.ts +0 -114
  280. package/test/tree.test.ts +0 -348
  281. package/test/type.test.ts +0 -226
  282. package/test/unique.test.ts +0 -71
  283. package/test/url.test.ts +0 -136
  284. package/test/version.test.ts +0 -52
  285. package/tsconfig.json +0 -31
  286. package/vite.config.mts +0 -114
  287. /package/{src/color.ts → dist/color.d.ts} +0 -0
  288. /package/{src/date.ts → dist/date.d.ts} +0 -0
  289. /package/{src/dict.ts → dist/dict.d.ts} +0 -0
  290. /package/{src/object.ts → dist/object.d.ts} +0 -0
  291. /package/{src/time.ts → dist/time.d.ts} +0 -0
package/test/type.test.ts DELETED
@@ -1,226 +0,0 @@
1
- import { fnNoop } from '@/fn';
2
- import {
3
- isArray,
4
- isAsyncFunction,
5
- isBigInt,
6
- isBoolean,
7
- isDate,
8
- isError,
9
- isFunction,
10
- isNever,
11
- isNull,
12
- isNullish,
13
- isNumber,
14
- isObject,
15
- isPrimitive,
16
- isPromise,
17
- isString,
18
- isSymbol,
19
- isUndefined,
20
- isVoid,
21
- typeIs,
22
- } from '@/type';
23
- import { describe, expect, it } from 'vitest';
24
-
25
- describe('typeIs', () => {
26
- it('应返回正确的类型名称', () => {
27
- expect(typeIs('hello')).toBe('string');
28
- expect(typeIs(42)).toBe('number');
29
- expect(typeIs(true)).toBe('boolean');
30
- expect(typeIs(Symbol('sym'))).toBe('symbol');
31
- expect(typeIs(BigInt(123))).toBe('bigint');
32
- expect(typeIs(undefined)).toBe('undefined');
33
- expect(typeIs(null)).toBe('null');
34
- expect(typeIs({})).toBe('object');
35
- expect(typeIs([])).toBe('array');
36
- expect(typeIs(() => {})).toBe('function');
37
- expect(typeIs(Number.NaN)).toBe('number');
38
- expect(typeIs(new Error('error'))).toBe('error');
39
- expect(typeIs(Promise.resolve())).toBe('promise');
40
- });
41
- });
42
-
43
- describe('isString', () => {
44
- it('应正确判断字符串', () => {
45
- expect(isString('hello')).toBe(true);
46
- expect(isString(42)).toBe(false);
47
- });
48
- });
49
-
50
- describe('isBoolean', () => {
51
- it('应正确判断布尔值', () => {
52
- expect(isBoolean(true)).toBe(true);
53
- expect(isBoolean(false)).toBe(true);
54
- expect(isBoolean(42)).toBe(false);
55
- });
56
- });
57
-
58
- describe('isSymbol', () => {
59
- it('应正确判断符号', () => {
60
- expect(isSymbol(Symbol('sym'))).toBe(true);
61
- expect(isSymbol('hello')).toBe(false);
62
- });
63
- });
64
-
65
- describe('isBigInt', () => {
66
- it('应正确判断大整数', () => {
67
- expect(isBigInt(BigInt(123))).toBe(true);
68
- expect(isBigInt(42)).toBe(false);
69
- });
70
- });
71
-
72
- describe('isNumber', () => {
73
- it('应正确判断数字', () => {
74
- expect(isNumber(42)).toBe(true);
75
- expect(isNumber(Number.NaN)).toBe(false);
76
- });
77
- });
78
-
79
- describe('isUndefined', () => {
80
- it('应正确判断 undefined', () => {
81
- expect(isUndefined(undefined)).toBe(true);
82
- expect(isUndefined(null)).toBe(false);
83
- });
84
- });
85
-
86
- describe('isVoid', () => {
87
- it('应正确判断 void', () => {
88
- expect(isVoid(undefined)).toBe(true);
89
- expect(isVoid(null)).toBe(false);
90
- });
91
- });
92
-
93
- describe('isNever', () => {
94
- it('应正确处理 never 类型', () => {
95
- try {
96
- // 这里需要传入一个 never 类型的值,但 TypeScript 无法直接创建 never 类型的值
97
- // 因此我们使用一个类型断言来模拟 never 类型
98
- const neverValue = ((): never => {
99
- throw new Error('never');
100
- })();
101
- expect(() => isNever(neverValue)).not.toThrow();
102
- } catch (cause) {
103
- //
104
- }
105
- });
106
- });
107
-
108
- describe('isNull', () => {
109
- it('应正确判断 null', () => {
110
- expect(isNull(null)).toBe(true);
111
- expect(isNull(undefined)).toBe(false);
112
- });
113
- });
114
-
115
- describe('isNullish', () => {
116
- it('应正确判断 nullish', () => {
117
- expect(isNullish(null)).toBe(true);
118
- expect(isNullish(undefined)).toBe(true);
119
- expect(isNullish(void 0)).toBe(true);
120
- expect(isNullish(0)).toBe(false);
121
- });
122
- });
123
-
124
- describe('isPrimitive', () => {
125
- it('应正确判断原始类型', () => {
126
- expect(isPrimitive(null)).toBe(true);
127
- expect(isPrimitive(42)).toBe(true);
128
- expect(isPrimitive('hello')).toBe(true);
129
- expect(isPrimitive(true)).toBe(true);
130
- expect(isPrimitive(Symbol('sym'))).toBe(true);
131
- expect(isPrimitive(BigInt(123))).toBe(true);
132
- expect(isPrimitive({})).toBe(false);
133
- expect(isPrimitive([])).toBe(false);
134
- expect(isPrimitive(() => {})).toBe(false);
135
- });
136
- });
137
-
138
- describe('isObject', () => {
139
- it('应正确判断对象', () => {
140
- expect(isObject({})).toBe(true);
141
- expect(isObject([])).toBe(false);
142
- expect(isObject(() => {})).toBe(false);
143
- });
144
- });
145
-
146
- describe('isArray', () => {
147
- it('应正确判断数组', () => {
148
- expect(isArray([])).toBe(true);
149
- expect(isArray({})).toBe(false);
150
- expect(isArray(() => {})).toBe(false);
151
- });
152
- });
153
-
154
- describe('isFunction', () => {
155
- it('应正确判断函数', () => {
156
- expect(isFunction(() => {})).toBe(true);
157
- expect(isFunction({})).toBe(false);
158
- expect(isFunction([])).toBe(false);
159
- });
160
- });
161
-
162
- describe('isError', () => {
163
- it('应正确判断 Error 类型', () => {
164
- expect(isError(new Error('error'))).toBe(true);
165
- expect(isError({})).toBe(false);
166
- });
167
- });
168
-
169
- describe('isPromise', () => {
170
- it('应正确判断 Promise 类型', () => {
171
- expect(isPromise(Promise.resolve())).toBe(true);
172
- expect(isPromise(new Promise(() => {}))).toBe(true);
173
- const p = Promise.reject().catch(fnNoop);
174
- expect(isPromise(p)).toBe(true);
175
- });
176
-
177
- it('应正确判断非 Promise 类型', () => {
178
- expect(isPromise('hello')).toBe(false);
179
- expect(isPromise(42)).toBe(false);
180
- expect(isPromise(true)).toBe(false);
181
- expect(isPromise(Symbol('sym'))).toBe(false);
182
- expect(isPromise(BigInt(123))).toBe(false);
183
- expect(isPromise(undefined)).toBe(false);
184
- expect(isPromise(null)).toBe(false);
185
- expect(isPromise({})).toBe(false);
186
- expect(isPromise([])).toBe(false);
187
- expect(isPromise(() => {})).toBe(false);
188
- expect(isPromise(Number.NaN)).toBe(false);
189
- expect(isPromise(new Error('error'))).toBe(false);
190
- });
191
- });
192
-
193
- describe('isDate', () => {
194
- it('应正确判断 Date 类型', () => {
195
- expect(isDate(new Date())).toBe(true);
196
- expect(isDate(Date.now())).toBe(false);
197
- });
198
- });
199
-
200
- describe('isAsyncFunction', () => {
201
- it('应正确判断异步函数', async () => {
202
- async function exampleAsync() {}
203
- const asyncArrow = async () => {};
204
-
205
- expect(isAsyncFunction(exampleAsync)).toBe(true);
206
- expect(isAsyncFunction(asyncArrow)).toBe(true);
207
- });
208
-
209
- it('应正确判断普通函数', () => {
210
- function exampleSync() {}
211
- const syncArrow = () => {};
212
-
213
- expect(isAsyncFunction(exampleSync)).toBe(false);
214
- expect(isAsyncFunction(syncArrow)).toBe(false);
215
- });
216
-
217
- it('应正确判断非函数类型', () => {
218
- expect(isAsyncFunction({})).toBe(false);
219
- expect(isAsyncFunction([])).toBe(false);
220
- expect(isAsyncFunction('function')).toBe(false);
221
- expect(isAsyncFunction(42)).toBe(false);
222
- expect(isAsyncFunction(true)).toBe(false);
223
- expect(isAsyncFunction(null)).toBe(false);
224
- expect(isAsyncFunction(undefined)).toBe(false);
225
- });
226
- });
@@ -1,71 +0,0 @@
1
- import { uniqueBigInt, uniqueString } from '@/unique';
2
-
3
- describe('uniqueBigInt', () => {
4
- test('默认参数返回 bigint 类型', () => {
5
- const result = uniqueBigInt();
6
- expect(typeof result).toBe('bigint');
7
- });
8
-
9
- test('指定 randomLength 为 0 时返回值正确', () => {
10
- const result = uniqueBigInt(0);
11
- expect(typeof result).toBe('bigint');
12
- expect(result.toString().length).toBeGreaterThanOrEqual(13); // 时间戳部分至少 13 位
13
- });
14
-
15
- test('指定 randomLength 为正整数时返回值正确', () => {
16
- const randomLength = 5;
17
- const result = uniqueBigInt(randomLength);
18
- expect(typeof result).toBe('bigint');
19
- expect(result.toString().length).toBeGreaterThanOrEqual(13 + randomLength); // 时间戳 + 随机部分
20
- });
21
-
22
- test('多次调用生成的值具有唯一性', () => {
23
- const results = new Set<bigint>();
24
- for (let i = 0; i < 1000; i++) {
25
- results.add(uniqueBigInt());
26
- }
27
- expect(results.size).toBe(1000); // 确保无重复值
28
- });
29
- });
30
-
31
- describe('uniqueString', () => {
32
- test('默认参数返回字符串且长度正确', () => {
33
- const result = uniqueString();
34
- expect(typeof result).toBe('string');
35
- expect(result.length).toBeGreaterThan(0);
36
- });
37
-
38
- test('指定 minLength 参数时返回字符串长度符合要求', () => {
39
- const minLength = 30;
40
- const result = uniqueString(minLength);
41
- expect(result.length).toBeGreaterThanOrEqual(minLength);
42
- });
43
-
44
- test('指定 dict 参数时使用指定字符集', () => {
45
- const customDict = 'ABC123';
46
- const result = uniqueString(0, customDict);
47
- expect(result).toEqual(expect.stringMatching(new RegExp(`^[${customDict}]+$`)));
48
- });
49
-
50
- test('同时指定 minLength 和 dict 参数时满足条件', () => {
51
- const minLength = 3;
52
- const customDict = 'XYZ';
53
- const result = uniqueString(minLength, customDict);
54
- expect(result.length).toBeGreaterThanOrEqual(minLength);
55
- expect(result).toEqual(expect.stringMatching(new RegExp(`^[${customDict}]+$`)));
56
- });
57
-
58
- test('多次调用生成唯一字符串', () => {
59
- const results = new Set<string>();
60
- for (let i = 0; i < 1000; i++) {
61
- results.add(uniqueString());
62
- }
63
- expect(results.size).toBe(1000);
64
- });
65
-
66
- test('使用字符串类型 dict 参数时正确应用字符集', () => {
67
- const customDict = 'abcdef';
68
- const result = uniqueString(customDict);
69
- expect(result).toEqual(expect.stringMatching(new RegExp(`^[${customDict}]+$`)));
70
- });
71
- });
package/test/url.test.ts DELETED
@@ -1,136 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { type TURLMeta, urlParse, urlStringify } from '../src/url';
3
-
4
- describe('urlParse 函数', () => {
5
- it('应正确解析完整的 URL', () => {
6
- const url = 'https://user:pass@example.com:8080/path/to/resource?query=param#hash';
7
- const parsed = urlParse(url);
8
- expect(parsed).toEqual({
9
- hash: '#hash',
10
- host: 'example.com:8080',
11
- hostname: 'example.com',
12
- password: 'pass',
13
- pathname: '/path/to/resource',
14
- port: '8080',
15
- protocol: 'https:',
16
- search: '?query=param',
17
- username: 'user',
18
- });
19
- });
20
-
21
- it('应正确处理缺少部分组件的 URL', () => {
22
- const url = 'https://example.com/path/to/resource';
23
- const parsed = urlParse(url);
24
- expect(parsed).toEqual({
25
- hash: '',
26
- host: 'example.com',
27
- hostname: 'example.com',
28
- password: '',
29
- pathname: '/path/to/resource',
30
- port: '',
31
- protocol: 'https:',
32
- search: '',
33
- username: '',
34
- });
35
- });
36
-
37
- it('应正确处理不完整的 URL:没有协议', () => {
38
- const url = 'example.com/path/to/resource';
39
- const parsed = urlParse(url);
40
- expect(parsed).toEqual({
41
- hash: '',
42
- host: '',
43
- hostname: '',
44
- password: '',
45
- pathname: '',
46
- port: '',
47
- protocol: '',
48
- search: '',
49
- username: '',
50
- });
51
- });
52
-
53
- it('应正确处理不完整的 URL:没有协议、域名', () => {
54
- const url = '/path/to/resource';
55
- const parsed = urlParse(url);
56
- expect(parsed).toEqual({
57
- hash: '',
58
- host: '',
59
- hostname: '',
60
- password: '',
61
- pathname: '',
62
- port: '',
63
- protocol: '',
64
- search: '',
65
- username: '',
66
- });
67
- });
68
-
69
- it('应正确处理不完整的 URL:只有域名', () => {
70
- const url = 'example.com';
71
- const parsed = urlParse(url);
72
- expect(parsed).toEqual({
73
- hash: '',
74
- host: '',
75
- hostname: '',
76
- password: '',
77
- pathname: '',
78
- port: '',
79
- protocol: '',
80
- search: '',
81
- username: '',
82
- });
83
- });
84
- });
85
-
86
- describe('urlStringify 函数', () => {
87
- it('应正确将 URLComponents 对象转换为 URL 字符串', () => {
88
- const urlObj = {
89
- protocol: 'https:',
90
- hostname: 'example.com',
91
- port: '8080',
92
- pathname: '/path/to/resource',
93
- search: '?query=param',
94
- hash: '#hash',
95
- username: 'user',
96
- password: 'pass',
97
- } as TURLMeta;
98
- const url = urlStringify(urlObj);
99
- expect(url).toBe('https://user:pass@example.com:8080/path/to/resource?query=param#hash');
100
- });
101
-
102
- it('应正确处理缺少部分组件的 URLInfo 对象', () => {
103
- const urlObj = {
104
- protocol: 'https:',
105
- hostname: 'example.com',
106
- pathname: '/path/to/resource',
107
- } as TURLMeta;
108
- const url = urlStringify(urlObj);
109
- expect(url).toBe('https://example.com/path/to/resource');
110
- });
111
-
112
- it('没有协议', () => {
113
- const urlObj = {
114
- hostname: 'example.com',
115
- pathname: '/path/to/resource',
116
- } as TURLMeta;
117
- const url = urlStringify(urlObj);
118
- expect(url).toBe('example.com/path/to/resource');
119
- });
120
-
121
- it('只有域名', () => {
122
- const urlObj = {
123
- hostname: 'example.com',
124
- } as TURLMeta;
125
- const url = urlStringify(urlObj);
126
- expect(url).toBe('example.com');
127
- });
128
-
129
- it('只有路径', () => {
130
- const urlObj = {
131
- pathname: '/path/to/resource',
132
- } as TURLMeta;
133
- const url = urlStringify(urlObj);
134
- expect(url).toBe('/path/to/resource');
135
- });
136
- });
@@ -1,52 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { versionCompare, versionParse } from '../src/version';
3
-
4
- describe('版本号工具函数测试', () => {
5
- describe('versionParse 函数', () => {
6
- it('应正确解析标准版本号', () => {
7
- const result = versionParse('1.2.3');
8
- expect(result).toEqual({ major: 1, minor: 2, patch: 3 });
9
- });
10
-
11
- it('应处理缺失的版本号部分', () => {
12
- const result = versionParse('1.2');
13
- expect(result).toEqual({ major: 1, minor: 2, patch: 0 });
14
- });
15
-
16
- it('应处理非数字字符', () => {
17
- const result = versionParse('1.a.3');
18
- expect(result).toEqual({ major: 1, minor: 0, patch: 3 });
19
- });
20
-
21
- it('应处理空字符串', () => {
22
- const result = versionParse('');
23
- expect(result).toEqual({ major: 0, minor: 0, patch: 0 });
24
- });
25
- });
26
-
27
- describe('versionCompare 函数', () => {
28
- it('应正确比较主版本号', () => {
29
- expect(versionCompare('2.0.0', '1.0.0')).toBe(1);
30
- expect(versionCompare('1.0.0', '2.0.0')).toBe(-1);
31
- });
32
-
33
- it('应正确比较次版本号', () => {
34
- expect(versionCompare('1.2.0', '1.1.0')).toBe(1);
35
- expect(versionCompare('1.1.0', '1.2.0')).toBe(-1);
36
- });
37
-
38
- it('应正确比较修订号', () => {
39
- expect(versionCompare('1.2.3', '1.2.2')).toBe(1);
40
- expect(versionCompare('1.2.2', '1.2.3')).toBe(-1);
41
- });
42
-
43
- it('应处理相等版本号', () => {
44
- expect(versionCompare('1.2.3', '1.2.3')).toBe(0);
45
- });
46
-
47
- it('应处理不完整版本号', () => {
48
- expect(versionCompare('1.2', '1.2.0')).toBe(0);
49
- expect(versionCompare('1', '1.0.0')).toBe(0);
50
- });
51
- });
52
- });
package/tsconfig.json DELETED
@@ -1,31 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "jsx": "preserve",
4
- "jsxImportSource": "vue",
5
- "target": "ES2024",
6
- "module": "ESNext",
7
- "moduleResolution": "bundler",
8
-
9
- "strict": true,
10
- "noEmit": true,
11
- "allowJs": true,
12
- "sourceMap": true,
13
- "skipLibCheck": true,
14
- "esModuleInterop": true,
15
- "resolveJsonModule": true,
16
- "verbatimModuleSyntax": true,
17
- "allowImportingTsExtensions": false,
18
- "allowSyntheticDefaultImports": true,
19
- "forceConsistentCasingInFileNames": true,
20
-
21
- "lib": ["ES2024", "DOM"],
22
- "types": ["node", "vite/client", "vitest/globals"],
23
- "plugins": [],
24
- "paths": {
25
- "@/*": ["./src/*"]
26
- }
27
- },
28
-
29
- "include": ["**/*.ts", "**/.*.ts", "**/*.mts", "**/*.tsx", "**/*.vue"],
30
- "exclude": []
31
- }
package/vite.config.mts DELETED
@@ -1,114 +0,0 @@
1
- /**
2
- * @file vite.config.mts
3
- * @ref https://vitejs.dev/
4
- */
5
-
6
- import dts from 'vite-plugin-dts';
7
- import { externalizeDeps } from 'vite-plugin-externalize-deps';
8
- import tsconfigPaths from 'vite-tsconfig-paths';
9
- import { defineConfig } from 'vitest/config';
10
- import pkg from './package.json';
11
-
12
- export default defineConfig((env) => {
13
- const isProd = env.mode === 'production';
14
- const isTest = env.mode === 'test';
15
-
16
- return {
17
- base: '/',
18
- server: {
19
- port: 15170,
20
- },
21
- preview: {
22
- port: 15171,
23
- },
24
- define: {
25
- PKG_NAME: JSON.stringify(isTest ? 'pkg-name-for-test' : pkg.name),
26
- PKG_VERSION: JSON.stringify(isTest ? 'pkg-version-for-test' : pkg.version),
27
- PKG_DESCRIPTION: JSON.stringify(isTest ? 'pkg-description-for-test' : pkg.description),
28
- IS_TEST: JSON.stringify(isTest),
29
- },
30
- build: {
31
- minify: false,
32
- sourcemap: true,
33
- copyPublicDir: false,
34
- reportCompressedSize: false,
35
- lib: {
36
- entry:
37
- // expose-start
38
- {
39
- index: 'src/index.ts',
40
- array: './src/array.ts',
41
- async: './src/async.ts',
42
- base64: './src/base64.ts',
43
- cache: './src/cache.ts',
44
- color: './src/color.ts',
45
- crypto: './src/crypto.ts',
46
- date: './src/date.ts',
47
- dict: './src/dict.ts',
48
- easing: './src/easing.ts',
49
- emitter: './src/emitter.ts',
50
- enum: './src/enum.ts',
51
- env: './src/env.ts',
52
- error: './src/error.ts',
53
- exception: './src/exception.ts',
54
- fn: './src/fn.ts',
55
- number: './src/number.ts',
56
- object: './src/object.ts',
57
- path: './src/path.ts',
58
- promise: './src/promise.ts',
59
- qs: './src/qs.ts',
60
- regexp: './src/regexp.ts',
61
- string: './src/string.ts',
62
- time: './src/time.ts',
63
- timer: './src/timer.ts',
64
- tree: './src/tree.ts',
65
- type: './src/type.ts',
66
- types: './src/types.ts',
67
- unique: './src/unique.ts',
68
- url: './src/url.ts',
69
- version: './src/version.ts',
70
- },
71
- // expose-end
72
- },
73
- rollupOptions: {
74
- output: [
75
- {
76
- format: 'esm',
77
- entryFileNames: '[name].mjs',
78
- chunkFileNames: '[name].mjs',
79
- },
80
- {
81
- format: 'cjs',
82
- entryFileNames: '[name].cjs',
83
- chunkFileNames: '[name].cjs',
84
- },
85
- ],
86
- },
87
- },
88
- test: {
89
- globals: true,
90
- environment: 'jsdom',
91
- coverage: {
92
- all: true,
93
- include: ['src/**/*.ts'],
94
- reporter: ['lcov', 'text'],
95
- },
96
- },
97
- // esbuild: {
98
- // drop: isProd ? ['console', 'debugger'] : [],
99
- // },
100
- plugins: [
101
- tsconfigPaths(),
102
- externalizeDeps({
103
- deps: true,
104
- devDeps: true,
105
- peerDeps: true,
106
- optionalDeps: true,
107
- nodeBuiltins: true,
108
- }),
109
- dts({
110
- include: 'src',
111
- }),
112
- ],
113
- };
114
- });
File without changes
File without changes
File without changes
File without changes
File without changes