@rahul_dadhich15/id-toolkit 0.1.0 → 0.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.
- package/README.md +800 -16
- package/package.json +14 -14
package/README.md
CHANGED
|
@@ -1,36 +1,820 @@
|
|
|
1
1
|
# ID Toolkit
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@rahul_dadhich15/id-toolkit)
|
|
4
|
-
[](https://www.npmjs.com/package/@rahul_dadhich15/id-toolkit)
|
|
5
|
-
[](https://github.com/rahuldadhich15/id-toolkit/actions/workflows/ci.yml)
|
|
6
|
-
[](https://github.com/rahuldadhich15/id-toolkit/blob/main/LICENSE)
|
|
7
|
-
|
|
8
3
|
A lightweight, dependency-free TypeScript toolkit for generating, validating, and working with UUIDs, short IDs, and cryptographically secure identifiers.
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
[](https://www.npmjs.com/package/@rahul_dadhich15/id-toolkit)
|
|
6
|
+
[](https://www.npmjs.com/package/@rahul_dadhich15/id-toolkit)
|
|
7
|
+
[](https://github.com/rahuldadhich1517-sys/id-toolkit/actions/workflows/ci.yml)
|
|
8
|
+
[](https://github.com/rahuldadhich1517-sys/id-toolkit)
|
|
9
|
+
|
|
10
|
+
Generate UUIDs, validate UUIDs, create compact IDs, and generate cryptographically secure identifiers with a simple TypeScript API.
|
|
11
11
|
|
|
12
12
|
---
|
|
13
13
|
|
|
14
14
|
## Features
|
|
15
15
|
|
|
16
|
-
- Cryptographically secure random identifiers
|
|
17
16
|
- UUID v4 generation
|
|
18
17
|
- UUID v7 generation
|
|
19
18
|
- Bulk UUID generation
|
|
20
|
-
- UUID
|
|
19
|
+
- UUID validation
|
|
20
|
+
- UUID version detection
|
|
21
21
|
- Compact URL-friendly short IDs
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
22
|
+
- Custom short-ID alphabets
|
|
23
|
+
- Cryptographically secure IDs
|
|
24
|
+
- Hex and Base64URL encodings
|
|
25
|
+
- Bulk secure-ID generation
|
|
26
|
+
- Cryptographically secure randomness using Node.js `crypto`
|
|
27
|
+
- TypeScript-first API
|
|
28
|
+
- Full type declarations
|
|
29
|
+
- ESM + CommonJS support
|
|
26
30
|
- Zero runtime dependencies
|
|
27
|
-
- Vitest
|
|
28
|
-
- Tree-
|
|
29
|
-
- Lightweight
|
|
31
|
+
- Built-in Vitest tests
|
|
32
|
+
- Tree-shakable package
|
|
33
|
+
- Lightweight and production-friendly
|
|
30
34
|
|
|
31
35
|
---
|
|
32
36
|
|
|
33
37
|
## Installation
|
|
34
38
|
|
|
35
39
|
```bash
|
|
36
|
-
npm install @rahul_dadhich15/id-toolkit
|
|
40
|
+
npm install @rahul_dadhich15/id-toolkit
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
### ESM
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import {
|
|
51
|
+
uuidV4,
|
|
52
|
+
uuidV7,
|
|
53
|
+
generateShortId,
|
|
54
|
+
generateSecureId,
|
|
55
|
+
isUUID,
|
|
56
|
+
} from "@rahul_dadhich15/id-toolkit";
|
|
57
|
+
|
|
58
|
+
console.log(uuidV4());
|
|
59
|
+
// Example:
|
|
60
|
+
// 550e8400-e29b-41d4-a716-446655440000
|
|
61
|
+
|
|
62
|
+
console.log(uuidV7());
|
|
63
|
+
// Example:
|
|
64
|
+
// 0190f7a2-7b3c-7e42-8b91-2a4c7d8e9f10
|
|
65
|
+
|
|
66
|
+
console.log(generateShortId());
|
|
67
|
+
// Example:
|
|
68
|
+
// K8x2LmQ9pR7a
|
|
69
|
+
|
|
70
|
+
console.log(generateSecureId());
|
|
71
|
+
// Example:
|
|
72
|
+
// 8f3c9d2e4a7b1c6f0e8d5a3b9c2f7e1d...
|
|
73
|
+
|
|
74
|
+
console.log(isUUID("550e8400-e29b-41d4-a716-446655440000"));
|
|
75
|
+
// true
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
# UUID Generator
|
|
81
|
+
|
|
82
|
+
Generate standards-compliant UUID v4 and UUID v7 identifiers.
|
|
83
|
+
|
|
84
|
+
## UUID v4
|
|
85
|
+
|
|
86
|
+
UUID v4 is randomly generated.
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
import { uuidV4 } from "@rahul_dadhich15/id-toolkit";
|
|
90
|
+
|
|
91
|
+
const id = uuidV4();
|
|
92
|
+
|
|
93
|
+
console.log(id);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Example:
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
550e8400-e29b-41d4-a716-446655440000
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
UUID v4 is useful for:
|
|
103
|
+
|
|
104
|
+
- Database identifiers
|
|
105
|
+
- API resource IDs
|
|
106
|
+
- Request IDs
|
|
107
|
+
- Entity identifiers
|
|
108
|
+
- Distributed systems
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## UUID v7
|
|
113
|
+
|
|
114
|
+
UUID v7 includes a Unix timestamp component while retaining random data.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
import { uuidV7 } from "@rahul_dadhich15/id-toolkit";
|
|
118
|
+
|
|
119
|
+
const id = uuidV7();
|
|
120
|
+
|
|
121
|
+
console.log(id);
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Example:
|
|
125
|
+
|
|
126
|
+
```text
|
|
127
|
+
0190f7a2-7b3c-7e42-8b91-2a4c7d8e9f10
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
UUID v7 can be useful when identifiers benefit from timestamp ordering, such as:
|
|
131
|
+
|
|
132
|
+
- Database primary keys
|
|
133
|
+
- Event IDs
|
|
134
|
+
- Log identifiers
|
|
135
|
+
- Distributed systems
|
|
136
|
+
- Time-ordered records
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## Generate Multiple UUIDs
|
|
141
|
+
|
|
142
|
+
Generate multiple UUIDs at once.
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { generateUUIDs } from "@rahul_dadhich15/id-toolkit";
|
|
146
|
+
|
|
147
|
+
const ids = generateUUIDs(5);
|
|
148
|
+
|
|
149
|
+
console.log(ids);
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Generate UUID v7 identifiers:
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
const ids = generateUUIDs(5, "v7");
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Supported versions:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
type UUIDVersion = "v4" | "v7";
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
# UUID Validator
|
|
167
|
+
|
|
168
|
+
Validate UUID strings and optionally verify their version.
|
|
169
|
+
|
|
170
|
+
## Validate a UUID
|
|
171
|
+
|
|
172
|
+
```ts
|
|
173
|
+
import { isUUID } from "@rahul_dadhich15/id-toolkit";
|
|
174
|
+
|
|
175
|
+
isUUID("550e8400-e29b-41d4-a716-446655440000");
|
|
176
|
+
// true
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Invalid UUID:
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
isUUID("hello-world");
|
|
183
|
+
// false
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
The function accepts `unknown`, making it convenient for validating external input.
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
isUUID(123);
|
|
190
|
+
// false
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Validate UUID Version
|
|
196
|
+
|
|
197
|
+
You can verify that a UUID is a specific version.
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
import { isUUID } from "@rahul_dadhich15/id-toolkit";
|
|
201
|
+
|
|
202
|
+
const id = "550e8400-e29b-41d4-a716-446655440000";
|
|
203
|
+
|
|
204
|
+
isUUID(id, 4);
|
|
205
|
+
// true
|
|
206
|
+
|
|
207
|
+
isUUID(id, 7);
|
|
208
|
+
// false
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Supported UUID versions:
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
## Get UUID Version
|
|
220
|
+
|
|
221
|
+
```ts
|
|
222
|
+
import { getUUIDVersion } from "@rahul_dadhich15/id-toolkit";
|
|
223
|
+
|
|
224
|
+
getUUIDVersion("550e8400-e29b-41d4-a716-446655440000");
|
|
225
|
+
// 4
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Invalid input:
|
|
229
|
+
|
|
230
|
+
```ts
|
|
231
|
+
getUUIDVersion("invalid");
|
|
232
|
+
// null
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
# Short ID
|
|
238
|
+
|
|
239
|
+
Generate compact, URL-friendly identifiers.
|
|
240
|
+
|
|
241
|
+
```ts
|
|
242
|
+
import { generateShortId } from "@rahul_dadhich15/id-toolkit";
|
|
243
|
+
|
|
244
|
+
const id = generateShortId();
|
|
245
|
+
|
|
246
|
+
console.log(id);
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
Example:
|
|
250
|
+
|
|
251
|
+
```text
|
|
252
|
+
K8x2LmQ9pR7a
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Default length:
|
|
256
|
+
|
|
257
|
+
```text
|
|
258
|
+
12 characters
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
The default alphabet contains:
|
|
262
|
+
|
|
263
|
+
```text
|
|
264
|
+
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Short IDs are useful for:
|
|
268
|
+
|
|
269
|
+
- Public URLs
|
|
270
|
+
- Short links
|
|
271
|
+
- Temporary references
|
|
272
|
+
- Human-friendly resource IDs
|
|
273
|
+
- Tracking identifiers
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
## Custom Length
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
const id = generateShortId({
|
|
281
|
+
length: 16,
|
|
282
|
+
});
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
---
|
|
286
|
+
|
|
287
|
+
## Custom Alphabet
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
const id = generateShortId({
|
|
291
|
+
length: 10,
|
|
292
|
+
alphabet: "0123456789",
|
|
293
|
+
});
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
Example:
|
|
297
|
+
|
|
298
|
+
```text
|
|
299
|
+
4829137051
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Custom alphabets must:
|
|
303
|
+
|
|
304
|
+
- Contain at least 2 characters
|
|
305
|
+
- Contain unique characters
|
|
306
|
+
- Contain no more than 256 characters
|
|
307
|
+
|
|
308
|
+
The generator uses rejection sampling to avoid modulo bias.
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## Generate Multiple Short IDs
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
import { generateShortIds } from "@rahul_dadhich15/id-toolkit";
|
|
316
|
+
|
|
317
|
+
const ids = generateShortIds(10);
|
|
318
|
+
|
|
319
|
+
console.log(ids);
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
With options:
|
|
323
|
+
|
|
324
|
+
```ts
|
|
325
|
+
const ids = generateShortIds(10, {
|
|
326
|
+
length: 16,
|
|
327
|
+
});
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
---
|
|
331
|
+
|
|
332
|
+
# Secure ID
|
|
333
|
+
|
|
334
|
+
Generate cryptographically strong random identifiers using Node.js `crypto.randomBytes`.
|
|
335
|
+
|
|
336
|
+
```ts
|
|
337
|
+
import { generateSecureId } from "@rahul_dadhich15/id-toolkit";
|
|
338
|
+
|
|
339
|
+
const id = generateSecureId();
|
|
340
|
+
|
|
341
|
+
console.log(id);
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
The default configuration generates:
|
|
345
|
+
|
|
346
|
+
```text
|
|
347
|
+
32 random bytes
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
encoded as hexadecimal.
|
|
351
|
+
|
|
352
|
+
That produces:
|
|
353
|
+
|
|
354
|
+
```text
|
|
355
|
+
64 hexadecimal characters
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## Hex Encoding
|
|
361
|
+
|
|
362
|
+
```ts
|
|
363
|
+
const id = generateSecureId({
|
|
364
|
+
bytes: 32,
|
|
365
|
+
encoding: "hex",
|
|
366
|
+
});
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
---
|
|
370
|
+
|
|
371
|
+
## Base64URL Encoding
|
|
372
|
+
|
|
373
|
+
Generate URL-safe identifiers using Base64URL encoding.
|
|
374
|
+
|
|
375
|
+
```ts
|
|
376
|
+
const id = generateSecureId({
|
|
377
|
+
bytes: 32,
|
|
378
|
+
encoding: "base64url",
|
|
379
|
+
});
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
Base64URL is useful when identifiers need to be safely embedded in:
|
|
383
|
+
|
|
384
|
+
- URLs
|
|
385
|
+
- Cookies
|
|
386
|
+
- Tokens
|
|
387
|
+
- Query parameters
|
|
388
|
+
- Web APIs
|
|
389
|
+
|
|
390
|
+
---
|
|
391
|
+
|
|
392
|
+
## Custom Entropy
|
|
393
|
+
|
|
394
|
+
You can control the number of random bytes.
|
|
395
|
+
|
|
396
|
+
```ts
|
|
397
|
+
const id = generateSecureId({
|
|
398
|
+
bytes: 16,
|
|
399
|
+
});
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
For stronger identifiers:
|
|
403
|
+
|
|
404
|
+
```ts
|
|
405
|
+
const id = generateSecureId({
|
|
406
|
+
bytes: 64,
|
|
407
|
+
});
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
The supported range is:
|
|
411
|
+
|
|
412
|
+
```text
|
|
413
|
+
1 - 1024 bytes
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
418
|
+
## Generate Multiple Secure IDs
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
import { generateSecureIds } from "@rahul_dadhich15/id-toolkit";
|
|
422
|
+
|
|
423
|
+
const ids = generateSecureIds(5);
|
|
424
|
+
|
|
425
|
+
console.log(ids);
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
With options:
|
|
429
|
+
|
|
430
|
+
```ts
|
|
431
|
+
const ids = generateSecureIds(5, {
|
|
432
|
+
bytes: 32,
|
|
433
|
+
encoding: "base64url",
|
|
434
|
+
});
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
---
|
|
438
|
+
|
|
439
|
+
# API Reference
|
|
440
|
+
|
|
441
|
+
## UUID
|
|
442
|
+
|
|
443
|
+
| Function | Description |
|
|
444
|
+
|---|---|
|
|
445
|
+
| `uuidV4()` | Generate a UUID v4 |
|
|
446
|
+
| `uuidV7()` | Generate a UUID v7 |
|
|
447
|
+
| `generateUUIDs(count, version?)` | Generate multiple UUIDs |
|
|
448
|
+
|
|
449
|
+
---
|
|
450
|
+
|
|
451
|
+
## UUID Validation
|
|
452
|
+
|
|
453
|
+
| Function | Description |
|
|
454
|
+
|---|---|
|
|
455
|
+
| `isUUID(value, version?)` | Validate a UUID |
|
|
456
|
+
| `getUUIDVersion(value)` | Get UUID version |
|
|
457
|
+
|
|
458
|
+
---
|
|
459
|
+
|
|
460
|
+
## Short IDs
|
|
461
|
+
|
|
462
|
+
| Function | Description |
|
|
463
|
+
|---|---|
|
|
464
|
+
| `generateShortId(options?)` | Generate a short ID |
|
|
465
|
+
| `generateShortIds(count, options?)` | Generate multiple short IDs |
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
## Secure IDs
|
|
470
|
+
|
|
471
|
+
| Function | Description |
|
|
472
|
+
|---|---|
|
|
473
|
+
| `generateSecureId(options?)` | Generate a secure identifier |
|
|
474
|
+
| `generateSecureIds(count, options?)` | Generate multiple secure identifiers |
|
|
475
|
+
|
|
476
|
+
---
|
|
477
|
+
|
|
478
|
+
# TypeScript Types
|
|
479
|
+
|
|
480
|
+
The package includes complete TypeScript declarations.
|
|
481
|
+
|
|
482
|
+
### Short ID Options
|
|
483
|
+
|
|
484
|
+
```ts
|
|
485
|
+
interface ShortIdOptions {
|
|
486
|
+
length?: number;
|
|
487
|
+
alphabet?: string;
|
|
488
|
+
}
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### Secure ID Options
|
|
492
|
+
|
|
493
|
+
```ts
|
|
494
|
+
interface SecureIdOptions {
|
|
495
|
+
bytes?: number;
|
|
496
|
+
encoding?: "hex" | "base64url";
|
|
497
|
+
}
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### UUID Generator Version
|
|
501
|
+
|
|
502
|
+
```ts
|
|
503
|
+
type UUIDGeneratorVersion = "v4" | "v7";
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
### UUID Validator Version
|
|
507
|
+
|
|
508
|
+
```ts
|
|
509
|
+
type UUIDValidatorVersion =
|
|
510
|
+
| 1
|
|
511
|
+
| 2
|
|
512
|
+
| 3
|
|
513
|
+
| 4
|
|
514
|
+
| 5
|
|
515
|
+
| 6
|
|
516
|
+
| 7
|
|
517
|
+
| 8;
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
---
|
|
521
|
+
|
|
522
|
+
# Which ID Should I Use?
|
|
523
|
+
|
|
524
|
+
| Use Case | Recommended |
|
|
525
|
+
|---|---|
|
|
526
|
+
| Random standard identifier | UUID v4 |
|
|
527
|
+
| Time-sortable identifier | UUID v7 |
|
|
528
|
+
| Compact public identifier | Short ID |
|
|
529
|
+
| Security-sensitive random value | Secure ID |
|
|
530
|
+
| URL-safe secure identifier | Secure ID + Base64URL |
|
|
531
|
+
| Validate incoming UUID | `isUUID()` |
|
|
532
|
+
| Detect UUID version | `getUUIDVersion()` |
|
|
533
|
+
|
|
534
|
+
### Important Security Note
|
|
535
|
+
|
|
536
|
+
Short IDs are designed primarily for compactness and usability.
|
|
537
|
+
|
|
538
|
+
For security-sensitive values such as:
|
|
539
|
+
|
|
540
|
+
- Reset tokens
|
|
541
|
+
- Authentication tokens
|
|
542
|
+
- Session secrets
|
|
543
|
+
- API secrets
|
|
544
|
+
- Password-reset links
|
|
545
|
+
- Cryptographic nonces
|
|
546
|
+
|
|
547
|
+
prefer `generateSecureId()`.
|
|
548
|
+
|
|
549
|
+
Do not rely on short IDs as secrets simply because they are randomly generated.
|
|
550
|
+
|
|
551
|
+
---
|
|
552
|
+
|
|
553
|
+
# Runtime Dependencies
|
|
554
|
+
|
|
555
|
+
ID Toolkit has **zero runtime dependencies**.
|
|
556
|
+
|
|
557
|
+
It uses Node.js built-in cryptographic functionality:
|
|
558
|
+
|
|
559
|
+
```ts
|
|
560
|
+
node:crypto
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
This keeps the package lightweight and reduces dependency and supply-chain risk.
|
|
564
|
+
|
|
565
|
+
---
|
|
566
|
+
|
|
567
|
+
# ESM and CommonJS
|
|
568
|
+
|
|
569
|
+
ID Toolkit supports both modern ESM and CommonJS environments.
|
|
570
|
+
|
|
571
|
+
### ESM
|
|
572
|
+
|
|
573
|
+
```ts
|
|
574
|
+
import { uuidV4 } from "@rahul_dadhich15/id-toolkit";
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### CommonJS
|
|
578
|
+
|
|
579
|
+
```js
|
|
580
|
+
const { uuidV4 } = require("@rahul_dadhich15/id-toolkit");
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
---
|
|
584
|
+
|
|
585
|
+
# Requirements
|
|
586
|
+
|
|
587
|
+
- Node.js 18+
|
|
588
|
+
- TypeScript 5+ recommended
|
|
589
|
+
|
|
590
|
+
Because the package uses Node.js `crypto`, it is primarily intended for Node.js/server-side applications.
|
|
591
|
+
|
|
592
|
+
---
|
|
593
|
+
|
|
594
|
+
# Development
|
|
595
|
+
|
|
596
|
+
Clone the repository:
|
|
597
|
+
|
|
598
|
+
```bash
|
|
599
|
+
git clone https://github.com/rahuldadhich1517-sys/id-toolkit.git
|
|
600
|
+
cd id-toolkit
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
Install dependencies:
|
|
604
|
+
|
|
605
|
+
```bash
|
|
606
|
+
npm install
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
---
|
|
610
|
+
|
|
611
|
+
## Type Check
|
|
612
|
+
|
|
613
|
+
```bash
|
|
614
|
+
npm run typecheck
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
---
|
|
618
|
+
|
|
619
|
+
## Run Tests
|
|
620
|
+
|
|
621
|
+
```bash
|
|
622
|
+
npm run test:run
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
Run Vitest in watch mode:
|
|
626
|
+
|
|
627
|
+
```bash
|
|
628
|
+
npm test
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
---
|
|
632
|
+
|
|
633
|
+
## Build
|
|
634
|
+
|
|
635
|
+
```bash
|
|
636
|
+
npm run build
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
---
|
|
640
|
+
|
|
641
|
+
## Validate Package Contents
|
|
642
|
+
|
|
643
|
+
```bash
|
|
644
|
+
npm pack --dry-run
|
|
645
|
+
```
|
|
646
|
+
|
|
647
|
+
---
|
|
648
|
+
|
|
649
|
+
# Project Structure
|
|
650
|
+
|
|
651
|
+
```text
|
|
652
|
+
id-toolkit/
|
|
653
|
+
├── src/
|
|
654
|
+
│ ├── uuid-generator/
|
|
655
|
+
│ │ ├── uuid-generator.ts
|
|
656
|
+
│ │ └── index.ts
|
|
657
|
+
│ │
|
|
658
|
+
│ ├── uuid-validator/
|
|
659
|
+
│ │ ├── uuid-validator.ts
|
|
660
|
+
│ │ └── index.ts
|
|
661
|
+
│ │
|
|
662
|
+
│ ├── short-id/
|
|
663
|
+
│ │ ├── short-id.ts
|
|
664
|
+
│ │ └── index.ts
|
|
665
|
+
│ │
|
|
666
|
+
│ ├── secure-id/
|
|
667
|
+
│ │ ├── secure-id.ts
|
|
668
|
+
│ │ └── index.ts
|
|
669
|
+
│ │
|
|
670
|
+
│ └── index.ts
|
|
671
|
+
│
|
|
672
|
+
├── tests/
|
|
673
|
+
│ ├── uuid-generator.test.ts
|
|
674
|
+
│ ├── uuid-validator.test.ts
|
|
675
|
+
│ ├── short-id.test.ts
|
|
676
|
+
│ └── secure-id.test.ts
|
|
677
|
+
│
|
|
678
|
+
├── .github/
|
|
679
|
+
│ └── workflows/
|
|
680
|
+
│ └── ci.yml
|
|
681
|
+
│
|
|
682
|
+
├── README.md
|
|
683
|
+
├── LICENSE
|
|
684
|
+
├── package.json
|
|
685
|
+
├── package-lock.json
|
|
686
|
+
├── tsconfig.json
|
|
687
|
+
└── .gitignore
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
---
|
|
691
|
+
|
|
692
|
+
# Testing
|
|
693
|
+
|
|
694
|
+
The project uses [Vitest](https://vitest.dev/) for automated testing.
|
|
695
|
+
|
|
696
|
+
Tests cover:
|
|
697
|
+
|
|
698
|
+
- UUID v4 generation
|
|
699
|
+
- UUID v7 generation
|
|
700
|
+
- UUID validation
|
|
701
|
+
- UUID version detection
|
|
702
|
+
- Short ID generation
|
|
703
|
+
- Custom alphabets
|
|
704
|
+
- Secure ID generation
|
|
705
|
+
- Encoding options
|
|
706
|
+
- Invalid input handling
|
|
707
|
+
- Boundary conditions
|
|
708
|
+
|
|
709
|
+
Run the full test suite:
|
|
710
|
+
|
|
711
|
+
```bash
|
|
712
|
+
npm run test:run
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
---
|
|
716
|
+
|
|
717
|
+
# CI
|
|
718
|
+
|
|
719
|
+
The repository includes GitHub Actions CI.
|
|
720
|
+
|
|
721
|
+
Every push and pull request runs:
|
|
722
|
+
|
|
723
|
+
```text
|
|
724
|
+
Install dependencies
|
|
725
|
+
↓
|
|
726
|
+
Type check
|
|
727
|
+
↓
|
|
728
|
+
Run tests
|
|
729
|
+
↓
|
|
730
|
+
Build package
|
|
731
|
+
↓
|
|
732
|
+
Validate npm package
|
|
733
|
+
```
|
|
734
|
+
|
|
735
|
+
GitHub repository:
|
|
736
|
+
|
|
737
|
+
https://github.com/rahuldadhich1517-sys/id-toolkit
|
|
738
|
+
|
|
739
|
+
---
|
|
740
|
+
|
|
741
|
+
# Performance
|
|
742
|
+
|
|
743
|
+
ID Toolkit is designed to remain lightweight and efficient.
|
|
744
|
+
|
|
745
|
+
It:
|
|
746
|
+
|
|
747
|
+
- Uses Node.js native cryptographic APIs
|
|
748
|
+
- Has zero runtime dependencies
|
|
749
|
+
- Supports tree shaking
|
|
750
|
+
- Avoids unnecessary abstractions
|
|
751
|
+
- Provides bulk generation helpers
|
|
752
|
+
- Uses rejection sampling for unbiased short-ID generation
|
|
753
|
+
|
|
754
|
+
For extremely large bulk-generation workloads, consider memory usage before generating millions of identifiers in a single array.
|
|
755
|
+
|
|
756
|
+
---
|
|
757
|
+
|
|
758
|
+
# Contributing
|
|
759
|
+
|
|
760
|
+
Contributions, bug reports, and feature requests are welcome.
|
|
761
|
+
|
|
762
|
+
1. Fork the repository.
|
|
763
|
+
2. Create a feature branch.
|
|
764
|
+
3. Make your changes.
|
|
765
|
+
4. Add or update tests.
|
|
766
|
+
5. Run:
|
|
767
|
+
|
|
768
|
+
```bash
|
|
769
|
+
npm run typecheck
|
|
770
|
+
npm run test:run
|
|
771
|
+
npm run build
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
6. Submit a pull request.
|
|
775
|
+
|
|
776
|
+
---
|
|
777
|
+
|
|
778
|
+
# License
|
|
779
|
+
|
|
780
|
+
MIT © 2026 Rahul Dadhich
|
|
781
|
+
|
|
782
|
+
---
|
|
783
|
+
|
|
784
|
+
# Author
|
|
785
|
+
|
|
786
|
+
**Rahul Dadhich**
|
|
787
|
+
|
|
788
|
+
GitHub:
|
|
789
|
+
|
|
790
|
+
https://github.com/rahuldadhich1517-sys
|
|
791
|
+
|
|
792
|
+
Repository:
|
|
793
|
+
|
|
794
|
+
https://github.com/rahuldadhich1517-sys/id-toolkit
|
|
795
|
+
|
|
796
|
+
---
|
|
797
|
+
|
|
798
|
+
# Changelog
|
|
799
|
+
|
|
800
|
+
## 0.1.0
|
|
801
|
+
|
|
802
|
+
Initial release.
|
|
803
|
+
|
|
804
|
+
### Included
|
|
805
|
+
|
|
806
|
+
- UUID v4 generation
|
|
807
|
+
- UUID v7 generation
|
|
808
|
+
- Bulk UUID generation
|
|
809
|
+
- UUID validation
|
|
810
|
+
- UUID version detection
|
|
811
|
+
- Short ID generation
|
|
812
|
+
- Custom short-ID alphabets
|
|
813
|
+
- Secure ID generation
|
|
814
|
+
- Hex encoding
|
|
815
|
+
- Base64URL encoding
|
|
816
|
+
- Bulk secure-ID generation
|
|
817
|
+
- TypeScript declarations
|
|
818
|
+
- ESM + CommonJS support
|
|
819
|
+
- Vitest test suite
|
|
820
|
+
- GitHub Actions CI
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rahul_dadhich15/id-toolkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "A lightweight, dependency-free TypeScript toolkit for UUIDs, short IDs, and secure identifiers.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,17 +17,6 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"sideEffects": false,
|
|
20
|
-
"publishConfig": {
|
|
21
|
-
"access": "public"
|
|
22
|
-
},
|
|
23
|
-
"repository": {
|
|
24
|
-
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/rahuldadhich15/id-toolkit.git"
|
|
26
|
-
},
|
|
27
|
-
"bugs": {
|
|
28
|
-
"url": "https://github.com/rahuldadhich15/id-toolkit/issues"
|
|
29
|
-
},
|
|
30
|
-
"homepage": "https://github.com/rahuldadhich15/id-toolkit#readme",
|
|
31
20
|
"keywords": [
|
|
32
21
|
"uuid",
|
|
33
22
|
"uuid-v4",
|
|
@@ -45,6 +34,17 @@
|
|
|
45
34
|
"utilities"
|
|
46
35
|
],
|
|
47
36
|
"license": "MIT",
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/rahuldadhich1517-sys/id-toolkit.git"
|
|
40
|
+
},
|
|
41
|
+
"bugs": {
|
|
42
|
+
"url": "https://github.com/rahuldadhich1517-sys/id-toolkit/issues"
|
|
43
|
+
},
|
|
44
|
+
"homepage": "https://github.com/rahuldadhich1517-sys/id-toolkit#readme",
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
48
|
"scripts": {
|
|
49
49
|
"build": "npm run clean && tsup src/index.ts --format esm,cjs && tsc",
|
|
50
50
|
"clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\"",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"typecheck": "tsc --noEmit"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/node": "^
|
|
56
|
+
"@types/node": "^24.0.0",
|
|
57
57
|
"tsup": "^8.0.0",
|
|
58
58
|
"typescript": "^5.0.0",
|
|
59
59
|
"vitest": "^3.0.0"
|
|
60
60
|
}
|
|
61
|
-
}
|
|
61
|
+
}
|