idmint 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # idmint
2
+
3
+ **Simple, secure, and scalable unique ID generator for modern applications**
4
+
5
+ `idmint` is a lightweight, TypeScript-friendly unique ID generator designed for **high-traffic frontend and backend applications**.
6
+ It uses **cryptographically secure randomness** to generate **collision-resistant IDs** without any database, server coordination, or external dependency.
7
+
8
+ ---
9
+
10
+ ## ✨ Features
11
+
12
+ - 🔐 **Cryptographically secure IDs** (Node.js `crypto`)
13
+ - ⚡ **Extremely low collision probability** (safe for millions to billions of IDs)
14
+ - 🧩 **Optional size parameter** (flexible length)
15
+ - 🕒 **Time-based sortable IDs**
16
+ - 🏷 **Prefix support**
17
+ - đŸ“Ļ **Zero runtime dependencies**
18
+ - đŸŸĻ **Written in TypeScript**
19
+ - 🚀 **Works in high-traffic & distributed systems**
20
+
21
+ ---
22
+
23
+ ## đŸ“Ļ Installation
24
+
25
+ ```bash
26
+ npm install idmint
27
+ ```
28
+
29
+ ## 🚀 Usage
30
+
31
+ ### Generate a default ID
32
+
33
+ ```bash
34
+ import { generateId } from "idmint";
35
+
36
+ const id = generateId();
37
+ console.log(id);
38
+ // → "V1StGXR8_Z5jdHi6B-myT"
39
+ ```
40
+
41
+ ### Generate ID with custom size
42
+
43
+ ```bash
44
+ generateId(7); // shorter ID
45
+ generateId(32); // longer, ultra-safe ID
46
+ ```
47
+
48
+ â„šī¸ Allowed size range: 4 to 64
49
+
50
+ ### Generate ID with prefix
51
+
52
+ ```bash
53
+ import { generateIdWithPrefix } from "idmint";
54
+
55
+ const id = generateIdWithPrefix("user", 10);
56
+ console.log(id);
57
+ // → "user_K9dLx2PqA"
58
+ ```
59
+
60
+ Useful for:
61
+
62
+ - User IDs
63
+ - Order IDs
64
+ - Entity-based identifiers
65
+
66
+ ### Generate time-based sortable ID
67
+
68
+ ```bash
69
+ import { timeBasedId } from "idmint";
70
+
71
+ const id = timeBasedId();
72
+ console.log(id);
73
+ // → "lq9z3a8c4kH9dP2"
74
+ ```
75
+
76
+ These IDs naturally sort by creation time, which is useful for:
77
+
78
+ - Logs
79
+ - Tables
80
+ - Pagination
81
+ - Short URLs
82
+ - Analytics & tracking
83
+
84
+ ### Preset generators
85
+
86
+ ```bash
87
+ import { idmint } from "idmint";
88
+
89
+ idmint.short(); // 8 characters
90
+ idmint.medium(); // 21 characters (default, recommended)
91
+ idmint.long(); // 32 characters
92
+ ```
93
+
94
+ ## 🔒 How uniqueness is ensured
95
+
96
+ idmint does not store IDs in any database.
97
+
98
+ Uniqueness is achieved through:
99
+
100
+ - Cryptographically secure random bytes
101
+ - High-entropy alphabet (64 URL-safe characters)
102
+ - Configurable ID length
103
+
104
+ ## Collision probability
105
+
106
+ With default settings:
107
+
108
+ - Alphabet size: 64
109
+ - Length: 21 characters
110
+ - Entropy: 126 bits
111
+
112
+ This makes collision probability astronomically low, even with millions or billions of generated IDs.
113
+
114
+ ## 🧠 When to use idmint
115
+
116
+ - React keys
117
+ - Short URLs
118
+ - Client-side ID generation
119
+ - Temporary IDs before database insert
120
+ - Logs & request tracking
121
+ - Distributed systems (no coordination required)
122
+
123
+ ## 📄 License
124
+
125
+ MIT
126
+
127
+ ## â¤ī¸ Why idmint?
128
+
129
+ - uuid is long and unreadable
130
+ - nanoid is minimal by design
131
+
132
+ idmint focuses on clarity, flexibility, and enterprise readiness while remaining lightweight and easy to use.
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Generate a cryptographically secure unique ID
3
+ */
4
+ export declare function generateId(size?: number): string;
5
+ /**
6
+ * Generate ID with prefix (e.g. user_xxx)
7
+ */
8
+ export declare function generateIdWithPrefix(prefix: string, size?: number): string;
9
+ /**
10
+ * Time-sortable ID
11
+ */
12
+ export declare function timeBasedId(size?: number): string;
13
+ /**
14
+ * Presets
15
+ */
16
+ export declare const trueid: {
17
+ short: () => string;
18
+ medium: () => string;
19
+ long: () => string;
20
+ };
package/dist/index.js ADDED
@@ -0,0 +1,42 @@
1
+ import { randomBytes } from "crypto";
2
+ /**
3
+ * URL-safe alphabet (64 chars)
4
+ * Each character = 6 bits of entropy
5
+ */
6
+ const ALPHABET = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
7
+ /**
8
+ * Generate a cryptographically secure unique ID
9
+ */
10
+ export function generateId(size = 21) {
11
+ if (!Number.isInteger(size) || size < 4 || size > 64) {
12
+ throw new Error("size must be an integer between 4 and 64");
13
+ }
14
+ const bytes = randomBytes(size);
15
+ let id = "";
16
+ for (let i = 0; i < size; i++) {
17
+ id += ALPHABET[bytes[i] & 63];
18
+ }
19
+ return id;
20
+ }
21
+ /**
22
+ * Generate ID with prefix (e.g. user_xxx)
23
+ */
24
+ export function generateIdWithPrefix(prefix, size = 21) {
25
+ return `${prefix}_${generateId(size)}`;
26
+ }
27
+ /**
28
+ * Time-sortable ID
29
+ */
30
+ export function timeBasedId(size = 21) {
31
+ const time = Date.now().toString(36);
32
+ const randomPart = generateId(size - time.length);
33
+ return time + randomPart;
34
+ }
35
+ /**
36
+ * Presets
37
+ */
38
+ export const trueid = {
39
+ short: () => generateId(8),
40
+ medium: () => generateId(21),
41
+ long: () => generateId(32),
42
+ };
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "idmint",
3
+ "version": "1.0.0",
4
+ "description": "Enterprise-grade, collision-resistant unique ID generator",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc",
13
+ "dev": "ts-node src/index.ts"
14
+ },
15
+ "keywords": [
16
+ "unique-id",
17
+ "uid",
18
+ "nanoid",
19
+ "uuid",
20
+ "id-generator",
21
+ "short-id",
22
+ "enterprise",
23
+ "secure"
24
+ ],
25
+ "author": "Vikram Singh Rajpurohit",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "@types/node": "^25.0.3",
29
+ "ts-node": "^10.9.2",
30
+ "typescript": "^5.9.3"
31
+ }
32
+ }