idchunk 1.0.0 → 1.1.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,100 @@
1
+ # ⚡ idchunk — Tiny, Fast & Customizable ID Generator
2
+
3
+ <table width="100%">
4
+ <tr>
5
+ <td>
6
+ <a href="https://www.npmjs.com/package/idchunk">
7
+ <img src="https://img.shields.io/npm/v/idchunk.svg" alt="npm version"/>
8
+ </a>
9
+ <a href="https://www.npmjs.com/package/idchunk">
10
+ <img src="https://img.shields.io/npm/dt/idchunk.svg" alt="downloads"/>
11
+ </a>
12
+ <a href="https://github.com/garvthakral/idchunk/blob/main/LICENSE">
13
+ <img src="https://img.shields.io/npm/l/idchunk.svg" alt="license"/>
14
+ </a>
15
+ </td>
16
+ <td>
17
+ <a href="https://idchunk.netlify.app/" onclick="window.open('https://idchunk.netlify.app/', '_blank'); return false;">
18
+ <img src="./id.png" alt="idchunk barcode" width="50" />
19
+ </a>
20
+ </td>
21
+ </tr>
22
+ </table>
23
+
24
+
25
+ > Generate short, unique, and customizable IDs for your applications in milliseconds.
26
+
27
+ ---
28
+
29
+ ## Features
30
+
31
+ - **Tiny:** Minimal footprint, zero dependencies.
32
+ - **Fast:** Uses Node.js `crypto` for secure random generation.
33
+ - **Customizable:** Specify ID length as needed.
34
+ - **Reliable:** Generates collision-resistant IDs.
35
+
36
+ ---
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ npm install idchunk
42
+ ```
43
+
44
+ ---
45
+
46
+ ## Usage
47
+
48
+ By default, `idchunk()` generates a random ID of length **10**:
49
+
50
+ ```js
51
+ const idchunk = require("idchunk");
52
+
53
+ console.log(idchunk()); // Example output: "aZ8_-kL2pQ"
54
+ ```
55
+
56
+ You can specify a custom length:
57
+
58
+ ```js
59
+ const idchunk = require("idchunk");
60
+
61
+ console.log(idchunk(16)); // Example output: "bQ9pL2_-aZ8kL2pQ"
62
+ ```
63
+
64
+ ---
65
+
66
+ ## API
67
+
68
+ ### `idchunk(length?: number): string`
69
+
70
+ - `length` (optional): Number. Length of the generated ID. Default is `10`.
71
+ - Returns: A random string ID.
72
+
73
+ ---
74
+
75
+ ## How It Works
76
+
77
+ - Uses Node.js [`crypto`](https://nodejs.org/api/crypto.html) for secure random number generation.
78
+ - Character set: `a-z`, `A-Z`, `0-9`, `_`, `-`.
79
+
80
+ ---
81
+
82
+ ## Testing
83
+
84
+ To test locally:
85
+
86
+ ```bash
87
+ node test/index.test.js
88
+ ```
89
+
90
+ ---
91
+
92
+ ## 📄 License
93
+
94
+ MIT © [Garv Thakral](https://github.com/codebygarv)
95
+
96
+ ---
97
+
98
+ ## Documentation
99
+
100
+ Read full documentation here : [**Read Docs**](https://idchunk.netlify.app/)
package/id.png ADDED
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "idchunk",
3
- "version": "1.0.0",
4
- "description": "A tiny, fast and customizable ID generator like NanoID.",
3
+ "version": "1.1.0",
4
+ "description": "A tiny, fast and customizable ID generator ",
5
5
  "main": "src/index.js",
6
6
  "keywords": [
7
7
  "id",
package/src/index.js CHANGED
@@ -1,14 +1,16 @@
1
1
  const values = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
2
+ const crypto = require('crypto');
2
3
 
3
- const idchunk = (length) =>{
4
+ const idchunk = (length) => {
4
5
  length = length || 10;
5
6
  let result = '';
6
7
  const valuesLength = values.length;
7
-
8
+
8
9
  for (let i = 0; i < length; i++) {
9
- result += values.charAt(Math.floor(Math.random() * valuesLength));
10
+ const randomIndex = crypto.randomInt(0, valuesLength);
11
+ result += values[randomIndex];
10
12
  }
11
-
13
+
12
14
  return result;
13
15
  }
14
16
 
@@ -1,3 +1,3 @@
1
1
  const idchunk = require('../src/index.js');
2
2
 
3
- console.log("Generated ID:", idchunk(6));
3
+ console.log("Generated ID:", idchunk());