@cloudcome/utils-core 0.0.0 → 1.1.1

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 (107) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/LICENSE +21 -0
  3. package/package.json +277 -6
  4. package/src/array.ts +312 -0
  5. package/src/async.ts +379 -0
  6. package/src/base64.ts +20 -0
  7. package/src/cache.ts +146 -0
  8. package/src/color/contrast.ts +20 -0
  9. package/src/color/distance.ts +28 -0
  10. package/src/color/helpers.ts +23 -0
  11. package/src/color/hex-hsl.ts +11 -0
  12. package/src/color/hex-hsv.ts +28 -0
  13. package/src/color/hex-hwb.ts +31 -0
  14. package/src/color/hex-rgb.ts +39 -0
  15. package/src/color/hsl-lighten.ts +15 -0
  16. package/src/color/hsv-brighten.ts +17 -0
  17. package/src/color/luminance.ts +17 -0
  18. package/src/color/mix.ts +26 -0
  19. package/src/color/rgb-hsl.ts +53 -0
  20. package/src/color/rgb-hsv.ts +52 -0
  21. package/src/color/rgb-hwb.ts +56 -0
  22. package/src/color/rgb-lab.ts +33 -0
  23. package/src/color/rgb-whiter.ts +22 -0
  24. package/src/color/rgb-xyz.ts +62 -0
  25. package/src/color/types.ts +65 -0
  26. package/src/color/xyz-lab.ts +54 -0
  27. package/src/color.ts +19 -0
  28. package/src/crypto/md5.mjs +357 -0
  29. package/src/crypto/sha1.mjs +300 -0
  30. package/src/crypto/sha256.mjs +310 -0
  31. package/src/crypto/sha512.mjs +459 -0
  32. package/src/crypto.ts +60 -0
  33. package/src/date/const.ts +6 -0
  34. package/src/date/core.ts +162 -0
  35. package/src/date/days.ts +51 -0
  36. package/src/date/is.ts +186 -0
  37. package/src/date/relative.ts +92 -0
  38. package/src/date/start-end.ts +246 -0
  39. package/src/date/timezone.ts +220 -0
  40. package/src/date/weeks.ts +100 -0
  41. package/src/date.ts +8 -0
  42. package/src/dict.ts +1 -0
  43. package/src/dts/global.d.ts +27 -0
  44. package/src/easing.ts +166 -0
  45. package/src/emitter.ts +117 -0
  46. package/src/enum.ts +171 -0
  47. package/src/env.ts +62 -0
  48. package/src/error.ts +31 -0
  49. package/src/exception.ts +68 -0
  50. package/src/fn.ts +197 -0
  51. package/src/index.ts +1 -0
  52. package/src/number.ts +236 -0
  53. package/src/object/each.ts +56 -0
  54. package/src/object/get-set.ts +273 -0
  55. package/src/object/is.ts +128 -0
  56. package/src/object/merge.ts +180 -0
  57. package/src/object/process.ts +80 -0
  58. package/src/object.ts +5 -0
  59. package/src/path.ts +188 -0
  60. package/src/promise.ts +111 -0
  61. package/src/qs.ts +119 -0
  62. package/src/regexp.ts +156 -0
  63. package/src/string.ts +146 -0
  64. package/src/time/from.ts +57 -0
  65. package/src/time/to.ts +106 -0
  66. package/src/time.ts +2 -0
  67. package/src/timer.ts +226 -0
  68. package/src/tree.ts +394 -0
  69. package/src/type.ts +197 -0
  70. package/src/types.ts +78 -0
  71. package/src/unique.ts +77 -0
  72. package/src/url.ts +93 -0
  73. package/src/version.ts +71 -0
  74. package/test/array.test.ts +332 -0
  75. package/test/async-real.test.ts +39 -0
  76. package/test/async.test.ts +375 -0
  77. package/test/base64.test.ts +32 -0
  78. package/test/cache.test.ts +83 -0
  79. package/test/color.test.ts +163 -0
  80. package/test/crypto.test.ts +34 -0
  81. package/test/date-tz.test.ts +206 -0
  82. package/test/date.test.ts +353 -0
  83. package/test/easing.test.ts +33 -0
  84. package/test/emitter.test.ts +71 -0
  85. package/test/enum.test.ts +113 -0
  86. package/test/env.test.ts +69 -0
  87. package/test/error.test.ts +58 -0
  88. package/test/exception.test.ts +43 -0
  89. package/test/fn.test.ts +263 -0
  90. package/test/helpers.ts +23 -0
  91. package/test/index.test.ts +6 -0
  92. package/test/number.test.ts +213 -0
  93. package/test/object.test.ts +309 -0
  94. package/test/path.test.ts +156 -0
  95. package/test/promise.test.ts +199 -0
  96. package/test/qs.test.ts +79 -0
  97. package/test/regexp.test.ts +97 -0
  98. package/test/string.test.ts +150 -0
  99. package/test/time.test.ts +214 -0
  100. package/test/timer.test.ts +114 -0
  101. package/test/tree.test.ts +348 -0
  102. package/test/type.test.ts +226 -0
  103. package/test/unique.test.ts +71 -0
  104. package/test/url.test.ts +136 -0
  105. package/test/version.test.ts +52 -0
  106. package/tsconfig.json +31 -0
  107. package/vite.config.mts +114 -0
@@ -0,0 +1,226 @@
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
+ });
@@ -0,0 +1,71 @@
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
+ });
@@ -0,0 +1,136 @@
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
+ });
@@ -0,0 +1,52 @@
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 ADDED
@@ -0,0 +1,31 @@
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
+ }
@@ -0,0 +1,114 @@
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
+ });