genkode 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 CHANGED
@@ -1,11 +1,10 @@
1
- # genkode
1
+ # genkode - Random String & ID Generator for Node.js
2
2
 
3
3
  ![npm version](https://img.shields.io/npm/v/genkode)
4
4
  ![npm downloads](https://img.shields.io/npm/dw/genkode)
5
5
  ![license](https://img.shields.io/npm/l/genkode)
6
6
  ![types](https://img.shields.io/npm/types/genkode)
7
7
 
8
-
9
8
  A lightweight Node.js utility to generate random alphanumeric, alphabetic, or numeric strings.
10
9
  Fully compatible with TypeScript. No external dependencies.
11
10
 
@@ -21,61 +20,58 @@ npm install genkode
21
20
 
22
21
  ## 🚀 Usage
23
22
 
24
- ### 1. Generate Alphanumeric String
23
+ ### Generate using main API
25
24
 
26
25
  ```ts
27
- import { mumble } from 'genkode';
26
+ import { generateCode } from 'genkode';
27
+
28
+ generateCode({ length: 12 });
29
+ // Example: aZ8kL2pQ9xW1
28
30
 
29
- console.log(mumble(12));
31
+ generateCode({ length: 12, type: "alpha" });
32
+ // Example: rqfvYxJRWfoP
30
33
 
31
- // Example output:
32
- // vl6QLrr3xIBe
34
+ generateCode({ length: 12, type: "numeric" });
35
+ // Example: 362128126198
33
36
  ```
34
37
 
35
38
  ---
36
39
 
37
- ### 2. Generate Alphabet-only String
40
+ ### Simple helper functions
38
41
 
39
42
  ```ts
40
- import { mumblealpha } from 'genkode';
41
-
42
- console.log(mumblealpha(12));
43
+ import { randomString, randomAlpha, randomNumeric } from 'genkode';
43
44
 
44
- // Example output:
45
- // rqfvYxJRWfoP
45
+ randomString(12); // alphanumeric
46
+ randomAlpha(12); // alphabets only
47
+ randomNumeric(12); // numbers only
46
48
  ```
47
49
 
48
50
  ---
49
51
 
50
- ### 3. Generate Numeric String
51
-
52
- ```ts
53
- import { mumblenum } from 'genkode';
52
+ ## ⚙️ API
54
53
 
55
- console.log(mumblenum(12));
54
+ ### generateCode(options)
56
55
 
57
- // Example output:
58
- // 362128126198
59
- ```
56
+ | Property | Type | Description |
57
+ |----------|------|-------------|
58
+ | length | number | Required length of string |
59
+ | type | "alpha" \| "numeric" \| "alphanumeric" | Optional (default: alphanumeric) |
60
60
 
61
61
  ---
62
62
 
63
- ## ⚙️ API
63
+ ## Why genkode?
64
64
 
65
- | Function | Description |
66
- |----------------|--------------------------------------|
67
- | `mumble(n)` | Returns alphanumeric string |
68
- | `mumblealpha(n)`| Returns alphabet-only string |
69
- | `mumblenum(n)` | Returns numeric string |
70
-
71
- - `n` → Length of the required string
65
+ - Zero dependencies
66
+ - Fast and lightweight
67
+ - TypeScript support
68
+ - Simple and flexible API
69
+ - Multiple formats (alpha, numeric, alphanumeric)
72
70
 
73
71
  ---
74
72
 
75
73
  ## 🧩 Use Cases
76
74
 
77
- These generated strings can be used for:
78
-
79
75
  - Database IDs
80
76
  - Tokens / API keys
81
77
  - Session identifiers
@@ -86,21 +82,20 @@ These generated strings can be used for:
86
82
 
87
83
  ## 🔒 Notes
88
84
 
89
- - This package uses standard random generation (`Math.random`)
90
- - Suitable for general-purpose use
91
- - Not recommended for cryptographic/security-critical use cases
85
+ - Uses Math.random (not cryptographically secure)
86
+ - Suitable for general-purpose usage
92
87
 
93
88
  ---
94
89
 
95
90
  ## 🔗 Related Package
96
91
 
97
- This package is also available as a JavaScript-only version:
92
+ JavaScript-only version:
98
93
 
99
- **node-mumble** (by the same developer)
94
+ node-mumble (by same developer)
100
95
  https://www.npmjs.com/package/node-mumble
101
96
 
102
97
  ---
103
98
 
104
99
  ## 📄 License
105
100
 
106
- ISC
101
+ MIT
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export declare function mumble(input: number): string;
2
- export declare function mumbleaplha(input: number): string;
3
- export declare function mumblenum(input: number): string;
1
+ import type { GenerateCodeOptions } from "./kode.interface.js";
2
+ export declare function generateCode({ length, type }: GenerateCodeOptions): string;
3
+ export declare function randomString(length: number): string;
4
+ export declare function randomAlpha(length: number): string;
5
+ export declare function randomNumeric(length: number): string;
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAWA,wBAAgB,MAAM,CAAC,KAAK,EAAC,MAAM,GAAE,MAAM,CAS1C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAC,MAAM,GAAG,MAAM,CAWhD;AACD,wBAAgB,SAAS,CAAC,KAAK,EAAC,MAAM,GAAG,MAAM,CAW9C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAmB/D,wBAAgB,YAAY,CAAC,EAAE,MAAM,EAAE,IAAqB,EAAE,EAAE,mBAAmB,GAAG,MAAM,CAI3F;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAElD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEpD"}
package/dist/index.js CHANGED
@@ -1,42 +1,30 @@
1
- const arr = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
2
- function isLetter(s) {
3
- return s.match("^[a-zA-Z\(\)]+$");
1
+ const ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
2
+ const NUMERIC = "0123456789";
3
+ const ALPHANUM = ALPHA + NUMERIC;
4
+ function generate(length, charset) {
5
+ let result = "";
6
+ const max = charset.length;
7
+ while (length > 0) {
8
+ const index = Math.floor(Math.random() * max);
9
+ result += charset[index];
10
+ length--;
11
+ }
12
+ return result;
4
13
  }
5
- function isNumeric(s) {
6
- return s.match("^[0-9\(\)]+$");
14
+ export function generateCode({ length, type = "alphanumeric" }) {
15
+ if (type === "alpha")
16
+ return generate(length, ALPHA);
17
+ if (type === "numeric")
18
+ return generate(length, NUMERIC);
19
+ return generate(length, ALPHANUM);
7
20
  }
8
- export function mumble(input) {
9
- let uniqString = "";
10
- const length = arr.length;
11
- while (input != 0) {
12
- const randomIndex = Math.floor(Math.random() * length);
13
- uniqString = uniqString + arr[randomIndex];
14
- input = input - 1;
15
- }
16
- return uniqString;
21
+ export function randomString(length) {
22
+ return generate(length, ALPHANUM);
17
23
  }
18
- export function mumbleaplha(input) {
19
- let uniqString = "";
20
- const length = arr.length;
21
- while (input != 0) {
22
- const randomIndex = Math.floor(Math.random() * length);
23
- if (isLetter(arr[randomIndex])) {
24
- uniqString = uniqString + arr[randomIndex];
25
- input = input - 1;
26
- }
27
- }
28
- return uniqString;
24
+ export function randomAlpha(length) {
25
+ return generate(length, ALPHA);
29
26
  }
30
- export function mumblenum(input) {
31
- let uniqString = "";
32
- const length = arr.length;
33
- while (input != 0) {
34
- const randomIndex = Math.floor(Math.random() * length);
35
- if (isNumeric(arr[randomIndex])) {
36
- uniqString = uniqString + arr[randomIndex];
37
- input = input - 1;
38
- }
39
- }
40
- return uniqString;
27
+ export function randomNumeric(length) {
28
+ return generate(length, NUMERIC);
41
29
  }
42
30
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,MAAM,GAAG,GAAG,CAAC,GAAG,EAAC,GAAG,EAAC,GAAG,EAAC,GAAG,EAAC,GAAG,EAAC,GAAG,EAAC,GAAG,EAAC,GAAG,EAAC,GAAG,EAAC,GAAG,EAAC,GAAG,EAAC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AC;IAChB,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAE3B,OAAO,MAAM,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC;QAC9C,MAAM,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;QACzB,MAAM,EAAE,CAAC;IACX,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,EAAE,MAAM,EAAE,IAAI,GAAG,cAAc,EAAuB;IACjF,IAAI,IAAI,KAAK,OAAO;QAAE,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACrD,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACzD,OAAO,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAc;IACzC,OAAO,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,OAAO,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACnC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export interface GenerateCodeOptions {
2
+ length: number;
3
+ type?: "alpha" | "numeric" | "alphanumeric";
4
+ }
5
+ //# sourceMappingURL=kode.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kode.interface.d.ts","sourceRoot":"","sources":["../kode.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,cAAc,CAAC;CAC7C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=kode.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kode.interface.js","sourceRoot":"","sources":["../kode.interface.ts"],"names":[],"mappings":""}
package/index.ts CHANGED
@@ -1,46 +1,36 @@
1
- const arr = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];
1
+ import type { GenerateCodeOptions } from "./kode.interface.js";
2
2
 
3
- function isLetter(s:string)
4
- {
5
- return s.match("^[a-zA-Z\(\)]+$");
3
+ const ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
4
+ const NUMERIC = "0123456789";
5
+ const ALPHANUM = ALPHA + NUMERIC;
6
+
7
+ function generate(length: number, charset: string): string {
8
+ let result = "";
9
+ const max = charset.length;
10
+
11
+ while (length > 0) {
12
+ const index = Math.floor(Math.random() * max);
13
+ result += charset[index];
14
+ length--;
15
+ }
16
+
17
+ return result;
6
18
  }
7
- function isNumeric(s:string)
8
- {
9
- return s.match("^[0-9\(\)]+$");
19
+
20
+ export function generateCode({ length, type = "alphanumeric" }: GenerateCodeOptions): string {
21
+ if (type === "alpha") return generate(length, ALPHA);
22
+ if (type === "numeric") return generate(length, NUMERIC);
23
+ return generate(length, ALPHANUM);
10
24
  }
11
25
 
12
- export function mumble(input:number):string {
13
- let uniqString = "";
14
- const length = arr.length
15
- while (input!=0) {
16
- const randomIndex = Math.floor(Math.random()*length)
17
- uniqString = uniqString+arr[randomIndex];
18
- input = input - 1;
19
- }
20
- return uniqString
26
+ export function randomString(length: number): string {
27
+ return generate(length, ALPHANUM);
21
28
  }
22
29
 
23
- export function mumbleaplha(input:number): string {
24
- let uniqString = "";
25
- const length = arr.length
26
- while (input!=0) {
27
- const randomIndex = Math.floor(Math.random()*length)
28
- if(isLetter(arr[randomIndex]!)){
29
- uniqString = uniqString+arr[randomIndex];
30
- input = input - 1;
31
- }
32
- }
33
- return uniqString
30
+ export function randomAlpha(length: number): string {
31
+ return generate(length, ALPHA);
34
32
  }
35
- export function mumblenum(input:number): string {
36
- let uniqString = "";
37
- const length = arr.length
38
- while (input!=0) {
39
- const randomIndex = Math.floor(Math.random()*length)
40
- if(isNumeric(arr[randomIndex]!)){
41
- uniqString = uniqString+arr[randomIndex];
42
- input = input - 1;
43
- }
44
- }
45
- return uniqString
33
+
34
+ export function randomNumeric(length: number): string {
35
+ return generate(length, NUMERIC);
46
36
  }
@@ -0,0 +1,4 @@
1
+ export interface GenerateCodeOptions {
2
+ length: number;
3
+ type?: "alpha" | "numeric" | "alphanumeric";
4
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "genkode",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "A node package that creates a random unique characters string (Typescript Supported)",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,15 +15,29 @@
15
15
  },
16
16
  "keywords": [
17
17
  "random",
18
- "string",
19
- "generator",
20
- "id",
18
+ "random-string",
19
+ "string-generator",
20
+ "random-id",
21
+ "id-generator",
21
22
  "token",
22
- "alphanumeric"
23
+ "token-generator",
24
+ "alphanumeric",
25
+ "alphabet",
26
+ "numeric",
27
+ "random-code",
28
+ "code-generator",
29
+ "unique-id",
30
+ "lightweight",
31
+ "zero-dependency",
32
+ "typescript",
33
+ "nodejs",
34
+ "utility"
23
35
  ],
24
36
  "author": "",
25
37
  "license": "MIT",
26
38
  "devDependencies": {
39
+ "tsx": "^4.21.0",
40
+ "txc": "^0.0.1",
27
41
  "typescript": "^6.0.2"
28
42
  },
29
43
  "bugs": {