@taicode/common-base 3.7.4 → 3.7.7

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 (167) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +7 -8
  3. package/output/batching-buffer/batching-buffer.d.ts +0 -133
  4. package/output/batching-buffer/batching-buffer.d.ts.map +0 -1
  5. package/output/batching-buffer/batching-buffer.js +0 -264
  6. package/output/batching-buffer/batching-buffer.test.d.ts +0 -2
  7. package/output/batching-buffer/batching-buffer.test.d.ts.map +0 -1
  8. package/output/batching-buffer/batching-buffer.test.js +0 -358
  9. package/output/batching-buffer/index.d.ts +0 -3
  10. package/output/batching-buffer/index.d.ts.map +0 -1
  11. package/output/batching-buffer/index.js +0 -1
  12. package/output/catch/catch.d.ts +0 -46
  13. package/output/catch/catch.d.ts.map +0 -1
  14. package/output/catch/catch.js +0 -48
  15. package/output/catch/catch.test.d.ts +0 -2
  16. package/output/catch/catch.test.d.ts.map +0 -1
  17. package/output/catch/catch.test.js +0 -43
  18. package/output/catch/index.d.ts +0 -2
  19. package/output/catch/index.d.ts.map +0 -1
  20. package/output/catch/index.js +0 -1
  21. package/output/color/color.d.ts +0 -6
  22. package/output/color/color.d.ts.map +0 -1
  23. package/output/color/color.js +0 -56
  24. package/output/color/color.test.d.ts +0 -2
  25. package/output/color/color.test.d.ts.map +0 -1
  26. package/output/color/color.test.js +0 -110
  27. package/output/color/index.d.ts +0 -2
  28. package/output/color/index.d.ts.map +0 -1
  29. package/output/color/index.js +0 -1
  30. package/output/debounce/debounce.d.ts +0 -7
  31. package/output/debounce/debounce.d.ts.map +0 -1
  32. package/output/debounce/debounce.js +0 -36
  33. package/output/debounce/debounce.test.d.ts +0 -2
  34. package/output/debounce/debounce.test.d.ts.map +0 -1
  35. package/output/debounce/debounce.test.js +0 -135
  36. package/output/debounce/index.d.ts +0 -2
  37. package/output/debounce/index.d.ts.map +0 -1
  38. package/output/debounce/index.js +0 -1
  39. package/output/disposer/disposer.d.ts +0 -8
  40. package/output/disposer/disposer.d.ts.map +0 -1
  41. package/output/disposer/disposer.js +0 -21
  42. package/output/disposer/disposer.test.d.ts +0 -2
  43. package/output/disposer/disposer.test.d.ts.map +0 -1
  44. package/output/disposer/disposer.test.js +0 -216
  45. package/output/disposer/index.d.ts +0 -2
  46. package/output/disposer/index.d.ts.map +0 -1
  47. package/output/disposer/index.js +0 -1
  48. package/output/error/error.d.ts +0 -128
  49. package/output/error/error.d.ts.map +0 -1
  50. package/output/error/error.js +0 -141
  51. package/output/error/error.test.d.ts +0 -2
  52. package/output/error/error.test.d.ts.map +0 -1
  53. package/output/error/error.test.js +0 -420
  54. package/output/error/index.d.ts +0 -3
  55. package/output/error/index.d.ts.map +0 -1
  56. package/output/error/index.js +0 -1
  57. package/output/event-emitter/event-emitter.d.ts +0 -33
  58. package/output/event-emitter/event-emitter.d.ts.map +0 -1
  59. package/output/event-emitter/event-emitter.js +0 -66
  60. package/output/event-emitter/event-emitter.test.d.ts +0 -2
  61. package/output/event-emitter/event-emitter.test.d.ts.map +0 -1
  62. package/output/event-emitter/event-emitter.test.js +0 -177
  63. package/output/event-emitter/index.d.ts +0 -2
  64. package/output/event-emitter/index.d.ts.map +0 -1
  65. package/output/event-emitter/index.js +0 -1
  66. package/output/flow-queue/flow-queue.d.ts +0 -486
  67. package/output/flow-queue/flow-queue.d.ts.map +0 -1
  68. package/output/flow-queue/flow-queue.js +0 -654
  69. package/output/flow-queue/flow-queue.test.d.ts +0 -2
  70. package/output/flow-queue/flow-queue.test.d.ts.map +0 -1
  71. package/output/flow-queue/flow-queue.test.js +0 -1205
  72. package/output/flow-queue/index.d.ts +0 -3
  73. package/output/flow-queue/index.d.ts.map +0 -1
  74. package/output/flow-queue/index.js +0 -3
  75. package/output/index.d.ts +0 -18
  76. package/output/index.d.ts.map +0 -1
  77. package/output/index.js +0 -26
  78. package/output/logger/formatter.d.ts +0 -70
  79. package/output/logger/formatter.d.ts.map +0 -1
  80. package/output/logger/formatter.js +0 -206
  81. package/output/logger/formatter.test.d.ts +0 -2
  82. package/output/logger/formatter.test.d.ts.map +0 -1
  83. package/output/logger/formatter.test.js +0 -296
  84. package/output/logger/index.d.ts +0 -4
  85. package/output/logger/index.d.ts.map +0 -1
  86. package/output/logger/index.js +0 -3
  87. package/output/logger/logger.d.ts +0 -64
  88. package/output/logger/logger.d.ts.map +0 -1
  89. package/output/logger/logger.js +0 -179
  90. package/output/logger/logger.test.d.ts +0 -2
  91. package/output/logger/logger.test.d.ts.map +0 -1
  92. package/output/logger/logger.test.js +0 -299
  93. package/output/logger/transport.d.ts +0 -124
  94. package/output/logger/transport.d.ts.map +0 -1
  95. package/output/logger/transport.js +0 -153
  96. package/output/logger/transport.test.d.ts +0 -2
  97. package/output/logger/transport.test.d.ts.map +0 -1
  98. package/output/logger/transport.test.js +0 -309
  99. package/output/lru-cache/index.d.ts +0 -2
  100. package/output/lru-cache/index.d.ts.map +0 -1
  101. package/output/lru-cache/index.js +0 -1
  102. package/output/lru-cache/lru-cache.d.ts +0 -22
  103. package/output/lru-cache/lru-cache.d.ts.map +0 -1
  104. package/output/lru-cache/lru-cache.js +0 -147
  105. package/output/lru-cache/lru-cache.test.d.ts +0 -2
  106. package/output/lru-cache/lru-cache.test.d.ts.map +0 -1
  107. package/output/lru-cache/lru-cache.test.js +0 -239
  108. package/output/number/index.d.ts +0 -2
  109. package/output/number/index.d.ts.map +0 -1
  110. package/output/number/index.js +0 -1
  111. package/output/number/number.d.ts +0 -2
  112. package/output/number/number.d.ts.map +0 -1
  113. package/output/number/number.js +0 -23
  114. package/output/number/number.test.d.ts +0 -2
  115. package/output/number/number.test.d.ts.map +0 -1
  116. package/output/number/number.test.js +0 -50
  117. package/output/object/index.d.ts +0 -2
  118. package/output/object/index.d.ts.map +0 -1
  119. package/output/object/index.js +0 -1
  120. package/output/object/object.d.ts +0 -7
  121. package/output/object/object.d.ts.map +0 -1
  122. package/output/object/object.js +0 -27
  123. package/output/object/object.test.d.ts +0 -2
  124. package/output/object/object.test.d.ts.map +0 -1
  125. package/output/object/object.test.js +0 -42
  126. package/output/ring-cache/index.d.ts +0 -6
  127. package/output/ring-cache/index.d.ts.map +0 -1
  128. package/output/ring-cache/index.js +0 -5
  129. package/output/ring-cache/ring-cache.d.ts +0 -125
  130. package/output/ring-cache/ring-cache.d.ts.map +0 -1
  131. package/output/ring-cache/ring-cache.js +0 -197
  132. package/output/ring-cache/ring-cache.test.d.ts +0 -2
  133. package/output/ring-cache/ring-cache.test.d.ts.map +0 -1
  134. package/output/ring-cache/ring-cache.test.js +0 -196
  135. package/output/service/index.d.ts +0 -2
  136. package/output/service/index.d.ts.map +0 -1
  137. package/output/service/index.js +0 -1
  138. package/output/service/service.d.ts +0 -6
  139. package/output/service/service.d.ts.map +0 -1
  140. package/output/service/service.js +0 -3
  141. package/output/string/index.d.ts +0 -2
  142. package/output/string/index.d.ts.map +0 -1
  143. package/output/string/index.js +0 -1
  144. package/output/string/string.d.ts +0 -3
  145. package/output/string/string.d.ts.map +0 -1
  146. package/output/string/string.js +0 -9
  147. package/output/string/string.test.d.ts +0 -2
  148. package/output/string/string.test.d.ts.map +0 -1
  149. package/output/string/string.test.js +0 -77
  150. package/output/throttle/index.d.ts +0 -2
  151. package/output/throttle/index.d.ts.map +0 -1
  152. package/output/throttle/index.js +0 -1
  153. package/output/throttle/throttle.d.ts +0 -12
  154. package/output/throttle/throttle.d.ts.map +0 -1
  155. package/output/throttle/throttle.js +0 -55
  156. package/output/throttle/throttle.test.d.ts +0 -2
  157. package/output/throttle/throttle.test.d.ts.map +0 -1
  158. package/output/throttle/throttle.test.js +0 -177
  159. package/output/ttl-cache/index.d.ts +0 -2
  160. package/output/ttl-cache/index.d.ts.map +0 -1
  161. package/output/ttl-cache/index.js +0 -1
  162. package/output/ttl-cache/ttl-cache.d.ts +0 -148
  163. package/output/ttl-cache/ttl-cache.d.ts.map +0 -1
  164. package/output/ttl-cache/ttl-cache.js +0 -313
  165. package/output/ttl-cache/ttl-cache.test.d.ts +0 -2
  166. package/output/ttl-cache/ttl-cache.test.d.ts.map +0 -1
  167. package/output/ttl-cache/ttl-cache.test.js +0 -222
