idchunk 1.0.1 → 1.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 CHANGED
@@ -1,25 +1,100 @@
1
- # ⚡ idchunk — A Tiny, Fast & Customizable ID Generator
1
+ # ⚡ idchunk — Tiny, Fast & Customizable ID Generator
2
+
3
+ <table width="100%" border="0">
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="https://i.pinimg.com/736x/d0/68/64/d06864b8b20b18921e465d401fa605e4.jpg" alt="idchunk barcode" width="50" />
19
+ </a>
20
+ </td>
21
+ </tr>
22
+ </table>
2
23
 
3
- [![npm version](https://img.shields.io/npm/v/idchunk.svg)](https://www.npmjs.com/package/idchunk)
4
- [![downloads](https://img.shields.io/npm/dt/idchunk.svg)](https://www.npmjs.com/package/idchunk)
5
- [![license](https://img.shields.io/npm/l/idchunk.svg)](https://github.com/garvthakral/idchunk/blob/main/LICENSE)
6
24
 
7
25
  > Generate short, unique, and customizable IDs for your applications in milliseconds.
8
26
 
9
27
  ---
10
28
 
11
- ## Installation & Usage
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
12
39
 
13
40
  ```bash
14
41
  npm install idchunk
15
42
  ```
16
43
 
17
- By default the random generate id length is 10
44
+ ---
45
+
46
+ ## Usage
47
+
48
+ By default, `idchunk()` generates a random ID of length **10**:
49
+
50
+ ```js
51
+ const idchunk = require("idchunk");
18
52
 
53
+ console.log(idchunk()); // Example output: "aZ8_-kL2pQ"
19
54
  ```
55
+
56
+ You can specify a custom length:
57
+
58
+ ```js
20
59
  const idchunk = require("idchunk");
21
60
 
22
- console.log(idchunk());
61
+ console.log(idchunk(16)); // Example output: "bQ9pL2_-aZ8kL2pQ"
23
62
  ```
24
63
 
25
- And you can pass the value as the arguement to the idchunk(length) in number to generate the id
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,6 +1,6 @@
1
1
  {
2
2
  "name": "idchunk",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "A tiny, fast and customizable ID generator ",
5
5
  "main": "src/index.js",
6
6
  "keywords": [
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());