@omnitron-dev/cuid 0.4.4 → 0.4.6
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.
- package/LICENSE +1 -1
- package/README.md +9 -981
- package/dist/index.js +121 -58
- package/dist/index.js.map +1 -1
- package/package.json +17 -16
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,999 +1,27 @@
|
|
|
1
|
-
# @omnitron-dev/
|
|
1
|
+
# @omnitron-dev/cuid
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
[](https://www.typescriptlang.org/)
|
|
6
|
-
[](https://nodejs.org)
|
|
7
|
-
[](https://bun.sh)
|
|
3
|
+
> Collision-resistant unique ID generation
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Table of Contents
|
|
12
|
-
|
|
13
|
-
- [Features](#features)
|
|
14
|
-
- [Installation](#installation)
|
|
15
|
-
- [Runtime Compatibility](#runtime-compatibility)
|
|
16
|
-
- [Quick Start](#quick-start)
|
|
17
|
-
- [Core Usage](#core-usage)
|
|
18
|
-
- [Primitives](#primitives)
|
|
19
|
-
- [Type Predicates](#type-predicates)
|
|
20
|
-
- [Promise Utilities](#promise-utilities)
|
|
21
|
-
- [Object Utilities](#object-utilities)
|
|
22
|
-
- [Data Structures](#data-structures)
|
|
23
|
-
- [API Reference](#api-reference)
|
|
24
|
-
- [Advanced Features](#advanced-features)
|
|
25
|
-
- [TypeScript Support](#typescript-support)
|
|
26
|
-
- [Performance](#performance)
|
|
27
|
-
- [Best Practices](#best-practices)
|
|
28
|
-
- [Contributing](#contributing)
|
|
29
|
-
- [License](#license)
|
|
30
|
-
|
|
31
|
-
## Features
|
|
32
|
-
|
|
33
|
-
- 🎯 **Type-Safe** - Full TypeScript support with proper type inference
|
|
34
|
-
- 📦 **Minimal Dependencies** - Only `@noble/hashes` for cryptographic operations
|
|
35
|
-
- 🌳 **Tree-Shakeable** - Import only what you need
|
|
36
|
-
- ✅ **Comprehensive** - Wide range of utility functions
|
|
37
|
-
- 🚀 **Optimized** - Performance-focused implementations
|
|
38
|
-
- 🌐 **Cross-Runtime** - Works in Node.js and Bun
|
|
39
|
-
- 🔍 **Well-Tested** - Extensive test coverage
|
|
40
|
-
- 📚 **Well-Documented** - Clear examples and API documentation
|
|
5
|
+
Part of the [Omni](../../README.md) monorepo — Fullstack Type-Safe RPC Framework.
|
|
41
6
|
|
|
42
7
|
## Installation
|
|
43
8
|
|
|
44
9
|
```bash
|
|
45
|
-
|
|
46
|
-
# or
|
|
47
|
-
yarn add @omnitron-dev/common
|
|
48
|
-
# or
|
|
49
|
-
pnpm add @omnitron-dev/common
|
|
50
|
-
# or (for Bun)
|
|
51
|
-
bun add @omnitron-dev/common
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Runtime Compatibility
|
|
55
|
-
|
|
56
|
-
This package is fully compatible with both **Node.js** and **Bun** runtimes.
|
|
57
|
-
|
|
58
|
-
### Running Tests
|
|
59
|
-
|
|
60
|
-
```bash
|
|
61
|
-
# Node.js
|
|
62
|
-
yarn test:node
|
|
63
|
-
|
|
64
|
-
# Bun
|
|
65
|
-
yarn test:bun
|
|
66
|
-
|
|
67
|
-
# Both runtimes
|
|
68
|
-
yarn test:all
|
|
10
|
+
pnpm add @omnitron-dev/cuid
|
|
69
11
|
```
|
|
70
12
|
|
|
71
|
-
|
|
13
|
+
## Overview
|
|
72
14
|
|
|
73
|
-
|
|
74
|
-
- **Promise tests**: Bun handles promise rejections slightly differently than Jest, but all functionality works identically.
|
|
75
|
-
- **No runtime-specific APIs**: The package doesn't use any Node.js or Bun-specific APIs, ensuring complete compatibility.
|
|
76
|
-
|
|
77
|
-
### Build Output
|
|
78
|
-
|
|
79
|
-
The package provides both CommonJS and ESM builds:
|
|
80
|
-
- CommonJS: `dist/index.js`
|
|
81
|
-
- ESM: `dist/esm/index.js`
|
|
82
|
-
- TypeScript definitions included
|
|
15
|
+
A fast, collision-resistant unique identifier generator. Produces URL-safe, monotonically sortable IDs suitable for distributed systems where coordination-free ID generation is required.
|
|
83
16
|
|
|
84
17
|
## Quick Start
|
|
85
18
|
|
|
86
19
|
```typescript
|
|
87
|
-
import {
|
|
88
|
-
|
|
89
|
-
// Use type predicates
|
|
90
|
-
if (isString(value)) {
|
|
91
|
-
console.log(value.toUpperCase());
|
|
92
|
-
}
|
|
20
|
+
import { cuid } from '@omnitron-dev/cuid';
|
|
93
21
|
|
|
94
|
-
//
|
|
95
|
-
await delay(1000); // Wait 1 second
|
|
96
|
-
|
|
97
|
-
// Use object utilities
|
|
98
|
-
const user = { id: 1, name: 'John', password: 'secret' };
|
|
99
|
-
const publicUser = omit(user, 'password'); // { id: 1, name: 'John' }
|
|
100
|
-
|
|
101
|
-
// Retry failed operations
|
|
102
|
-
const data = await retry(
|
|
103
|
-
async () => fetch('/api/data'),
|
|
104
|
-
{ max: 3, backoffBase: 1000 }
|
|
105
|
-
);
|
|
22
|
+
const id = cuid(); // e.g. "clh3k7v0a0000..."
|
|
106
23
|
```
|
|
107
24
|
|
|
108
|
-
## Core Usage
|
|
109
|
-
|
|
110
|
-
### Primitives
|
|
111
|
-
|
|
112
|
-
Basic utility functions for common operations.
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
import { noop, identity, truly, falsely, arrify } from '@omnitron-dev/common';
|
|
116
|
-
|
|
117
|
-
// noop - A function that does nothing (useful for default callbacks)
|
|
118
|
-
button.onClick = noop;
|
|
119
|
-
setInterval(noop, 1000); // Placeholder timer
|
|
120
|
-
|
|
121
|
-
// identity - Returns the input value unchanged
|
|
122
|
-
const result = [1, null, 2, undefined, 3].map(identity).filter(Boolean);
|
|
123
|
-
// [1, 2, 3]
|
|
124
|
-
|
|
125
|
-
// truly - Always returns true (useful for filters and tests)
|
|
126
|
-
const activeItems = items.filter(process.env.SKIP_FILTER ? truly : isActive);
|
|
127
|
-
|
|
128
|
-
// falsely - Always returns false
|
|
129
|
-
const disabled = permissions.checkAccess || falsely;
|
|
130
|
-
|
|
131
|
-
// arrify - Converts any value to an array
|
|
132
|
-
arrify(null); // => []
|
|
133
|
-
arrify(undefined); // => []
|
|
134
|
-
arrify(1); // => [1]
|
|
135
|
-
arrify([1, 2, 3]); // => [1, 2, 3] (returns same array)
|
|
136
|
-
arrify('hello'); // => ['hello']
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### Type Predicates
|
|
140
|
-
|
|
141
|
-
Comprehensive type checking and validation functions.
|
|
142
|
-
|
|
143
|
-
```typescript
|
|
144
|
-
import {
|
|
145
|
-
isString, isNumber, isBoolean, isSymbol, isBigInt,
|
|
146
|
-
isArray, isObject, isFunction, isPromise, isAsyncFunction,
|
|
147
|
-
isNull, isUndefined, isNil, isExist,
|
|
148
|
-
isDate, isRegexp, isError, isMap, isSet,
|
|
149
|
-
isPlainObject, isPrimitive, isBuffer,
|
|
150
|
-
isEmptyString, isEmptyObject,
|
|
151
|
-
isNumeral, isNumeralInteger, isNumeralBigInt,
|
|
152
|
-
isFinite, isInfinite, isInteger, isSafeInteger,
|
|
153
|
-
isFloat, isOdd, isEven, isNegativeZero,
|
|
154
|
-
isSubstring, isPrefix, isSuffix,
|
|
155
|
-
isAsyncGenerator, isClass, isNan,
|
|
156
|
-
isPropertyOwned, isPropertyDefined,
|
|
157
|
-
getTag, getTagSimple
|
|
158
|
-
} from '@omnitron-dev/common';
|
|
159
|
-
|
|
160
|
-
// Basic type checks with type narrowing
|
|
161
|
-
function processValue(value: unknown) {
|
|
162
|
-
if (isString(value)) {
|
|
163
|
-
// TypeScript knows value is string here
|
|
164
|
-
return value.toLowerCase();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (isNumber(value)) {
|
|
168
|
-
// TypeScript knows value is number here
|
|
169
|
-
return value.toFixed(2);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (isArray(value)) {
|
|
173
|
-
// TypeScript knows value is array here
|
|
174
|
-
return value.length;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Advanced type checks
|
|
179
|
-
const data = { name: 'John', age: 30 };
|
|
180
|
-
isPlainObject(data); // true (plain object)
|
|
181
|
-
isPlainObject(new Date()); // false (class instance)
|
|
182
|
-
|
|
183
|
-
isPrimitive(42); // true
|
|
184
|
-
isPrimitive('hello'); // true
|
|
185
|
-
isPrimitive({}); // false
|
|
186
|
-
|
|
187
|
-
// Nil checks
|
|
188
|
-
isNil(null); // true
|
|
189
|
-
isNil(undefined); // true
|
|
190
|
-
isNil(''); // false
|
|
191
|
-
isExist(''); // true (not null/undefined)
|
|
192
|
-
|
|
193
|
-
// Empty checks
|
|
194
|
-
isEmptyString(' '); // true (whitespace only)
|
|
195
|
-
isEmptyObject({}); // true
|
|
196
|
-
isEmptyObject({ a: 1 }); // false
|
|
197
|
-
|
|
198
|
-
// Numeric checks
|
|
199
|
-
isNumeral('42'); // true
|
|
200
|
-
isNumeral('42.5'); // true
|
|
201
|
-
isNumeral('abc'); // false
|
|
202
|
-
isNumeralInteger('42'); // true
|
|
203
|
-
isNumeralInteger('42.5'); // false
|
|
204
|
-
isNumeralBigInt('123n'); // true
|
|
205
|
-
|
|
206
|
-
// Number properties
|
|
207
|
-
isOdd(3); // true
|
|
208
|
-
isEven(4); // true
|
|
209
|
-
isFloat(3.14); // true
|
|
210
|
-
isNegativeZero(-0); // true
|
|
211
|
-
|
|
212
|
-
// String utilities
|
|
213
|
-
isSubstring('world', 'hello world'); // true
|
|
214
|
-
isPrefix('hello', 'hello world'); // true
|
|
215
|
-
isSuffix('world', 'hello world'); // true
|
|
216
|
-
isSubstring('foo', 'hello world'); // false
|
|
217
|
-
|
|
218
|
-
// Advanced checks
|
|
219
|
-
isAsyncFunction(async () => {}); // true
|
|
220
|
-
isAsyncGenerator(async function* () {}()); // true
|
|
221
|
-
isClass(class MyClass {}); // true
|
|
222
|
-
|
|
223
|
-
// Property checks
|
|
224
|
-
const obj = { a: 1 };
|
|
225
|
-
isPropertyOwned(obj, 'a'); // true
|
|
226
|
-
isPropertyOwned(obj, 'toString'); // false (inherited)
|
|
227
|
-
isPropertyDefined(obj, 'a'); // true
|
|
228
|
-
isPropertyDefined(obj, 'toString'); // true (includes inherited)
|
|
229
|
-
|
|
230
|
-
// Platform checks
|
|
231
|
-
import { isWindows, linux, darwin, freebsd, openbsd, sunos, aix, isNodejs } from '@omnitron-dev/common';
|
|
232
|
-
|
|
233
|
-
if (isWindows) {
|
|
234
|
-
// Windows-specific code
|
|
235
|
-
}
|
|
236
|
-
if (darwin) {
|
|
237
|
-
// macOS-specific code
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### Promise Utilities
|
|
242
|
-
|
|
243
|
-
Advanced promise handling and control flow utilities.
|
|
244
|
-
|
|
245
|
-
```typescript
|
|
246
|
-
import {
|
|
247
|
-
defer, delay, timeout, retry, props,
|
|
248
|
-
promisify, promisifyAll, callbackify, nodeify,
|
|
249
|
-
universalify, universalifyFromPromise,
|
|
250
|
-
finally as finallyUtil, try as tryUtil
|
|
251
|
-
} from '@omnitron-dev/common';
|
|
252
|
-
|
|
253
|
-
// defer - Create a deferred promise
|
|
254
|
-
const deferred = defer<string>();
|
|
255
|
-
|
|
256
|
-
// Some async operation
|
|
257
|
-
setTimeout(() => {
|
|
258
|
-
deferred.resolve('Success!');
|
|
259
|
-
}, 1000);
|
|
260
|
-
|
|
261
|
-
const result = await deferred.promise; // 'Success!'
|
|
262
|
-
|
|
263
|
-
// delay - Promise-based setTimeout
|
|
264
|
-
console.log('Starting...');
|
|
265
|
-
await delay(2000);
|
|
266
|
-
console.log('2 seconds later');
|
|
267
|
-
|
|
268
|
-
// With value and unref option
|
|
269
|
-
const delayedValue = await delay(1000, 'Hello', { unref: true });
|
|
270
|
-
console.log(delayedValue); // 'Hello' (after 1 second)
|
|
271
|
-
|
|
272
|
-
// timeout - Add timeout to any promise
|
|
273
|
-
try {
|
|
274
|
-
const response = await timeout(
|
|
275
|
-
fetch('https://slow-api.example.com/data'),
|
|
276
|
-
5000, // 5 second timeout
|
|
277
|
-
{
|
|
278
|
-
unref: true, // Allow process to exit
|
|
279
|
-
signal: abortController.signal // AbortSignal support
|
|
280
|
-
}
|
|
281
|
-
);
|
|
282
|
-
} catch (error) {
|
|
283
|
-
if (error.message.includes('exceeded')) {
|
|
284
|
-
console.log('Request was too slow');
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// retry - Retry failed operations with exponential backoff
|
|
289
|
-
const fetchWithRetry = await retry(
|
|
290
|
-
async ({ current }) => {
|
|
291
|
-
console.log(`Attempt ${current}`);
|
|
292
|
-
|
|
293
|
-
const response = await fetch('/api/data');
|
|
294
|
-
if (!response.ok) {
|
|
295
|
-
throw new Error(`HTTP ${response.status}`);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
return response.json();
|
|
299
|
-
},
|
|
300
|
-
{
|
|
301
|
-
max: 3, // Maximum 3 attempts
|
|
302
|
-
timeout: 5000, // Timeout per attempt
|
|
303
|
-
backoffBase: 1000, // Start with 1s delay
|
|
304
|
-
backoffExponent: 1.1, // Multiply delay by 1.1 each time
|
|
305
|
-
match: [/HTTP 5\d\d/], // Only retry on 5xx errors
|
|
306
|
-
report: (message, options, error) => {
|
|
307
|
-
console.log(`${message}: ${error?.message}`);
|
|
308
|
-
},
|
|
309
|
-
name: 'fetchData' // Name for logging
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
|
|
313
|
-
// props - Resolve an object of promises
|
|
314
|
-
const userData = await props({
|
|
315
|
-
profile: fetchUserProfile(),
|
|
316
|
-
posts: fetchUserPosts(),
|
|
317
|
-
followers: fetchFollowers(),
|
|
318
|
-
settings: fetchUserSettings()
|
|
319
|
-
});
|
|
320
|
-
// userData = {
|
|
321
|
-
// profile: {...},
|
|
322
|
-
// posts: [...],
|
|
323
|
-
// followers: [...],
|
|
324
|
-
// settings: {...}
|
|
325
|
-
// }
|
|
326
|
-
|
|
327
|
-
// promisify - Convert callback-based functions
|
|
328
|
-
import { readFile } from 'fs';
|
|
329
|
-
|
|
330
|
-
const readFileAsync = promisify(readFile);
|
|
331
|
-
const content = await readFileAsync('config.json', 'utf8');
|
|
332
|
-
|
|
333
|
-
// With context
|
|
334
|
-
const boundPromisify = promisify(obj.method, { context: obj });
|
|
335
|
-
|
|
336
|
-
// promisifyAll - Promisify entire object
|
|
337
|
-
const fs = require('fs');
|
|
338
|
-
const fsAsync = promisifyAll(fs, {
|
|
339
|
-
suffix: 'Async',
|
|
340
|
-
filter: (key) => !key.startsWith('_')
|
|
341
|
-
});
|
|
342
|
-
await fsAsync.readFileAsync('file.txt', 'utf8');
|
|
343
|
-
|
|
344
|
-
// callbackify - Convert promise-based to callback-based
|
|
345
|
-
const fetchCallback = callbackify(fetch);
|
|
346
|
-
|
|
347
|
-
fetchCallback('https://api.example.com', (err, response) => {
|
|
348
|
-
if (err) {
|
|
349
|
-
console.error('Request failed:', err);
|
|
350
|
-
} else {
|
|
351
|
-
console.log('Response:', response);
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
|
|
355
|
-
// nodeify - Add callback support to promise
|
|
356
|
-
const promise = fetch('/api/data');
|
|
357
|
-
nodeify(promise, (err, result) => {
|
|
358
|
-
if (err) console.error(err);
|
|
359
|
-
else console.log(result);
|
|
360
|
-
});
|
|
361
|
-
|
|
362
|
-
// universalify - Support both callback and promise styles
|
|
363
|
-
const readFileUniversal = universalify(readFile);
|
|
364
|
-
|
|
365
|
-
// Use as promise
|
|
366
|
-
const data = await readFileUniversal('file.txt');
|
|
367
|
-
|
|
368
|
-
// Use with callback
|
|
369
|
-
readFileUniversal('file.txt', (err, data) => {
|
|
370
|
-
// ...
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
// finally - Execute cleanup regardless of outcome
|
|
374
|
-
const connection = await openConnection();
|
|
375
|
-
await finallyUtil(
|
|
376
|
-
performOperation(connection),
|
|
377
|
-
() => connection.close()
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
// try - Wrap sync function in promise
|
|
381
|
-
const result = await tryUtil(() => JSON.parse(jsonString));
|
|
382
|
-
```
|
|
383
|
-
|
|
384
|
-
### Object Utilities
|
|
385
|
-
|
|
386
|
-
Functions for working with objects and their properties.
|
|
387
|
-
|
|
388
|
-
```typescript
|
|
389
|
-
import { omit, entries, keys, values } from '@omnitron-dev/common';
|
|
390
|
-
|
|
391
|
-
// omit - Create object copy without specified keys
|
|
392
|
-
const user = {
|
|
393
|
-
id: 1,
|
|
394
|
-
name: 'John Doe',
|
|
395
|
-
email: 'john@example.com',
|
|
396
|
-
password: 'secret123',
|
|
397
|
-
ssn: '123-45-6789'
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
// Single key
|
|
401
|
-
const publicUser = omit(user, 'password');
|
|
402
|
-
// { id: 1, name: 'John Doe', email: 'john@example.com', ssn: '123-45-6789' }
|
|
403
|
-
|
|
404
|
-
// Multiple keys
|
|
405
|
-
const safeUser = omit(user, ['password', 'ssn']);
|
|
406
|
-
// { id: 1, name: 'John Doe', email: 'john@example.com' }
|
|
407
|
-
|
|
408
|
-
// Using predicate function
|
|
409
|
-
const filtered = omit(user, (key, value) => {
|
|
410
|
-
return key.startsWith('_') || value === null;
|
|
411
|
-
});
|
|
412
|
-
|
|
413
|
-
// Using regex pattern
|
|
414
|
-
const withoutPrivate = omit(user, /^_/);
|
|
415
|
-
|
|
416
|
-
// Deep omit
|
|
417
|
-
const nested = {
|
|
418
|
-
user: {
|
|
419
|
-
id: 1,
|
|
420
|
-
profile: {
|
|
421
|
-
name: 'John',
|
|
422
|
-
password: 'secret',
|
|
423
|
-
settings: {
|
|
424
|
-
theme: 'dark',
|
|
425
|
-
apiKey: 'xyz123'
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
const cleaned = omit(nested, ['password', 'apiKey'], { deep: true });
|
|
432
|
-
// Removes password and apiKey at any depth
|
|
433
|
-
|
|
434
|
-
// Path-based omit
|
|
435
|
-
const config = {
|
|
436
|
-
app: {
|
|
437
|
-
name: 'MyApp',
|
|
438
|
-
secret: {
|
|
439
|
-
key: 'secret123',
|
|
440
|
-
token: 'abc'
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
|
|
445
|
-
const publicConfig = omit(config, 'app.secret.key', { path: true });
|
|
446
|
-
// Removes only the specific nested key
|
|
447
|
-
|
|
448
|
-
// entries/keys/values with advanced options
|
|
449
|
-
const obj = { a: 1, b: 2 };
|
|
450
|
-
Object.defineProperty(obj, 'hidden', {
|
|
451
|
-
value: 3,
|
|
452
|
-
enumerable: false
|
|
453
|
-
});
|
|
454
|
-
|
|
455
|
-
entries(obj); // [['a', 1], ['b', 2]]
|
|
456
|
-
entries(obj, { enumOnly: false }); // [['a', 1], ['b', 2], ['hidden', 3]]
|
|
457
|
-
|
|
458
|
-
// Work with prototype chain
|
|
459
|
-
class Parent {
|
|
460
|
-
inherited = 'from parent';
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
class Child extends Parent {
|
|
464
|
-
own = 'child property';
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
const instance = new Child();
|
|
468
|
-
|
|
469
|
-
keys(instance); // ['own', 'inherited']
|
|
470
|
-
keys(instance, { followProto: false }); // ['own', 'inherited']
|
|
471
|
-
keys(instance, { followProto: true }); // Includes prototype chain
|
|
472
|
-
keys(instance, { all: true }); // All properties including non-enumerable
|
|
473
|
-
|
|
474
|
-
values(instance); // ['child property', 'from parent']
|
|
475
|
-
values(instance, { enumOnly: false }); // Includes non-enumerable values
|
|
476
|
-
```
|
|
477
|
-
|
|
478
|
-
### Data Structures
|
|
479
|
-
|
|
480
|
-
Specialized data structures for common use cases.
|
|
481
|
-
|
|
482
|
-
```typescript
|
|
483
|
-
import { ListBuffer, TimedMap } from '@omnitron-dev/common';
|
|
484
|
-
|
|
485
|
-
// ListBuffer - Efficient linked list implementation
|
|
486
|
-
const buffer = new ListBuffer<string>();
|
|
487
|
-
|
|
488
|
-
// Add items to the end
|
|
489
|
-
buffer.push('first');
|
|
490
|
-
buffer.push('second');
|
|
491
|
-
buffer.push('third');
|
|
492
|
-
|
|
493
|
-
// Remove items from the beginning
|
|
494
|
-
const first = buffer.shift(); // 'first'
|
|
495
|
-
const second = buffer.shift(); // 'second'
|
|
496
|
-
|
|
497
|
-
// Check size
|
|
498
|
-
console.log(buffer.length); // 1
|
|
499
|
-
|
|
500
|
-
// Clear all items
|
|
501
|
-
buffer.clear();
|
|
502
|
-
console.log(buffer.length); // 0
|
|
503
|
-
|
|
504
|
-
// Use for queue-like operations
|
|
505
|
-
class MessageQueue {
|
|
506
|
-
private queue = new ListBuffer<Message>();
|
|
507
|
-
|
|
508
|
-
enqueue(message: Message) {
|
|
509
|
-
this.queue.push(message);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
dequeue(): Message | undefined {
|
|
513
|
-
return this.queue.shift();
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
get pending(): number {
|
|
517
|
-
return this.queue.length;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
// TimedMap - Map with automatic expiration
|
|
522
|
-
const cache = new TimedMap<string, any>(60000); // 60 second default TTL
|
|
523
|
-
|
|
524
|
-
// Store data with default timeout
|
|
525
|
-
cache.set('user:123', { name: 'John', role: 'admin' });
|
|
526
|
-
|
|
527
|
-
// Store with custom timeout
|
|
528
|
-
cache.set('session:abc', { token: 'xyz' }, undefined, 30000); // 30s TTL
|
|
529
|
-
|
|
530
|
-
// Store with custom callback on expiration
|
|
531
|
-
cache.set('temp:data', data, (key) => {
|
|
532
|
-
console.log(`Key ${key} expired`);
|
|
533
|
-
}, 5000);
|
|
534
|
-
|
|
535
|
-
// Retrieve data
|
|
536
|
-
const user = cache.get('user:123'); // { name: 'John', role: 'admin' }
|
|
537
|
-
|
|
538
|
-
// Iterate over entries
|
|
539
|
-
for (const [key, value] of cache.entries()) {
|
|
540
|
-
console.log(key, value);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// Iterate over values
|
|
544
|
-
for (const value of cache.values()) {
|
|
545
|
-
console.log(value);
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
// Manual cleanup
|
|
549
|
-
cache.delete('session:abc');
|
|
550
|
-
cache.clear(); // Remove all entries
|
|
551
|
-
|
|
552
|
-
// Use forEach
|
|
553
|
-
cache.forEach((value, key, map) => {
|
|
554
|
-
console.log(`${key}: ${JSON.stringify(value)}`);
|
|
555
|
-
}, thisArg);
|
|
556
|
-
```
|
|
557
|
-
|
|
558
|
-
## API Reference
|
|
559
|
-
|
|
560
|
-
### Primitives
|
|
561
|
-
|
|
562
|
-
| Function | Description | Example |
|
|
563
|
-
|----------|-------------|---------|
|
|
564
|
-
| `noop()` | No operation function | `setTimeout(noop, 1000)` |
|
|
565
|
-
| `identity(value)` | Returns input unchanged | `[1, 2, 3].map(identity)` |
|
|
566
|
-
| `truly()` | Always returns true | `items.filter(truly)` |
|
|
567
|
-
| `falsely()` | Always returns false | `if (falsely()) { }` |
|
|
568
|
-
| `arrify(value)` | Converts value to array | `arrify(null) // []` |
|
|
569
|
-
|
|
570
|
-
### Type Predicates
|
|
571
|
-
|
|
572
|
-
| Function | Description | Returns |
|
|
573
|
-
|----------|-------------|---------|
|
|
574
|
-
| `isString(value)` | Checks if value is string | `value is string` |
|
|
575
|
-
| `isNumber(value)` | Checks if value is number | `value is number` |
|
|
576
|
-
| `isBoolean(value)` | Checks if value is boolean | `value is boolean` |
|
|
577
|
-
| `isBigInt(value)` | Checks if value is BigInt | `value is bigint` |
|
|
578
|
-
| `isSymbol(value)` | Checks if value is Symbol | `boolean` |
|
|
579
|
-
| `isArray(value)` | Checks if value is array | `value is any[]` |
|
|
580
|
-
| `isObject(value)` | Checks if value is object | `boolean` |
|
|
581
|
-
| `isFunction(value)` | Checks if value is function | `boolean` |
|
|
582
|
-
| `isAsyncFunction(value)` | Checks if value is async function | `boolean` |
|
|
583
|
-
| `isAsyncGenerator(value)` | Checks if value is async generator | `value is AsyncGenerator` |
|
|
584
|
-
| `isPromise(value)` | Checks if value is Promise | `boolean` |
|
|
585
|
-
| `isClass(value)` | Checks if value is class | `boolean` |
|
|
586
|
-
| `isNull(value)` | Checks if value is null | `boolean` |
|
|
587
|
-
| `isUndefined(value)` | Checks if value is undefined | `boolean` |
|
|
588
|
-
| `isNil(value)` | Checks if value is null or undefined | `boolean` |
|
|
589
|
-
| `isExist(value)` | Checks if value exists (not null/undefined) | `boolean` |
|
|
590
|
-
| `isPlainObject(value)` | Checks if value is plain object | `boolean` |
|
|
591
|
-
| `isPrimitive(value)` | Checks if value is primitive | `boolean` |
|
|
592
|
-
| `isEmptyString(value)` | Checks if string is empty or whitespace | `boolean` |
|
|
593
|
-
| `isEmptyObject(value)` | Checks if object has no own properties | `boolean` |
|
|
594
|
-
| `isBuffer(value)` | Checks if value is Buffer | `boolean` |
|
|
595
|
-
| `isDate(value)` | Checks if value is Date | `boolean` |
|
|
596
|
-
| `isRegexp(value)` | Checks if value is RegExp | `boolean` |
|
|
597
|
-
| `isError(value)` | Checks if value is Error | `boolean` |
|
|
598
|
-
| `isMap(value)` | Checks if value is Map | `boolean` |
|
|
599
|
-
| `isSet(value)` | Checks if value is Set | `boolean` |
|
|
600
|
-
| `isArrayBuffer(value)` | Checks if value is ArrayBuffer | `boolean` |
|
|
601
|
-
| `isArrayBufferView(value)` | Checks if value is ArrayBufferView | `boolean` |
|
|
602
|
-
| `isNumeral(value)` | Checks if value represents a finite number | `boolean` |
|
|
603
|
-
| `isNumeralInteger(value)` | Checks if value represents an integer | `boolean` |
|
|
604
|
-
| `isNumeralBigInt(value)` | Checks if string represents BigInt | `boolean` |
|
|
605
|
-
| `isFinite(value)` | Checks if number is finite | `boolean` |
|
|
606
|
-
| `isInfinite(value)` | Checks if number is infinite | `boolean` |
|
|
607
|
-
| `isInteger(value)` | Checks if number is integer | `boolean` |
|
|
608
|
-
| `isSafeInteger(value)` | Checks if number is safe integer | `boolean` |
|
|
609
|
-
| `isFloat(value)` | Checks if number is float | `boolean` |
|
|
610
|
-
| `isOdd(value)` | Checks if number is odd | `boolean` |
|
|
611
|
-
| `isEven(value)` | Checks if number is even | `boolean` |
|
|
612
|
-
| `isNan(value)` | Checks if value is NaN | `boolean` |
|
|
613
|
-
| `isNegativeZero(value)` | Checks if value is negative zero | `boolean` |
|
|
614
|
-
| `isSubstring(substr, str, offset?)` | Checks if substr exists in str | `boolean` |
|
|
615
|
-
| `isPrefix(prefix, str)` | Checks if str starts with prefix | `boolean` |
|
|
616
|
-
| `isSuffix(suffix, str)` | Checks if str ends with suffix | `boolean` |
|
|
617
|
-
| `isPropertyOwned(obj, key)` | Checks if property is own (not inherited) | `boolean` |
|
|
618
|
-
| `isPropertyDefined(obj, path)` | Checks if property path exists | `boolean` |
|
|
619
|
-
| `getTag(value)` | Gets detailed type tag | `string` |
|
|
620
|
-
| `getTagSimple(value)` | Gets simple type tag | `string` |
|
|
621
|
-
|
|
622
|
-
### Platform Predicates
|
|
623
|
-
|
|
624
|
-
| Constant | Description | Type |
|
|
625
|
-
|----------|-------------|------|
|
|
626
|
-
| `isWindows` | Running on Windows | `boolean` |
|
|
627
|
-
| `linux` | Running on Linux | `boolean` |
|
|
628
|
-
| `darwin` | Running on macOS | `boolean` |
|
|
629
|
-
| `freebsd` | Running on FreeBSD | `boolean` |
|
|
630
|
-
| `openbsd` | Running on OpenBSD | `boolean` |
|
|
631
|
-
| `sunos` | Running on SunOS | `boolean` |
|
|
632
|
-
| `aix` | Running on AIX | `boolean` |
|
|
633
|
-
| `isNodejs` | Running in Node.js | `boolean` |
|
|
634
|
-
|
|
635
|
-
### Promise Utilities
|
|
636
|
-
|
|
637
|
-
| Function | Description |
|
|
638
|
-
|----------|-------------|
|
|
639
|
-
| `defer<T>()` | Creates a deferred promise with resolve/reject methods |
|
|
640
|
-
| `delay(ms, value?, options?)` | Delays execution with optional value |
|
|
641
|
-
| `timeout(promise, ms, options?)` | Adds timeout to promise |
|
|
642
|
-
| `retry(fn, options)` | Retries function with backoff |
|
|
643
|
-
| `props(object)` | Resolves object of promises |
|
|
644
|
-
| `promisify(fn, options?)` | Converts callback to promise |
|
|
645
|
-
| `promisifyAll(obj, options?)` | Promisifies all methods in object |
|
|
646
|
-
| `callbackify(fn)` | Converts promise to callback |
|
|
647
|
-
| `nodeify(promise, callback)` | Adds callback support to promise |
|
|
648
|
-
| `universalify(fn)` | Supports both callback and promise |
|
|
649
|
-
| `universalifyFromPromise(fn)` | Universal wrapper for promise function |
|
|
650
|
-
| `finally(promise, onFinally)` | Execute cleanup regardless of outcome |
|
|
651
|
-
| `try(fn, ...args)` | Wrap sync function in promise |
|
|
652
|
-
|
|
653
|
-
### Object Utilities
|
|
654
|
-
|
|
655
|
-
| Function | Description |
|
|
656
|
-
|----------|-------------|
|
|
657
|
-
| `omit(obj, keys, options?)` | Creates object without specified keys |
|
|
658
|
-
| `entries(obj, options?)` | Gets object entries with options |
|
|
659
|
-
| `keys(obj, options?)` | Gets object keys with options |
|
|
660
|
-
| `values(obj, options?)` | Gets object values with options |
|
|
661
|
-
|
|
662
|
-
### Data Structures
|
|
663
|
-
|
|
664
|
-
| Class | Description |
|
|
665
|
-
|-------|-------------|
|
|
666
|
-
| `ListBuffer<T>` | Efficient linked list for queue operations |
|
|
667
|
-
| `TimedMap<K, V>` | Map with automatic key expiration |
|
|
668
|
-
|
|
669
|
-
## Advanced Features
|
|
670
|
-
|
|
671
|
-
### Custom Retry Strategies
|
|
672
|
-
|
|
673
|
-
```typescript
|
|
674
|
-
import { retry, delay } from '@omnitron-dev/common';
|
|
675
|
-
|
|
676
|
-
// Custom retry with jitter
|
|
677
|
-
const fetchWithJitter = async (url: string) => {
|
|
678
|
-
return retry(
|
|
679
|
-
async ({ current }) => {
|
|
680
|
-
// Add random jitter to prevent thundering herd
|
|
681
|
-
const jitter = Math.random() * 1000;
|
|
682
|
-
await delay(jitter);
|
|
683
|
-
|
|
684
|
-
return fetch(url);
|
|
685
|
-
},
|
|
686
|
-
{
|
|
687
|
-
max: 5,
|
|
688
|
-
backoffBase: 1000,
|
|
689
|
-
backoffExponent: 2,
|
|
690
|
-
report: (msg, options) => {
|
|
691
|
-
console.log(`Retry ${options.$current}/${options.max}`);
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
);
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
// Conditional retry based on error type
|
|
698
|
-
const resilientFetch = async (url: string) => {
|
|
699
|
-
return retry(
|
|
700
|
-
async () => {
|
|
701
|
-
const response = await fetch(url);
|
|
702
|
-
|
|
703
|
-
if (!response.ok) {
|
|
704
|
-
const error = new Error(`HTTP ${response.status}`);
|
|
705
|
-
(error as any).status = response.status;
|
|
706
|
-
throw error;
|
|
707
|
-
}
|
|
708
|
-
|
|
709
|
-
return response.json();
|
|
710
|
-
},
|
|
711
|
-
{
|
|
712
|
-
max: 3,
|
|
713
|
-
match: [
|
|
714
|
-
// Only retry on network errors or 5xx
|
|
715
|
-
/NetworkError/,
|
|
716
|
-
/HTTP 5\d\d/
|
|
717
|
-
]
|
|
718
|
-
}
|
|
719
|
-
);
|
|
720
|
-
};
|
|
721
|
-
```
|
|
722
|
-
|
|
723
|
-
### Type-Safe Object Filtering
|
|
724
|
-
|
|
725
|
-
```typescript
|
|
726
|
-
import { omit, entries, isString, isNumber } from '@omnitron-dev/common';
|
|
727
|
-
|
|
728
|
-
// Type-safe configuration filtering
|
|
729
|
-
interface Config {
|
|
730
|
-
apiUrl: string;
|
|
731
|
-
apiKey: string;
|
|
732
|
-
timeout: number;
|
|
733
|
-
debug: boolean;
|
|
734
|
-
secretToken: string;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
function getPublicConfig(config: Config) {
|
|
738
|
-
// Remove sensitive fields
|
|
739
|
-
return omit(config, ['apiKey', 'secretToken']);
|
|
740
|
-
}
|
|
741
|
-
|
|
742
|
-
// Filter object by value types
|
|
743
|
-
function extractStrings<T extends object>(obj: T): Partial<T> {
|
|
744
|
-
const stringEntries = entries(obj)
|
|
745
|
-
.filter(([_, value]) => isString(value));
|
|
746
|
-
|
|
747
|
-
return Object.fromEntries(stringEntries) as Partial<T>;
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
// Deep filtering with predicate
|
|
751
|
-
function removeNullish<T extends object>(obj: T): T {
|
|
752
|
-
return omit(obj, (key, value) => isNil(value), { deep: true });
|
|
753
|
-
}
|
|
754
|
-
```
|
|
755
|
-
|
|
756
|
-
### Advanced Timing Patterns
|
|
757
|
-
|
|
758
|
-
```typescript
|
|
759
|
-
import { delay, timeout, defer, TimedMap } from '@omnitron-dev/common';
|
|
760
|
-
|
|
761
|
-
// Polling with timeout
|
|
762
|
-
async function pollEndpoint(url: string, interval = 1000, maxTime = 30000) {
|
|
763
|
-
const start = Date.now();
|
|
764
|
-
|
|
765
|
-
while (Date.now() - start < maxTime) {
|
|
766
|
-
try {
|
|
767
|
-
const response = await timeout(fetch(url), 5000);
|
|
768
|
-
|
|
769
|
-
if (response.ok) {
|
|
770
|
-
return response.json();
|
|
771
|
-
}
|
|
772
|
-
} catch (error) {
|
|
773
|
-
// Continue polling
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
await delay(interval);
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
throw new Error('Polling timeout exceeded');
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
// Rate limiting with TimedMap
|
|
783
|
-
class RateLimiter {
|
|
784
|
-
private attempts = new TimedMap<string, number>(60000); // 1 minute window
|
|
785
|
-
private maxAttempts = 10;
|
|
786
|
-
|
|
787
|
-
async checkLimit(key: string): Promise<boolean> {
|
|
788
|
-
const current = this.attempts.get(key) || 0;
|
|
789
|
-
|
|
790
|
-
if (current >= this.maxAttempts) {
|
|
791
|
-
return false;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
this.attempts.set(key, current + 1);
|
|
795
|
-
return true;
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
|
|
799
|
-
// Debounced async operations
|
|
800
|
-
function createAsyncDebounce<T>(fn: () => Promise<T>, wait: number) {
|
|
801
|
-
let pending: Promise<T> | null = null;
|
|
802
|
-
let timer: NodeJS.Timeout | null = null;
|
|
803
|
-
const deferred = defer<T>();
|
|
804
|
-
|
|
805
|
-
return async (): Promise<T> => {
|
|
806
|
-
if (timer) clearTimeout(timer);
|
|
807
|
-
|
|
808
|
-
if (!pending) {
|
|
809
|
-
pending = deferred.promise;
|
|
810
|
-
|
|
811
|
-
timer = setTimeout(async () => {
|
|
812
|
-
try {
|
|
813
|
-
const result = await fn();
|
|
814
|
-
deferred.resolve(result);
|
|
815
|
-
} catch (error) {
|
|
816
|
-
deferred.reject(error);
|
|
817
|
-
} finally {
|
|
818
|
-
pending = null;
|
|
819
|
-
timer = null;
|
|
820
|
-
}
|
|
821
|
-
}, wait);
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
return pending;
|
|
825
|
-
};
|
|
826
|
-
}
|
|
827
|
-
```
|
|
828
|
-
|
|
829
|
-
## TypeScript Support
|
|
830
|
-
|
|
831
|
-
This library is written in TypeScript and provides comprehensive type definitions.
|
|
832
|
-
|
|
833
|
-
```typescript
|
|
834
|
-
// Type inference works automatically
|
|
835
|
-
const numbers = arrify(42); // number[]
|
|
836
|
-
const mixed = arrify<string | number>('hello'); // (string | number)[]
|
|
837
|
-
|
|
838
|
-
// Type predicates provide type narrowing
|
|
839
|
-
function processUnknown(value: unknown) {
|
|
840
|
-
if (isString(value)) {
|
|
841
|
-
// TypeScript knows value is string
|
|
842
|
-
return value.toUpperCase();
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
if (isArray(value)) {
|
|
846
|
-
// TypeScript knows value is array
|
|
847
|
-
return value.map(x => x);
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
if (isPromise(value)) {
|
|
851
|
-
// TypeScript knows value is Promise
|
|
852
|
-
return value.then(x => x);
|
|
853
|
-
}
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// Generic types are preserved
|
|
857
|
-
const config = {
|
|
858
|
-
name: 'app',
|
|
859
|
-
version: '1.0',
|
|
860
|
-
debug: true,
|
|
861
|
-
secret: 'xyz'
|
|
862
|
-
};
|
|
863
|
-
|
|
864
|
-
const publicConfig = omit(config, ['secret']);
|
|
865
|
-
// Type is inferred correctly
|
|
866
|
-
|
|
867
|
-
// Async utilities maintain types
|
|
868
|
-
const data = await retry(
|
|
869
|
-
async () => ({ id: 1, name: 'John' }),
|
|
870
|
-
{ max: 3 }
|
|
871
|
-
);
|
|
872
|
-
// Type: { id: number, name: string }
|
|
873
|
-
```
|
|
874
|
-
|
|
875
|
-
## Performance
|
|
876
|
-
|
|
877
|
-
### Optimization Strategies
|
|
878
|
-
|
|
879
|
-
1. **Tree Shaking** - Import only what you need
|
|
880
|
-
```typescript
|
|
881
|
-
// Good - only imports what's needed
|
|
882
|
-
import { delay, retry } from '@omnitron-dev/common';
|
|
883
|
-
|
|
884
|
-
// Avoid - imports entire library
|
|
885
|
-
import * as common from '@omnitron-dev/common';
|
|
886
|
-
```
|
|
887
|
-
|
|
888
|
-
2. **Efficient Type Checking** - Predicates use optimal checks
|
|
889
|
-
- Direct `typeof` checks where possible
|
|
890
|
-
- Prototype chain checks minimized
|
|
891
|
-
- Early returns for performance
|
|
892
|
-
|
|
893
|
-
3. **Memory Management**
|
|
894
|
-
- `TimedMap` automatically cleans expired entries
|
|
895
|
-
- `ListBuffer` provides O(1) push/shift operations
|
|
896
|
-
- No memory leaks in async utilities
|
|
897
|
-
|
|
898
|
-
### Benchmarks
|
|
899
|
-
|
|
900
|
-
Performance characteristics:
|
|
901
|
-
|
|
902
|
-
- Type predicates: ~2-5ns per check
|
|
903
|
-
- Object utilities: O(n) where n is number of keys
|
|
904
|
-
- Promise utilities: Minimal overhead over native promises
|
|
905
|
-
- ListBuffer: O(1) push/shift operations
|
|
906
|
-
- TimedMap: O(1) get/set with automatic cleanup
|
|
907
|
-
|
|
908
|
-
## Best Practices
|
|
909
|
-
|
|
910
|
-
### Error Handling
|
|
911
|
-
|
|
912
|
-
```typescript
|
|
913
|
-
import { retry, isError, timeout } from '@omnitron-dev/common';
|
|
914
|
-
|
|
915
|
-
// Always handle errors in retry operations
|
|
916
|
-
const safeRetry = async <T>(operation: () => Promise<T>) => {
|
|
917
|
-
try {
|
|
918
|
-
return await retry(operation, {
|
|
919
|
-
max: 3,
|
|
920
|
-
report: (msg, options, error) => {
|
|
921
|
-
logger.warn(`Retry ${options.$current}: ${error?.message}`);
|
|
922
|
-
}
|
|
923
|
-
});
|
|
924
|
-
} catch (finalError) {
|
|
925
|
-
logger.error('All retries failed:', finalError);
|
|
926
|
-
throw finalError;
|
|
927
|
-
}
|
|
928
|
-
};
|
|
929
|
-
|
|
930
|
-
// Combine timeout with retry for robustness
|
|
931
|
-
const fetchWithTimeoutAndRetry = async (url: string) => {
|
|
932
|
-
return retry(
|
|
933
|
-
async () => {
|
|
934
|
-
return timeout(fetch(url), 5000);
|
|
935
|
-
},
|
|
936
|
-
{ max: 3, backoffBase: 1000 }
|
|
937
|
-
);
|
|
938
|
-
};
|
|
939
|
-
```
|
|
940
|
-
|
|
941
|
-
### Type Safety
|
|
942
|
-
|
|
943
|
-
```typescript
|
|
944
|
-
// Use type predicates for unknown values
|
|
945
|
-
function handleApiResponse(response: unknown) {
|
|
946
|
-
if (!isObject(response)) {
|
|
947
|
-
throw new Error('Invalid response format');
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
if (!isPropertyDefined(response, 'status')) {
|
|
951
|
-
throw new Error('Missing status field');
|
|
952
|
-
}
|
|
953
|
-
|
|
954
|
-
if (isPropertyDefined(response, 'data') && !isArray(response.data)) {
|
|
955
|
-
throw new Error('Data must be an array');
|
|
956
|
-
}
|
|
957
|
-
|
|
958
|
-
// Now safely typed
|
|
959
|
-
return {
|
|
960
|
-
status: response.status,
|
|
961
|
-
data: response.data || []
|
|
962
|
-
};
|
|
963
|
-
}
|
|
964
|
-
```
|
|
965
|
-
|
|
966
|
-
### Memory Efficiency
|
|
967
|
-
|
|
968
|
-
```typescript
|
|
969
|
-
// Use TimedMap for automatic cache expiration
|
|
970
|
-
const cache = new TimedMap<string, any>(300000); // 5 minutes
|
|
971
|
-
|
|
972
|
-
// Use ListBuffer for queue operations
|
|
973
|
-
const eventQueue = new ListBuffer<Event>();
|
|
974
|
-
eventQueue.push(event);
|
|
975
|
-
const next = eventQueue.shift();
|
|
976
|
-
|
|
977
|
-
// Clean up when done
|
|
978
|
-
cache.clear();
|
|
979
|
-
```
|
|
980
|
-
|
|
981
|
-
## Contributing
|
|
982
|
-
|
|
983
|
-
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
984
|
-
|
|
985
|
-
1. Fork the repository
|
|
986
|
-
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
|
|
987
|
-
3. Commit your changes (`git commit -m 'Add amazing feature'`)
|
|
988
|
-
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
989
|
-
5. Open a Pull Request
|
|
990
|
-
|
|
991
25
|
## License
|
|
992
26
|
|
|
993
|
-
MIT
|
|
994
|
-
|
|
995
|
-
## Links
|
|
996
|
-
|
|
997
|
-
- [GitHub Repository](https://github.com/omnitron-dev/omni/tree/main/packages/common)
|
|
998
|
-
- [npm Package](https://www.npmjs.com/package/@omnitron-dev/common)
|
|
999
|
-
- [Issue Tracker](https://github.com/omnitron-dev/omni/issues)
|
|
27
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sha3_512 as sha3 } from '@noble/hashes/sha3';
|
|
1
|
+
import { sha3_512 as sha3 } from '@noble/hashes/sha3.js';
|
|
2
2
|
const ALPHABET = 'abcdefghijklmnopqrstuvwxyz';
|
|
3
3
|
const ALPHABET_LENGTH = 26;
|
|
4
4
|
const BASE36_CHARS = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
@@ -8,67 +8,131 @@ const BIG_LENGTH = 32;
|
|
|
8
8
|
const textEncoder = new TextEncoder();
|
|
9
9
|
let cachedFingerprint = null;
|
|
10
10
|
let cachedCounter = Math.floor(Math.random() * INITIAL_COUNT_MAX);
|
|
11
|
+
const b36 = (n) => BASE36_CHARS[n];
|
|
11
12
|
const createEntropy = (length) => {
|
|
12
13
|
let result = '';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
switch (length) {
|
|
15
|
+
case 4:
|
|
16
|
+
return (b36((Math.random() * 36) | 0) +
|
|
17
|
+
b36((Math.random() * 36) | 0) +
|
|
18
|
+
b36((Math.random() * 36) | 0) +
|
|
19
|
+
b36((Math.random() * 36) | 0));
|
|
20
|
+
case 8:
|
|
21
|
+
return (b36((Math.random() * 36) | 0) +
|
|
22
|
+
b36((Math.random() * 36) | 0) +
|
|
23
|
+
b36((Math.random() * 36) | 0) +
|
|
24
|
+
b36((Math.random() * 36) | 0) +
|
|
25
|
+
b36((Math.random() * 36) | 0) +
|
|
26
|
+
b36((Math.random() * 36) | 0) +
|
|
27
|
+
b36((Math.random() * 36) | 0) +
|
|
28
|
+
b36((Math.random() * 36) | 0));
|
|
29
|
+
case 16:
|
|
30
|
+
return (b36((Math.random() * 36) | 0) +
|
|
31
|
+
b36((Math.random() * 36) | 0) +
|
|
32
|
+
b36((Math.random() * 36) | 0) +
|
|
33
|
+
b36((Math.random() * 36) | 0) +
|
|
34
|
+
b36((Math.random() * 36) | 0) +
|
|
35
|
+
b36((Math.random() * 36) | 0) +
|
|
36
|
+
b36((Math.random() * 36) | 0) +
|
|
37
|
+
b36((Math.random() * 36) | 0) +
|
|
38
|
+
b36((Math.random() * 36) | 0) +
|
|
39
|
+
b36((Math.random() * 36) | 0) +
|
|
40
|
+
b36((Math.random() * 36) | 0) +
|
|
41
|
+
b36((Math.random() * 36) | 0) +
|
|
42
|
+
b36((Math.random() * 36) | 0) +
|
|
43
|
+
b36((Math.random() * 36) | 0) +
|
|
44
|
+
b36((Math.random() * 36) | 0) +
|
|
45
|
+
b36((Math.random() * 36) | 0));
|
|
46
|
+
case 24:
|
|
47
|
+
return (b36((Math.random() * 36) | 0) +
|
|
48
|
+
b36((Math.random() * 36) | 0) +
|
|
49
|
+
b36((Math.random() * 36) | 0) +
|
|
50
|
+
b36((Math.random() * 36) | 0) +
|
|
51
|
+
b36((Math.random() * 36) | 0) +
|
|
52
|
+
b36((Math.random() * 36) | 0) +
|
|
53
|
+
b36((Math.random() * 36) | 0) +
|
|
54
|
+
b36((Math.random() * 36) | 0) +
|
|
55
|
+
b36((Math.random() * 36) | 0) +
|
|
56
|
+
b36((Math.random() * 36) | 0) +
|
|
57
|
+
b36((Math.random() * 36) | 0) +
|
|
58
|
+
b36((Math.random() * 36) | 0) +
|
|
59
|
+
b36((Math.random() * 36) | 0) +
|
|
60
|
+
b36((Math.random() * 36) | 0) +
|
|
61
|
+
b36((Math.random() * 36) | 0) +
|
|
62
|
+
b36((Math.random() * 36) | 0) +
|
|
63
|
+
b36((Math.random() * 36) | 0) +
|
|
64
|
+
b36((Math.random() * 36) | 0) +
|
|
65
|
+
b36((Math.random() * 36) | 0) +
|
|
66
|
+
b36((Math.random() * 36) | 0) +
|
|
67
|
+
b36((Math.random() * 36) | 0) +
|
|
68
|
+
b36((Math.random() * 36) | 0) +
|
|
69
|
+
b36((Math.random() * 36) | 0) +
|
|
70
|
+
b36((Math.random() * 36) | 0));
|
|
71
|
+
case 32:
|
|
72
|
+
return (b36((Math.random() * 36) | 0) +
|
|
73
|
+
b36((Math.random() * 36) | 0) +
|
|
74
|
+
b36((Math.random() * 36) | 0) +
|
|
75
|
+
b36((Math.random() * 36) | 0) +
|
|
76
|
+
b36((Math.random() * 36) | 0) +
|
|
77
|
+
b36((Math.random() * 36) | 0) +
|
|
78
|
+
b36((Math.random() * 36) | 0) +
|
|
79
|
+
b36((Math.random() * 36) | 0) +
|
|
80
|
+
b36((Math.random() * 36) | 0) +
|
|
81
|
+
b36((Math.random() * 36) | 0) +
|
|
82
|
+
b36((Math.random() * 36) | 0) +
|
|
83
|
+
b36((Math.random() * 36) | 0) +
|
|
84
|
+
b36((Math.random() * 36) | 0) +
|
|
85
|
+
b36((Math.random() * 36) | 0) +
|
|
86
|
+
b36((Math.random() * 36) | 0) +
|
|
87
|
+
b36((Math.random() * 36) | 0) +
|
|
88
|
+
b36((Math.random() * 36) | 0) +
|
|
89
|
+
b36((Math.random() * 36) | 0) +
|
|
90
|
+
b36((Math.random() * 36) | 0) +
|
|
91
|
+
b36((Math.random() * 36) | 0) +
|
|
92
|
+
b36((Math.random() * 36) | 0) +
|
|
93
|
+
b36((Math.random() * 36) | 0) +
|
|
94
|
+
b36((Math.random() * 36) | 0) +
|
|
95
|
+
b36((Math.random() * 36) | 0) +
|
|
96
|
+
b36((Math.random() * 36) | 0) +
|
|
97
|
+
b36((Math.random() * 36) | 0) +
|
|
98
|
+
b36((Math.random() * 36) | 0) +
|
|
99
|
+
b36((Math.random() * 36) | 0) +
|
|
100
|
+
b36((Math.random() * 36) | 0) +
|
|
101
|
+
b36((Math.random() * 36) | 0) +
|
|
102
|
+
b36((Math.random() * 36) | 0) +
|
|
103
|
+
b36((Math.random() * 36) | 0));
|
|
104
|
+
default:
|
|
105
|
+
for (let i = 0; i < length; i++) {
|
|
106
|
+
result += b36((Math.random() * 36) | 0);
|
|
107
|
+
}
|
|
108
|
+
return result;
|
|
20
109
|
}
|
|
21
|
-
else {
|
|
22
|
-
const parts = new Array(length);
|
|
23
|
-
for (let i = 0; i < length; i++) {
|
|
24
|
-
parts[i] = BASE36_CHARS.charAt(Math.floor(random() * 36));
|
|
25
|
-
}
|
|
26
|
-
result = parts.join('');
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
110
|
};
|
|
30
|
-
const BIGINT_SHIFT_8 = 8n;
|
|
31
|
-
const BIGINT_SHIFT_16 = 16n;
|
|
32
|
-
const BIGINT_SHIFT_24 = 24n;
|
|
33
|
-
const BIGINT_SHIFT_32 = 32n;
|
|
34
|
-
const BIGINT_SHIFT_40 = 40n;
|
|
35
|
-
const BIGINT_SHIFT_48 = 48n;
|
|
36
|
-
const BIGINT_SHIFT_56 = 56n;
|
|
37
|
-
const BIGINT_SHIFT_64 = 64n;
|
|
38
|
-
const BIGINT_CACHE = new Array(256);
|
|
39
|
-
for (let i = 0; i < 256; i++) {
|
|
40
|
-
BIGINT_CACHE[i] = BigInt(i);
|
|
41
|
-
}
|
|
42
111
|
const bufToBigInt = (buf) => {
|
|
43
112
|
const len = buf.length;
|
|
44
113
|
if (len === 0)
|
|
45
114
|
return 0n;
|
|
115
|
+
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
116
|
+
if (len === 64) {
|
|
117
|
+
const c0 = view.getBigUint64(0, false);
|
|
118
|
+
const c1 = view.getBigUint64(8, false);
|
|
119
|
+
const c2 = view.getBigUint64(16, false);
|
|
120
|
+
const c3 = view.getBigUint64(24, false);
|
|
121
|
+
const c4 = view.getBigUint64(32, false);
|
|
122
|
+
const c5 = view.getBigUint64(40, false);
|
|
123
|
+
const c6 = view.getBigUint64(48, false);
|
|
124
|
+
const c7 = view.getBigUint64(56, false);
|
|
125
|
+
return (c0 << 448n) | (c1 << 384n) | (c2 << 320n) | (c3 << 256n) | (c4 << 192n) | (c5 << 128n) | (c6 << 64n) | c7;
|
|
126
|
+
}
|
|
46
127
|
let value = 0n;
|
|
47
128
|
let i = 0;
|
|
48
129
|
const fullChunks = (len >> 3) << 3;
|
|
49
130
|
while (i < fullChunks) {
|
|
50
|
-
|
|
51
|
-
const b1 = BIGINT_CACHE[buf[i + 1]];
|
|
52
|
-
const b2 = BIGINT_CACHE[buf[i + 2]];
|
|
53
|
-
const b3 = BIGINT_CACHE[buf[i + 3]];
|
|
54
|
-
const b4 = BIGINT_CACHE[buf[i + 4]];
|
|
55
|
-
const b5 = BIGINT_CACHE[buf[i + 5]];
|
|
56
|
-
const b6 = BIGINT_CACHE[buf[i + 6]];
|
|
57
|
-
const b7 = BIGINT_CACHE[buf[i + 7]];
|
|
58
|
-
const chunk = (b0 << BIGINT_SHIFT_56) |
|
|
59
|
-
(b1 << BIGINT_SHIFT_48) |
|
|
60
|
-
(b2 << BIGINT_SHIFT_40) |
|
|
61
|
-
(b3 << BIGINT_SHIFT_32) |
|
|
62
|
-
(b4 << BIGINT_SHIFT_24) |
|
|
63
|
-
(b5 << BIGINT_SHIFT_16) |
|
|
64
|
-
(b6 << BIGINT_SHIFT_8) |
|
|
65
|
-
b7;
|
|
66
|
-
value = (value << BIGINT_SHIFT_64) | chunk;
|
|
131
|
+
value = (value << 64n) | view.getBigUint64(i, false);
|
|
67
132
|
i += 8;
|
|
68
133
|
}
|
|
69
134
|
while (i < len) {
|
|
70
|
-
|
|
71
|
-
value = (value << BIGINT_SHIFT_8) | byte;
|
|
135
|
+
value = (value << 8n) | BigInt(buf[i]);
|
|
72
136
|
i++;
|
|
73
137
|
}
|
|
74
138
|
return value;
|
|
@@ -93,15 +157,14 @@ const createFingerprint = () => {
|
|
|
93
157
|
cachedFingerprint = hash(sourceString).substring(0, BIG_LENGTH);
|
|
94
158
|
return cachedFingerprint;
|
|
95
159
|
};
|
|
96
|
-
const getNextCount = () => ++cachedCounter;
|
|
97
160
|
export const cuid = () => {
|
|
98
|
-
const firstLetter = ALPHABET
|
|
161
|
+
const firstLetter = ALPHABET[(Math.random() * ALPHABET_LENGTH) | 0];
|
|
99
162
|
const time = Date.now().toString(36);
|
|
100
|
-
const count =
|
|
163
|
+
const count = (++cachedCounter).toString(36);
|
|
101
164
|
const salt = createEntropy(DEFAULT_LENGTH);
|
|
102
|
-
const
|
|
103
|
-
const hashInput =
|
|
104
|
-
const hashed =
|
|
165
|
+
const fp = cachedFingerprint;
|
|
166
|
+
const hashInput = `${time}${salt}${count}${fp}`;
|
|
167
|
+
const hashed = bufToBigInt(sha3(textEncoder.encode(hashInput))).toString(36);
|
|
105
168
|
return firstLetter + hashed.substring(1, DEFAULT_LENGTH);
|
|
106
169
|
};
|
|
107
170
|
export const isCuid = (id) => {
|
|
@@ -124,15 +187,15 @@ export const isCuid = (id) => {
|
|
|
124
187
|
createFingerprint();
|
|
125
188
|
export const createOptimizedCuid = (options) => {
|
|
126
189
|
const length = options?.length || DEFAULT_LENGTH;
|
|
127
|
-
const
|
|
128
|
-
let counter = options?.initialCount
|
|
190
|
+
const fp = options?.fingerprint || createFingerprint();
|
|
191
|
+
let counter = options?.initialCount ?? (Math.random() * INITIAL_COUNT_MAX) | 0;
|
|
129
192
|
return () => {
|
|
130
|
-
const firstLetter = ALPHABET
|
|
193
|
+
const firstLetter = ALPHABET[(Math.random() * ALPHABET_LENGTH) | 0];
|
|
131
194
|
const time = Date.now().toString(36);
|
|
132
195
|
const count = (++counter).toString(36);
|
|
133
196
|
const salt = createEntropy(length);
|
|
134
|
-
const hashInput =
|
|
135
|
-
const hashed =
|
|
197
|
+
const hashInput = `${time}${salt}${count}${fp}`;
|
|
198
|
+
const hashed = bufToBigInt(sha3(textEncoder.encode(hashInput))).toString(36);
|
|
136
199
|
return firstLetter + hashed.substring(1, length);
|
|
137
200
|
};
|
|
138
201
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAGtD,MAAM,QAAQ,GAAG,4BAA4B,CAAC;AAC9C,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,YAAY,GAAG,sCAAsC,CAAC;AAC5D,MAAM,iBAAiB,GAAG,SAAS,CAAC;AACpC,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,MAAM,UAAU,GAAG,EAAE,CAAC;AAGtB,MAAM,WAAW,GAAG,IAAI,W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",
|
|
5
5
|
"author": "LuxQuant",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,19 +11,18 @@
|
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"@paralleldrive/cuid2": "^3.
|
|
14
|
+
"@paralleldrive/cuid2": "^3.3.0",
|
|
15
15
|
"@types/benchmark": "^2.1.5",
|
|
16
16
|
"@types/bun": "latest",
|
|
17
|
-
"@types/
|
|
18
|
-
"@types/node": "25.0.1",
|
|
17
|
+
"@types/node": "26.6.6",
|
|
19
18
|
"benchmark": "^2.1.4",
|
|
20
|
-
"
|
|
21
|
-
"nanoid": "^5.1.6",
|
|
19
|
+
"nanoid": "^6.0.2",
|
|
22
20
|
"short-uuid": "^6.0.3",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
21
|
+
"tsx": "^4.23.15",
|
|
22
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
23
|
+
"uuid": "^14.0.3",
|
|
24
|
+
"vitest": "^5.0.5",
|
|
25
|
+
"@typescript/native": "npm:typescript@^7.0.2"
|
|
27
26
|
},
|
|
28
27
|
"keywords": [
|
|
29
28
|
"utils",
|
|
@@ -46,19 +45,21 @@
|
|
|
46
45
|
"repository": {
|
|
47
46
|
"type": "git",
|
|
48
47
|
"url": "git+https://github.com/omnitron-dev/omni.git",
|
|
49
|
-
"directory": "packages/
|
|
48
|
+
"directory": "packages/cuid"
|
|
50
49
|
},
|
|
51
50
|
"bugs": {
|
|
52
51
|
"url": "https://github.com/omnitron-dev/omni/issues"
|
|
53
52
|
},
|
|
54
|
-
"homepage": "https://github.com/omnitron-dev/omni/tree/main/packages/
|
|
53
|
+
"homepage": "https://github.com/omnitron-dev/omni/tree/main/packages/cuid#readme",
|
|
55
54
|
"dependencies": {
|
|
56
|
-
"@noble/hashes": "
|
|
55
|
+
"@noble/hashes": "2.4.0"
|
|
57
56
|
},
|
|
57
|
+
"gitHead": "3a912fa181e97ddd238a28bb355cd7445c1b7364",
|
|
58
58
|
"scripts": {
|
|
59
|
-
"build": "
|
|
60
|
-
"
|
|
61
|
-
"test
|
|
59
|
+
"build": "../../scripts/build-package.sh -p ./tsconfig.json",
|
|
60
|
+
"typecheck": "tsc --noEmit -p tsconfig.typecheck.json",
|
|
61
|
+
"test": "vitest run",
|
|
62
|
+
"test:node": "vitest run",
|
|
62
63
|
"test:bun": "bun test test/primitives.spec.ts test/list-buffer.spec.ts test/entries.spec.ts test/omit.spec.ts test/predicates.spec.ts test/promise.spec.ts test/timed-map-bun-compat.spec.ts",
|
|
63
64
|
"test:all": "npm run test:node && npm run test:bun",
|
|
64
65
|
"benchmark": "tsx benchmark/index.ts",
|