@@ -1,239 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { LruCache } from './lru-cache.js';
3
- describe('LruCache', () => {
4
- describe('构造函数', () => {
5
- it('应该创建默认容量为100的缓存', () => {
6
- const cache = new LruCache();
7
- expect(cache.capacity).toBe(100);
8
- expect(cache.size).toBe(0);
9
- });
10
- it('应该创建指定容量的缓存', () => {
11
- const cache = new LruCache(50);
12
- expect(cache.capacity).toBe(50);
13
- expect(cache.size).toBe(0);
14
- });
15
- it('应该在容量小于等于0时抛出错误', () => {
16
- expect(() => new LruCache(0)).toThrow('maxSize must be greater than 0');
17
- expect(() => new LruCache(-1)).toThrow('maxSize must be greater than 0');
18
- });
19
- });
20
- describe('基本操作', () => {
21
- it('应该能设置和获取值', () => {
22
- const cache = new LruCache(3);
23
- cache.set('key1', 'value1');
24
- expect(cache.get('key1')).toBe('value1');
25
- expect(cache.size).toBe(1);
26
- });
27
- it('应该在键不存在时返回undefined', () => {
28
- const cache = new LruCache(3);
29
- expect(cache.get('nonexistent')).toBeUndefined();
30
- });
31
- it('应该正确检查键是否存在', () => {
32
- const cache = new LruCache(3);
33
- expect(cache.has('key1')).toBe(false);
34
- cache.set('key1', 'value1');
35
- expect(cache.has('key1')).toBe(true);
36
- });
37
- it('应该能更新现有键的值', () => {
38
- const cache = new LruCache(3);
39
- cache.set('key1', 'value1');
40
- cache.set('key1', 'updated_value1');
41
- expect(cache.get('key1')).toBe('updated_value1');
42
- expect(cache.size).toBe(1);
43
- });
44
- it('应该能删除键', () => {
45
- const cache = new LruCache(3);
46
- cache.set('key1', 'value1');
47
- expect(cache.delete('key1')).toBe(true);
48
- expect(cache.has('key1')).toBe(false);
49
- expect(cache.size).toBe(0);
50
- });
51
- it('应该在删除不存在的键时返回false', () => {
52
- const cache = new LruCache(3);
53
- expect(cache.delete('nonexistent')).toBe(false);
54
- });
55
- it('应该能清空缓存', () => {
56
- const cache = new LruCache(3);
57
- cache.set('key1', 'value1');
58
- cache.set('key2', 'value2');
59
- cache.clear();
60
- expect(cache.size).toBe(0);
61
- expect(cache.has('key1')).toBe(false);
62
- expect(cache.has('key2')).toBe(false);
63
- });
64
- });
65
- describe('LRU 行为', () => {
66
- it('应该在达到容量限制时移除最久未使用的项', () => {
67
- const cache = new LruCache(2);
68
- cache.set('key1', 'value1');
69
- cache.set('key2', 'value2');
70
- cache.set('key3', 'value3'); // 这应该移除 key1
71
- expect(cache.has('key1')).toBe(false);
72
- expect(cache.has('key2')).toBe(true);
73
- expect(cache.has('key3')).toBe(true);
74
- expect(cache.size).toBe(2);
75
- });
76
- it('应该在访问时更新使用顺序', () => {
77
- const cache = new LruCache(2);
78
- cache.set('key1', 'value1');
79
- cache.set('key2', 'value2');
80
- cache.get('key1'); // 使 key1 成为最近使用的
81
- cache.set('key3', 'value3'); // 这应该移除 key2,而不是 key1
82
- expect(cache.has('key1')).toBe(true);
83
- expect(cache.has('key2')).toBe(false);
84
- expect(cache.has('key3')).toBe(true);
85
- });
86
- it('应该在更新现有键时保持其为最近使用', () => {
87
- const cache = new LruCache(2);
88
- cache.set('key1', 'value1');
89
- cache.set('key2', 'value2');
90
- cache.set('key1', 'updated_value1'); // 更新 key1
91
- cache.set('key3', 'value3'); // 这应该移除 key2
92
- expect(cache.has('key1')).toBe(true);
93
- expect(cache.get('key1')).toBe('updated_value1');
94
- expect(cache.has('key2')).toBe(false);
95
- expect(cache.has('key3')).toBe(true);
96
- });
97
- });
98
- describe('遍历方法', () => {
99
- it('应该返回正确的键列表(按使用顺序)', () => {
100
- const cache = new LruCache(3);
101
- cache.set('key1', 'value1');
102
- cache.set('key2', 'value2');
103
- cache.set('key3', 'value3');
104
- cache.get('key1'); // 使 key1 成为最近使用的
105
- const keys = cache.keys();
106
- expect(keys).toEqual(['key1', 'key3', 'key2']);
107
- });
108
- it('应该返回正确的值列表(按使用顺序)', () => {
109
- const cache = new LruCache(3);
110
- cache.set('key1', 'value1');
111
- cache.set('key2', 'value2');
112
- cache.set('key3', 'value3');
113
- cache.get('key1'); // 使 key1 成为最近使用的
114
- const values = cache.values();
115
- expect(values).toEqual(['value1', 'value3', 'value2']);
116
- });
117
- it('应该返回正确的键值对列表(按使用顺序)', () => {
118
- const cache = new LruCache(3);
119
- cache.set('key1', 'value1');
120
- cache.set('key2', 'value2');
121
- cache.set('key3', 'value3');
122
- cache.get('key1'); // 使 key1 成为最近使用的
123
- const entries = cache.entries();
124
- expect(entries).toEqual([
125
- ['key1', 'value1'],
126
- ['key3', 'value3'],
127
- ['key2', 'value2']
128
- ]);
129
- });
130
- it('应该在空缓存时返回空数组', () => {
131
- const cache = new LruCache(3);
132
- expect(cache.keys()).toEqual([]);
133
- expect(cache.values()).toEqual([]);
134
- expect(cache.entries()).toEqual([]);
135
- });
136
- });
137
- describe('边界情况', () => {
138
- it('应该处理容量为1的缓存', () => {
139
- const cache = new LruCache(1);
140
- cache.set('key1', 'value1');
141
- expect(cache.get('key1')).toBe('value1');
142
- cache.set('key2', 'value2');
143
- expect(cache.has('key1')).toBe(false);
144
- expect(cache.get('key2')).toBe('value2');
145
- expect(cache.size).toBe(1);
146
- });
147
- it('应该处理大量的操作', () => {
148
- const cache = new LruCache(100);
149
- // 添加200个项目
150
- for (let i = 0; i < 200; i++) {
151
- cache.set(`key${i}`, i);
152
- }
153
- expect(cache.size).toBe(100);
154
- // 前100个应该被移除
155
- for (let i = 0; i < 100; i++) {
156
- expect(cache.has(`key${i}`)).toBe(false);
157
- }
158
- // 后100个应该存在
159
- for (let i = 100; i < 200; i++) {
160
- expect(cache.has(`key${i}`)).toBe(true);
161
- expect(cache.get(`key${i}`)).toBe(i);
162
- }
163
- });
164
- it('应该处理复杂的对象类型', () => {
165
- const cache = new LruCache(3);
166
- const obj1 = { id: 1, name: 'test1', data: { count: 10 } };
167
- const obj2 = { id: 2, name: 'test2', data: { count: 20 } };
168
- cache.set('obj1', obj1);
169
- cache.set('obj2', obj2);
170
- expect(cache.get('obj1')).toEqual(obj1);
171
- expect(cache.get('obj2')).toEqual(obj2);
172
- });
173
- it('应该处理null和undefined值', () => {
174
- const cache = new LruCache(3);
175
- cache.set('null', null);
176
- cache.set('undefined', undefined);
177
- expect(cache.get('null')).toBeNull();
178
- expect(cache.get('undefined')).toBeUndefined();
179
- expect(cache.has('null')).toBe(true);
180
- expect(cache.has('undefined')).toBe(true);
181
- });
182
- });
183
- describe('性能和内存', () => {
184
- it('应该在删除后正确管理内存', () => {
185
- const cache = new LruCache(3);
186
- cache.set('key1', 'value1');
187
- cache.set('key2', 'value2');
188
- cache.set('key3', 'value3');
189
- expect(cache.size).toBe(3);
190
- cache.delete('key2');
191
- expect(cache.size).toBe(2);
192
- expect(cache.keys()).toEqual(['key3', 'key1']);
193
- });
194
- it('应该正确处理连续的相同键设置', () => {
195
- const cache = new LruCache(2);
196
- cache.set('key1', 'value1');
197
- cache.set('key1', 'value1_updated');
198
- cache.set('key1', 'value1_final');
199
- expect(cache.size).toBe(1);
200
- expect(cache.get('key1')).toBe('value1_final');
201
- });
202
- });
203
- describe('实际使用场景', () => {
204
- it('应该能用作函数结果缓存', () => {
205
- const cache = new LruCache(3);
206
- let computeCount = 0;
207
- function expensiveCompute(n) {
208
- const cacheKey = `compute_${n}`;
209
- if (cache.has(cacheKey)) {
210
- return cache.get(cacheKey);
211
- }
212
- computeCount++;
213
- const result = n * n; // 模拟昂贵的计算
214
- cache.set(cacheKey, result);
215
- return result;
216
- }
217
- // 第一次计算
218
- expect(expensiveCompute(5)).toBe(25);
219
- expect(computeCount).toBe(1);
220
- // 缓存命中
221
- expect(expensiveCompute(5)).toBe(25);
222
- expect(computeCount).toBe(1);
223
- // 新的计算
224
- expect(expensiveCompute(6)).toBe(36);
225
- expect(computeCount).toBe(2);
226
- });
227
- it('应该能用作API响应缓存', () => {
228
- const cache = new LruCache(10);
229
- const mockApiResponse = {
230
- data: [{ id: 1, name: 'test' }],
231
- timestamp: Date.now()
232
- };
233
- cache.set('/api/users', mockApiResponse);
234
- const cachedResponse = cache.get('/api/users');
235
- expect(cachedResponse).toEqual(mockApiResponse);
236
- expect(cachedResponse?.data).toHaveLength(1);
237
- });
238
- });
239
- });
@@ -1,2 +0,0 @@
1
- export * from './number.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/number/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -1 +0,0 @@
1
- export * from './number.js';
@@ -1,2 +0,0 @@
1
- export declare function bigintToNumber(value: bigint | null): number;
2
- //# sourceMappingURL=number.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../source/number/number.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAwB3D"}
@@ -1,23 +0,0 @@
1
- export function bigintToNumber(value) {
2
- if (value === null)
3
- return 0;
4
- // JavaScript 的 number 类型最大值
5
- const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER; // 2^53 - 1
6
- const MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER; // -(2^53 - 1)
7
- try {
8
- // 检查输入是否为 bigint
9
- if (typeof value !== 'bigint') {
10
- throw new TypeError('Input must be a bigint');
11
- }
12
- // 检查是否溢出
13
- if (value > BigInt(MAX_SAFE_INTEGER) || value < BigInt(MIN_SAFE_INTEGER)) {
14
- return MAX_SAFE_INTEGER; // 溢出,返回 NaN
15
- }
16
- // 将 bigint 转换为 number
17
- return Number(value);
18
- }
19
- catch {
20
- // 捕获任何错误并返回 NaN
21
- return 0;
22
- }
23
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=number.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"number.test.d.ts","sourceRoot":"","sources":["../../source/number/number.test.ts"],"names":[],"mappings":""}
@@ -1,50 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { bigintToNumber } from './number.js';
3
- describe('bigintToNumber 函数', () => {
4
- it('应该将小的 bigint 转换为 number', () => {
5
- const result = bigintToNumber(123n);
6
- expect(result).toBe(123);
7
- });
8
- it('应该将负数 bigint 转换为 number', () => {
9
- const result = bigintToNumber(-456n);
10
- expect(result).toBe(-456);
11
- });
12
- it('应该将零 bigint 转换为 number', () => {
13
- const result = bigintToNumber(0n);
14
- expect(result).toBe(0);
15
- });
16
- it('应该为 null 输入返回 0', () => {
17
- const result = bigintToNumber(null);
18
- expect(result).toBe(0);
19
- });
20
- it('应该处理 MAX_SAFE_INTEGER 的 bigint', () => {
21
- const maxSafe = BigInt(Number.MAX_SAFE_INTEGER);
22
- const result = bigintToNumber(maxSafe);
23
- expect(result).toBe(Number.MAX_SAFE_INTEGER);
24
- });
25
- it('应该处理 MIN_SAFE_INTEGER 的 bigint', () => {
26
- const minSafe = BigInt(Number.MIN_SAFE_INTEGER);
27
- const result = bigintToNumber(minSafe);
28
- expect(result).toBe(Number.MIN_SAFE_INTEGER);
29
- });
30
- it('应该为 bigint 溢出(正数)返回 MAX_SAFE_INTEGER', () => {
31
- const tooBig = BigInt(Number.MAX_SAFE_INTEGER) + 1n;
32
- const result = bigintToNumber(tooBig);
33
- expect(result).toBe(Number.MAX_SAFE_INTEGER);
34
- });
35
- it('应该为 bigint 溢出(负数)返回 MAX_SAFE_INTEGER', () => {
36
- const tooSmall = BigInt(Number.MIN_SAFE_INTEGER) - 1n;
37
- const result = bigintToNumber(tooSmall);
38
- expect(result).toBe(Number.MAX_SAFE_INTEGER);
39
- });
40
- it('应该处理非常大的 bigint', () => {
41
- const veryLarge = 999999999999999999999n;
42
- const result = bigintToNumber(veryLarge);
43
- expect(result).toBe(Number.MAX_SAFE_INTEGER);
44
- });
45
- it('应该处理从 number 创建的 bigint', () => {
46
- const bigintFromNumber = BigInt(42);
47
- const result = bigintToNumber(bigintFromNumber);
48
- expect(result).toBe(42);
49
- });
50
- });
@@ -1,2 +0,0 @@
1
- export * from './object.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/object/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA"}
@@ -1 +0,0 @@
1
- export * from './object.js';
@@ -1,7 +0,0 @@
1
- /**
2
- * 递归合并对象,只针对对象类型的属性进行合并,其他类型后者覆盖前者
3
- */
4
- export declare function objectMerge<T extends object>(target: T, ...rest: Partial<T>[]): T;
5
- export declare function ObjectKeys<T extends object>(obj: T): (keyof T)[];
6
- export declare function ObjectValues<T extends object>(obj: T): T[keyof T][];
7
- //# sourceMappingURL=object.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../source/object/object.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAiBjF;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAEhE;AAED,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAEnE"}
@@ -1,27 +0,0 @@
1
- /**
2
- * 递归合并对象,只针对对象类型的属性进行合并,其他类型后者覆盖前者
3
- */
4
- export function objectMerge(target, ...rest) {
5
- for (const source of rest) {
6
- for (const key in source) {
7
- if (source.hasOwnProperty(key)) {
8
- if (typeof source[key] === 'object' && source[key] !== null && !Array.isArray(source[key])) {
9
- if (!target.hasOwnProperty(key)) {
10
- target[key] = {};
11
- }
12
- objectMerge(target[key], source[key]);
13
- }
14
- else {
15
- target[key] = source[key];
16
- }
17
- }
18
- }
19
- }
20
- return target;
21
- }
22
- export function ObjectKeys(obj) {
23
- return Object.keys(obj);
24
- }
25
- export function ObjectValues(obj) {
26
- return Object.values(obj);
27
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=object.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"object.test.d.ts","sourceRoot":"","sources":["../../source/object/object.test.ts"],"names":[],"mappings":""}
@@ -1,42 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { objectMerge } from './object.js';
3
- describe('merge 函数', () => {
4
- it('应该合并两个简单对象', () => {
5
- const target = { a: 1 };
6
- const source = { b: 2 };
7
- const result = objectMerge(target, source);
8
- expect(result).toEqual({ a: 1, b: 2 });
9
- });
10
- it('应该合并嵌套对象', () => {
11
- const target = { a: 1, b: { c: 2 } };
12
- const source = { b: { d: 3 }, e: 4 };
13
- const result = objectMerge(target, source);
14
- expect(result).toEqual({ a: 1, b: { c: 2, d: 3 }, e: 4 });
15
- });
16
- it('应该合并多个对象', () => {
17
- const target = { a: 1 };
18
- const source1 = { b: 2 };
19
- const source2 = { c: 3 };
20
- const result = objectMerge(target, source1, source2);
21
- expect(result).toEqual({ a: 1, b: 2, c: 3 });
22
- });
23
- it('应该覆盖现有属性', () => {
24
- const target = { a: 1, b: 2 };
25
- const source = { b: 3, c: 4 };
26
- const result = objectMerge(target, source);
27
- expect(result).toEqual({ a: 1, b: 3, c: 4 });
28
- });
29
- it('应该处理 null 和数组值', () => {
30
- const target = { a: 1, b: null };
31
- const source = { b: [1, 2, 3], c: 4 };
32
- const result = objectMerge(target, source);
33
- expect(result).toEqual({ a: 1, b: [1, 2, 3], c: 4 });
34
- });
35
- it('应该不改变原始目标对象', () => {
36
- const target = { a: 1 };
37
- const source = { b: 2 };
38
- const result = objectMerge(target, source);
39
- expect(result).toEqual({ a: 1, b: 2 });
40
- expect(source).toEqual({ b: 2 }); // Target should remain unchanged
41
- });
42
- });
@@ -1,6 +0,0 @@
1
- /**
2
- * Ring Cache 模块
3
- * 专门用于日志场景的FIFO环形缓存
4
- */
5
- export * from './ring-cache.js';
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../source/ring-cache/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,cAAc,iBAAiB,CAAA"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Ring Cache 模块
3
- * 专门用于日志场景的FIFO环形缓存
4
- */
5
- export * from './ring-cache.js';
@@ -1,125 +0,0 @@
1
- /**
2
- * 环形缓存(Ring Cache)实现
3
- * 专门用于日志场景的FIFO(先进先出)缓存
4
- *
5
- * 特点:
6
- * - FIFO行为:新数据总是添加到尾部,当容量满时从头部移除旧数据
7
- * - 固定容量:避免内存无限增长
8
- * - 高效操作:O(1)的添加和访问操作
9
- * - 适用场景:日志记录、事件历史、时间序列数据等
10
- */
11
- /**
12
- * 环形缓存配置选项
13
- */
14
- export interface RingCacheOptions {
15
- /** 缓存容量,默认为1000 */
16
- capacity?: number;
17
- }
18
- /**
19
- * 环形缓存条目
20
- */
21
- export interface RingCacheEntry<T> {
22
- /** 数据 */
23
- data: T;
24
- /** 添加时间戳 */
25
- timestamp: Date;
26
- /** 条目ID */
27
- id: string;
28
- }
29
- /**
30
- * 环形缓存统计信息
31
- */
32
- export interface RingCacheStats {
33
- /** 当前条目数量 */
34
- size: number;
35
- /** 缓存容量 */
36
- capacity: number;
37
- /** 是否已满 */
38
- isFull: boolean;
39
- /** 最旧条目的时间戳 */
40
- oldestTimestamp?: Date;
41
- /** 最新条目的时间戳 */
42
- newestTimestamp?: Date;
43
- /** 总共添加的条目数(包括已被覆盖的) */
44
- totalAdded: number;
45
- }
46
- /**
47
- * 环形缓存实现
48
- * 使用固定大小的数组实现FIFO行为的环形缓存
49
- */
50
- export declare class RingCache<T> {
51
- private buffer;
52
- private head;
53
- private tail;
54
- private size;
55
- private capacity;
56
- private totalAdded;
57
- private nextId;
58
- constructor(options?: RingCacheOptions);
59
- /**
60
- * 添加新条目到缓存
61
- * 如果缓存已满,将覆盖最旧的条目
62
- */
63
- add(data: T): RingCacheEntry<T>;
64
- /**
65
- * 获取所有缓存条目(按添加顺序)
66
- */
67
- getAll(): RingCacheEntry<T>[];
68
- /**
69
- * 获取最近的N个条目
70
- */
71
- getRecent(count: number): RingCacheEntry<T>[];
72
- /**
73
- * 获取最旧的N个条目
74
- */
75
- getOldest(count: number): RingCacheEntry<T>[];
76
- /**
77
- * 根据时间范围获取条目
78
- */
79
- getByTimeRange(start: Date, end: Date): RingCacheEntry<T>[];
80
- /**
81
- * 搜索满足条件的条目
82
- */
83
- search(predicate: (entry: RingCacheEntry<T>) => boolean): RingCacheEntry<T>[];
84
- /**
85
- * 获取缓存统计信息
86
- */
87
- getStats(): RingCacheStats;
88
- /**
89
- * 检查缓存是否为空
90
- */
91
- isEmpty(): boolean;
92
- /**
93
- * 检查缓存是否已满
94
- */
95
- isFull(): boolean;
96
- /**
97
- * 获取当前缓存大小
98
- */
99
- getSize(): number;
100
- /**
101
- * 获取缓存容量
102
- */
103
- getCapacity(): number;
104
- /**
105
- * 清空缓存
106
- */
107
- clear(): void;
108
- /**
109
- * 导出为数组格式
110
- */
111
- toArray(): T[];
112
- /**
113
- * 导出为JSON格式
114
- */
115
- toJSON(): string;
116
- /**
117
- * 生成唯一ID
118
- */
119
- private generateId;
120
- /**
121
- * 创建迭代器,支持for...of语法
122
- */
123
- [Symbol.iterator](): Iterator<RingCacheEntry<T>>;
124
- }
125
- //# sourceMappingURL=ring-cache.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ring-cache.d.ts","sourceRoot":"","sources":["../../source/ring-cache/ring-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,mBAAmB;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,SAAS;IACT,IAAI,EAAE,CAAC,CAAA;IACP,YAAY;IACZ,SAAS,EAAE,IAAI,CAAA;IACf,WAAW;IACX,EAAE,EAAE,MAAM,CAAA;CACX;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,aAAa;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW;IACX,MAAM,EAAE,OAAO,CAAA;IACf,eAAe;IACf,eAAe,CAAC,EAAE,IAAI,CAAA;IACtB,eAAe;IACf,eAAe,CAAC,EAAE,IAAI,CAAA;IACtB,wBAAwB;IACxB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,qBAAa,SAAS,CAAC,CAAC;IACtB,OAAO,CAAC,MAAM,CAAmC;IACjD,OAAO,CAAC,IAAI,CAAY;IACxB,OAAO,CAAC,IAAI,CAAY;IACxB,OAAO,CAAC,IAAI,CAAY;IACxB,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,UAAU,CAAY;IAC9B,OAAO,CAAC,MAAM,CAAY;gBAEd,OAAO,GAAE,gBAAqB;IAQ1C;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC;IAqB/B;;OAEG;IACH,MAAM,IAAI,cAAc,CAAC,CAAC,CAAC,EAAE;IAkB7B;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE;IAoB7C;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE;IAmB7C;;OAEG;IACH,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE;IAM3D;;OAEG;IACH,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,EAAE;IAI7E;;OAEG;IACH,QAAQ,IAAI,cAAc;IAa1B;;OAEG;IACH,OAAO,IAAI,OAAO;IAIlB;;OAEG;IACH,MAAM,IAAI,OAAO;IAIjB;;OAEG;IACH,OAAO,IAAI,MAAM;IAIjB;;OAEG;IACH,WAAW,IAAI,MAAM;IAIrB;;OAEG;IACH,KAAK,IAAI,IAAI;IASb;;OAEG;IACH,OAAO,IAAI,CAAC,EAAE;IAId;;OAEG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACH,OAAO,CAAC,UAAU;IAIlB;;OAEG;IACF,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;CASlD"}