hindicode 1.0.3 → 1.2.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.
Files changed (5) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -241
  3. package/index.d.ts +5 -0
  4. package/index.js +232 -149
  5. package/package.json +34 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ujjwal Dadhich
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,241 +1,97 @@
1
- # HindiCode - हिंदी में जावास्क्रिप्ट लिखें! 🚀
2
-
3
- ## परिचय
4
- **HindiCode** एक अनोखा NPM पैकेज है जो आपको **हिंदी में जावास्क्रिप्ट** लिखने की सुविधा देता है। यह कोड को रन-टाइम पर **हिंदी से जावास्क्रिप्ट** में परिवर्तित करता है ताकि आप **JavaScript के कीवर्ड्स हिंदी में** लिख सकें!
5
-
6
- 🔹 **दृष्टांत:**
7
- ```hindi
8
- स्थिर x = 10;
9
- अगर (x > 5) {
10
- दिखाओ("x बड़ा है!");
11
- } अन्यथा {
12
- दिखाओ("x छोटा है!");
13
- }
14
- ```
15
- **परिवर्तित जावास्क्रिप्ट कोड:**
16
- ```javascript
17
- const x = 10;
18
- if (x > 5) {
19
- console.log("x बड़ा है!");
20
- } else {
21
- console.log("x छोटा है!");
22
- }
23
- ```
24
-
25
- ---
26
-
27
- ## 📌 विशेषताएँ
28
- **हिंदी में कोडिंग:** जावास्क्रिप्ट के कीवर्ड्स हिंदी में!
29
- **रन-टाइम ट्रांसपाइलर:** `.hindi.js` फ़ाइल को डायरेक्ट रन करें।
30
- **स्ट्रिंग्स सुरक्षित:** कोड में लिखे हुए टेक्स्ट को अनछुए रखता है।
31
- ✔ **सिंपल सेटअप:** बस इंस्टॉल करें और उपयोग करें!
32
-
33
- ---
34
-
35
- ## 🔧 इंस्टॉलेशन
36
- ```sh
37
- npm install -g hindicode
38
- ```
39
-
40
- ---
41
-
42
- ## 🚀 उपयोग कैसे करें?
43
-
44
- ### **1️⃣ हिंदी कोड लिखें**
45
- `.hindi.js` फाइल बनाएं और हिंदी में जावास्क्रिप्ट लिखें:
46
- ```hindi
47
- // test.hindi.js
48
- स्थिर संख्या = 42;
49
- दिखाओ("संख्या है:", संख्या);
50
-
51
- कार्य जोड़ो(क, ख) {
52
- लौटाओ क + ख;
53
- }
54
-
55
- दिखाओ("जोड़:", जोड़ो(5, 7));
56
- ```
57
-
58
- ### **2️⃣ सीधे चलाएँ**
59
- ```sh
60
-
61
- node test.hindi.js
62
- or
63
- node hindicode test.hindi.js
64
-
65
-
66
- आउटपुट:
67
- ```
68
- संख्या है: 42
69
- जोड़: 12
70
- ```
71
-
72
- ---
73
-
74
- ## 🔍 कैसे काम करता है?
75
- **HindiCode** रन-टाइम पर `.hindi.js` फ़ाइल को लोड करता है और उसमें लिखे गए **हिंदी कीवर्ड्स को जावास्क्रिप्ट में** बदलकर उसे रन करता है।
76
-
77
- ```javascript
78
- require.extensions[".hindi.js"] = function (module, filename) {
79
- let content = fs.readFileSync(filename, "utf8").trim();
80
- content = translateHindiJS(content);
81
- module._compile(content, filename);
82
- };
83
- ```
84
-
85
- ---
86
-
87
- ## 📖 हिंदी से जावास्क्रिप्ट कीवर्ड्स मैपिंग
88
- | **हिंदी** | **जावास्क्रिप्ट** |
89
- |-----------|------------------|
90
- | अगर | if |
91
- | अन्यथा | else |
92
- | दिखाओ | console.log |
93
- | कार्य | function |
94
- | लौटाओ | return |
95
- | चलाओ | for |
96
- | जबतक | while |
97
- | नया | let |
98
- | स्थिर | const |
99
- | परिभाषा | var |
100
- | सही | true |
101
- | गलत | false |
102
-
103
-
104
-
105
- ---
106
-
107
- ## 💖 सहयोग करें!
108
- अगर आपको **HindiCode** पसंद आया हो, तो हमारे प्रोजेक्ट को **सपोर्ट** करें!
109
- 👉 [डोनेट करें - Patreon](https://www.patreon.com/c/BABU_ISHU)
110
-
111
- ---
112
-
113
- ## 📜 लाइसेंस
114
- यह प्रोजेक्ट **MIT लाइसेंस** के अंतर्गत जारी किया गया है।
115
- आप इसे फ्री में उपयोग कर सकते हैं, लेकिन इसका सही उपयोग करें! 😊
116
-
117
- ---
118
-
119
- ## 🚀 योगदान करें
120
- अगर आपके पास कोई सुझाव या नया फ़ीचर जोड़ना चाहते हैं, तो GitHub पर PR भेजें!
121
- **Happy Coding! ❤️**
122
-
123
- # HindiCode - Write JavaScript in Hindi! 🚀
124
-
125
- ## Introduction
126
- **HindiCode** is an NPM package that allows you to **write JavaScript in Hindi**. It transpiles **Hindi keywords into JavaScript** at runtime, enabling you to code in Hindi seamlessly!
127
-
128
- 🔹 **Example:**
129
- ```hindi
130
- स्थिर x = 10;
131
- अगर (x > 5) {
132
- दिखाओ("x बड़ा है!");
133
- } अन्यथा {
134
- दिखाओ("x छोटा है!");
135
- }
136
- ```
137
- ✅ **Transpiled JavaScript:**
138
- ```javascript
139
- const x = 10;
140
- if (x > 5) {
141
- console.log("x बड़ा है!");
142
- } else {
143
- console.log("x छोटा है!");
144
- }
145
- ```
146
-
147
- ---
148
-
149
- ## 📌 Features
150
- ✔ **Code in Hindi:** Use Hindi keywords instead of JavaScript ones.
151
- ✔ **Runtime Transpiler:** Run `.hindi.js` files directly.
152
- ✔ **String Protection:** Keeps your string content untouched.
153
- ✔ **Simple Setup:** Install and start using immediately.
154
-
155
- ---
156
-
157
- ## 🔧 Installation
158
- ```sh
159
- npm install -g hindicode
160
- ```
161
-
162
- ---
163
-
164
- ## 🚀 How to Use?
165
-
166
- ### **1️⃣ Write Hindi Code**
167
- Create a `.hindi.js` file and write JavaScript using Hindi keywords:
168
- ```hindi
169
- // test.hindi.js
170
- स्थिर संख्या = 42;
171
- दिखाओ("संख्या है:", संख्या);
172
-
173
- कार्य जोड़ो(क, ख) {
174
- लौटाओ क + ख;
175
- }
176
-
177
- दिखाओ("जोड़:", जोड़ो(5, 7));
178
- ```
179
-
180
- ### **2️⃣ Run Directly**
181
- ```sh
182
- node test.hindi.js
183
- or
184
- node hindicode test.hindi.js
185
- ```
186
- ✅ **Output:**
187
- ```
188
- संख्या है: 42
189
- जोड़: 12
190
- ```
191
-
192
- ---
193
-
194
- ## 🔍 How Does It Work?
195
- **HindiCode** hooks into Node.js and **transpiles Hindi keywords into JavaScript** at runtime before execution.
196
-
197
- ```javascript
198
- require.extensions[".hindi.js"] = function (module, filename) {
199
- let content = fs.readFileSync(filename, "utf8").trim();
200
- content = translateHindiJS(content);
201
- module._compile(content, filename);
202
- };
203
- ```
204
-
205
- ---
206
-
207
- ## 📖 Hindi to JavaScript Keyword Mapping
208
- | **Hindi** | **JavaScript** |
209
- |------------|--------------|
210
- | अगर | if |
211
- | अन्यथा | else |
212
- | दिखाओ | console.log |
213
- | कार्य | function |
214
- | लौटाओ | return |
215
- | चलाओ | for |
216
- | जबतक | while |
217
- | नया | let |
218
- | स्थिर | const |
219
- | परिभाषा | var |
220
- | सही | true |
221
- | गलत | false |
222
-
223
-
224
-
225
- ---
226
-
227
- ## 💖 Support Us!
228
- If you like **HindiCode**, consider supporting the project!
229
- 👉 [Donate on Patreon](https://www.patreon.com/c/BABU_ISHU)
230
-
231
- ---
232
-
233
- ## 📜 License
234
- This project is released under the **MIT License**.
235
- Feel free to use it responsibly! 😊
236
-
237
- ---
238
-
239
- ## 🚀 Contribute
240
- Have suggestions or want to add new features? Submit a PR on GitHub!
241
- **Happy Coding! ❤️**
1
+ # HindiCode - हिंदी में जावास्क्रिप्ट लिखें! 🚀
2
+ > Write JavaScript in Hindi with Industrial-Grade Robustness.
3
+
4
+ ---
5
+
6
+ ## 🌍 [HI] परिचय (Introduction)
7
+ **HindiCode** एक आधुनिक NPM पैकेज है जो आपको **हिंदी में जावास्क्रिप्ट** लिखने की सुविधा देता है। यह कोड को रन-टाइम पर पार्स करता है और हिंदी के कीवर्ड्स को जावास्क्रिप्ट में बदल देता है।
8
+
9
+ **HindiCode** is a modern NPM package that lets you **write JavaScript in Hindi**. It transpiles Hindi keywords into JavaScript at runtime, enabling a seamless native coding experience.
10
+
11
+ ### 🔹 Example (उदाहरण)
12
+ ```javascript
13
+ स्थिर x = 10;
14
+ अगर (x > 5) {
15
+ दिखाओ("x बड़ा है!");
16
+ } अन्यथा {
17
+ दिखाओ("x छोटा है!");
18
+ }
19
+ ```
20
+
21
+ ---
22
+
23
+ ## 🌟 Features (विशेषताएँ)
24
+ - **Industrial-Grade Protection**:
25
+ - **🛡️ Comment Protection**: Keywords inside `//` or `/* */` are never translated.
26
+ - **🛡️ String Protection**: Your text inside `" "` or `' '` stays exactly as written.
27
+ - **🛡️ Regex Protection**: Search patterns like `/अगर/g` are preserved perfectly.
28
+ - **Smart Template Literals**: Supports full `${}` interpolation with recursive translation.
29
+ - **Unicode Boundaries**: Professional word boundaries ensure `नम` doesn't break `नमस्ते`.
30
+ - **Zero Configuration**: Just register the hook and run `.hindi.js` files.
31
+
32
+ ---
33
+
34
+ ## 🔧 Installation (स्थापना)
35
+ ```sh
36
+ npm install hindicode
37
+ ```
38
+
39
+ ---
40
+
41
+ ## 🚀 Usage (उपयोग)
42
+
43
+ ### 1. Register the Transpiler
44
+ Add this to your entry point (e.g., `index.js`):
45
+ ```javascript
46
+ require('hindicode');
47
+ require('./your-file.hindi.js');
48
+ ```
49
+
50
+ ### 2. Write in Hindi (`.hindi.js`)
51
+ ```javascript
52
+ // app.hindi.js
53
+ नया नाम = "अर्जुन";
54
+ दिखाओ(`नमस्ते ${नाम}!`);
55
+
56
+ कार्य जोड़(अ, ब) {
57
+ लौटाओ अ + ब;
58
+ }
59
+
60
+ दिखाओ("योग:", जोड़(10, 20));
61
+ ```
62
+
63
+ ---
64
+
65
+ ## 📖 Keyword Mapping (कीवर्ड्स)
66
+ | Hindi | JavaScript | Hindi | JavaScript |
67
+ | :--- | :--- | :--- | :--- |
68
+ | अगर | if | अन्य | else |
69
+ | दिखाओ | console.log | कार्य | function |
70
+ | लौटाओ | return | चलाओ | for |
71
+ | जबतक | while | नया | let |
72
+ | स्थिर | const | सही | true |
73
+ | गलत | false | असांयकालिक | async |
74
+ | प्रतीक्षा | await | त्रुटि | Error |
75
+
76
+ *(Check `index.js` for the full dictionary of over 90+ terms!)*
77
+
78
+ ---
79
+
80
+ ## 🗺️ Roadmap (भविष्य की योजना)
81
+ - [ ] **Hindi Variables**: Support for non-keyword Hindi tokens as identifiers.
82
+ - [ ] **Hindi CLI**: A dedicated runner (`hindicode my-file.hindi.js`).
83
+ - [ ] **VS Code Extension**: Syntax highlighting and snippets for `.hindi.js`.
84
+ - [ ] **Hindi Error Messages**: Localized compiler errors.
85
+ - [ ] **Hindi-DOM**: Support for `दस्तावेज़` (document) and `खिड़की` (window).
86
+
87
+ ---
88
+
89
+ ## 💖 Contribute (योगदान)
90
+ We welcome contributions! Star the repo and join the movement to make coding accessible in every language.
91
+
92
+ 👉 **Support Us**: [Patreon](https://www.patreon.com/c/BABU_ISHU)
93
+
94
+ ---
95
+
96
+ ## 📜 License
97
+ Released under the **MIT License**. 😊
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Transpiles Hindi JavaScript code to standard JavaScript.
3
+ * @param code - The Hindi JavaScript code string.
4
+ */
5
+ export function translateHindiJS(code: string): string;
package/index.js CHANGED
@@ -1,149 +1,232 @@
1
- const fs = require("fs");
2
- const Module = require("module");
3
- const path = require("path");
4
- const hindiToJS = {
5
- "अगर": "if",
6
- "अन्यथा": "else",
7
- "दिखाओ": "console.log",
8
- "कार्य": "function",
9
- "लौटाओ": "return",
10
- "चलाओ": "for",
11
- "जबतक": "while",
12
- "नया": "let",
13
- "स्थिर": "const",
14
- "परिभाषा": "var",
15
- "सही": "true",
16
- "गलत": "false",
17
- "शून्य": "null",
18
- "प्रयास": "try",
19
- "पकड़ो": "catch",
20
- "अंततः": "finally",
21
- "फेंको": "throw",
22
- "वर्ग": "class",
23
- "विस्तार": "extends",
24
- "सुपर": "super",
25
- "वापसी": "yield",
26
- "प्रतीक्षा": "await",
27
- "आयात": "import",
28
- "निर्यात": "export",
29
- "डिफ़ॉल्ट": "default",
30
- "केस": "case",
31
- "ब्रेक": "break",
32
- "जारी": "continue",
33
- "स्विच": "switch",
34
- "केलिए": "for",
35
- "प्रत्येक": "forEach",
36
- "मानचित्र": "map",
37
- "फ़िल्टर": "filter",
38
- "कम करना": "reduce",
39
- "शामिल": "includes",
40
- "इंडेक्स": "indexOf",
41
- "पुश": "push",
42
- "पॉप": "pop",
43
- "शिफ्ट": "shift",
44
- "अनशिफ्ट": "unshift",
45
- "splice": "splice",
46
- "concat": "concat",
47
- "स्लाइस": "slice",
48
- "लंबाई": "length",
49
- "प्रकार": "typeof",
50
- "उदाहरण": "instanceof",
51
- "में": "in",
52
- "नयाउदाहरण": "new",
53
- "हटाना": "delete",
54
- "शून्य करना": "void",
55
- "साथ": "with",
56
- "डीबग": "debugger",
57
- "लेबल": "label",
58
- "कोशिश": "try",
59
- "ये": "this",
60
- "प्रोटो": "prototype",
61
- "कॉल": "call",
62
- "लागू": "apply",
63
- "बाध्य": "bind",
64
- "अर्जुन": "arguments",
65
- "बनाएँ": "create",
66
- "कुंजी": "key",
67
- "मूल्य": "value",
68
- "प्रविष्टि": "entry",
69
- "सेट": "set",
70
- "प्राप्त": "get",
71
- "है": "has",
72
- "साफ़": "clear",
73
- "आकार": "size",
74
- "फिर": "then",
75
- "पकड़": "catch",
76
- "अंत में": "finally",
77
- "सभी": "all",
78
- "रेस": "race",
79
- "हल": "resolve",
80
- "अस्वीकार": "reject",
81
- "से": "from",
82
- "एक": "as",
83
- "नम": "name",
84
- "भेजें": "send",
85
- "प्राप्त": "receive",
86
- "कनेक्ट": "connect",
87
- "सुनो": "listen",
88
- "सर्वर": "server",
89
- "ग्राहक": "client",
90
- "अनंत": "Infinity",
91
- "NaN": "NaN",
92
- "कोड": "code",
93
- "संदेश": "message",
94
- };
95
- // // Hindi to JavaScript keyword mapping
96
- // const hindiToJS = {
97
- // "अगर": "if",
98
- // "अन्यथा": "else",
99
- // "दिखाओ": "console.log",
100
- // "कार्य": "function",
101
- // "लौटाओ": "return",
102
- // "चलाओ": "for",
103
- // "जबतक": "while",
104
- // "नया": "let",
105
- // "स्थिर": "const",
106
- // "परिभाषा": "var"
107
- // };
108
- function translateHindiJS(code) {
109
- // स्ट्रिंग्स को प्रोटेक्ट करने के लिए, पहले उन्हें अलग कर लें
110
- let stringLiterals = [];
111
- code = code.replace(/(["'`])((?:\\\1|.)*?)\1/g, (match) => {
112
- stringLiterals.push(match); // स्ट्रिंग सेव कर लो
113
- return `___STR${stringLiterals.length - 1}___`; // प्लेसहोल्डर डाल दो
114
- });
115
-
116
- // अब सिर्फ जावास्क्रिप्ट केवर्ड्स को ही ट्रांसलेट करो
117
- Object.entries(hindiToJS).forEach(([hindi, js]) => {
118
- if (hindi === "नाम") {
119
- // 'this.नाम' और 'let नाम' को नहीं बदलना
120
- code = code.replace(/([^.\w])नाम([^.\w])/g, `$1name$2`);
121
- } else {
122
- const regex = new RegExp(`(?<![\\u00BF-\\u1FFF\\u2C00-\\uD7FF\\w])${hindi}(?![\\u00BF-\\u1FFF\\u2C00-\\uD7FF\\w])`, "g");
123
- code = code.replace(regex, js);
124
- }
125
- });
126
-
127
- // अब स्ट्रिंग्स को वापस लाओ
128
- code = code.replace(/___STR(\d+)___/g, (_, index) => stringLiterals[parseInt(index)]);
129
- console.log(code);
130
- return code;
131
- }
132
-
133
-
134
- // Custom require hook for `.hindi.js` files
135
- require.extensions[".hindi.js"] = function (module, filename) {
136
- try {
137
- let content = fs.readFileSync(filename, "utf8").trim();
138
-
139
-
140
- // Translate Hindi to JavaScript
141
- content = translateHindiJS(content); // Assign the returned value back to 'content'
142
-
143
-
144
- // Run translated JavaScript code
145
- module._compile(content, filename);
146
- } catch (error) {
147
- console.error(" Hindi Transpiler Error:", error);
148
- }
149
- };
1
+ const fs = require("fs");
2
+ const Module = require("module");
3
+ const path = require("path");
4
+
5
+ const hindiToJS = {
6
+ // ── Multi-word phrases FIRST (longest → shortest to avoid partial matches) ──
7
+ "नहीं तो": "else",
8
+ "के रूप में": "as",
9
+ "का प्रकार": "typeof",
10
+ "नया बनाओ": "new",
11
+ "कम या बराबर": "<=",
12
+ "ज्यादा या बराबर": ">=",
13
+ "बराबर नहीं": "!==",
14
+
15
+ // ── Control Flow ─────────────────────────────────
16
+ "अगर": "if",
17
+ "वरना": "else",
18
+ "करो": "do",
19
+ "जबतक": "while",
20
+ "केलिए": "for",
21
+ "स्विच": "switch",
22
+ "मामला": "case",
23
+ "रोकें": "break",
24
+ "जारी": "continue",
25
+ "लौटाओ": "return",
26
+ "फेंको": "throw",
27
+
28
+ // ── Declarations ─────────────────────────────────
29
+ "नया": "let",
30
+ "स्थिर": "const",
31
+ "पुराना": "var",
32
+ "कार्य": "function",
33
+ "वर्ग": "class",
34
+
35
+ // ── Async ─────────────────────────────────────────
36
+ "असिंक": "async",
37
+ "इंतज़ार": "await",
38
+
39
+ // ── Literals ─────────────────────────────────────
40
+ "सच": "true",
41
+ "झूठ": "false",
42
+ "खाली": "null",
43
+ "अपरिभाषित": "undefined",
44
+
45
+ // ── OOP ──────────────────────────────────────────
46
+ "विस्तार": "extends",
47
+ "सुपर": "super",
48
+ "यह": "this",
49
+ "हटाओ": "delete",
50
+ "प्रोटो": "prototype",
51
+ "में": "in",
52
+ "सत्यापित": "instanceof",
53
+ "वापसी": "yield",
54
+
55
+ // ── Modules ──────────────────────────────────────
56
+ "आयात": "import",
57
+ "निर्यात": "export",
58
+ "डिफ़ॉल्ट": "default",
59
+ "से": "from",
60
+ "मांगो": "require",
61
+ "मॉड्यूल": "module",
62
+
63
+ // ── Operators ────────────────────────────────────
64
+ "और": "&&",
65
+ "या": "||",
66
+ "नहीं": "!",
67
+ "बराबर": "===",
68
+ "छोटा": "<",
69
+ "बड़ा": ">",
70
+
71
+ // ── Error Handling ────────────────────────────────
72
+ "कोशिश": "try",
73
+ "पकड़ो": "catch",
74
+ "पकड़": "catch",
75
+ "अंततः": "finally",
76
+ "त्रुटि": "Error",
77
+
78
+ // ── Console ──────────────────────────────────────
79
+ "दिखाओ": "console.log",
80
+ "गलती": "console.error",
81
+ "चेतावनी": "console.warn",
82
+ "जानकारी": "console.info",
83
+ "कंसोल": "console",
84
+
85
+ // ── Array Methods ────────────────────────────────
86
+ "पुश": "push",
87
+ "पॉप": "pop",
88
+ "शिफ्ट": "shift",
89
+ "अनशिफ्ट": "unshift",
90
+ "स्लाइस": "slice",
91
+ "जोड़ो": "concat",
92
+ "शामिल": "includes",
93
+ "ढूँढो": "find",
94
+ "मानचित्र": "map",
95
+ "फ़िल्टर": "filter",
96
+ "कमकरो": "reduce",
97
+ "हरएक": "forEach",
98
+ "लंबाई": "length",
99
+ "इंडेक्स": "indexOf",
100
+ "उलटाओ": "reverse",
101
+ "क्रमित": "sort",
102
+
103
+ // ── Object Methods ────────────────────────────────
104
+ "कुंजियाँ": "keys",
105
+ "मूल्य": "values",
106
+ "प्रविष्टियाँ": "entries",
107
+ "बनाएँ": "create",
108
+ "मिलाओ": "assign",
109
+ "जमाओ": "freeze",
110
+
111
+ // ── Map / Set ─────────────────────────────────────
112
+ "नक्शा": "Map",
113
+ "है": "has",
114
+ "प्राप्त": "get",
115
+ "रखो": "set",
116
+ "साफ़": "clear",
117
+ "आकार": "size",
118
+
119
+ // ── Promise ───────────────────────────────────────
120
+ "फिर": "then",
121
+ "सभी": "all",
122
+ "हल": "resolve",
123
+ "अस्वीकार": "reject",
124
+ "प्रॉमिस": "Promise",
125
+
126
+ // ── Browser APIs ──────────────────────────────────
127
+ "विंडो": "window",
128
+ "दस्तावेज": "document",
129
+ "ब्राउज़र": "navigator",
130
+ "स्थान": "location",
131
+ "इतिहास": "history",
132
+ "संग्रह": "localStorage",
133
+ "सत्र_संग्रह": "sessionStorage",
134
+ "चेतावनी_डिब्बा": "alert",
135
+ "पूछो": "prompt",
136
+ "पक्का_करो": "confirm",
137
+ "लाओ": "fetch",
138
+ "समय_बाद": "setTimeout",
139
+ "बार_बार": "setInterval",
140
+ "समय_रोकें": "clearTimeout",
141
+ "बार_रोकें": "clearInterval",
142
+
143
+ // ── Node.js ───────────────────────────────────────
144
+ "प्रक्रिया": "process",
145
+ "__नाम": "__filename",
146
+ "__डायरेक्टरी": "__dirname",
147
+ "बफर": "Buffer",
148
+
149
+ // ── Built-ins ─────────────────────────────────────
150
+ "ऑब्जेक्ट": "Object",
151
+ "ऐरे": "Array",
152
+ "टेक्स्ट": "String",
153
+ "नंबर": "Number",
154
+ "बूलियन": "Boolean",
155
+ "तारीख": "Date",
156
+ "गणित": "Math",
157
+ "जेसन": "JSON",
158
+ "रेगएक्स": "RegExp",
159
+ "अनंत": "Infinity",
160
+
161
+ // ── Math Shortcuts ────────────────────────────────
162
+ "गोलाई": "Math.round",
163
+ "ऊपर": "Math.ceil",
164
+ "नीचे": "Math.floor",
165
+ "अधिकतम": "Math.max",
166
+ "न्यूनतम": "Math.min",
167
+ "यादृच्छ": "Math.random",
168
+ "वर्गमूल": "Math.sqrt",
169
+ "पाई": "Math.PI",
170
+
171
+ // ── JSON Shortcuts ────────────────────────────────
172
+ "पार्स": "JSON.parse",
173
+ "तार_बनाओ": "JSON.stringify",
174
+
175
+ // ── String Methods ────────────────────────────────
176
+ "बड़े_अक्षर": "toUpperCase",
177
+ "छोटे_अक्षर": "toLowerCase",
178
+ "काटो": "trim",
179
+ "विभाजन": "split",
180
+ "बदलो": "replace",
181
+ "खोजो": "search",
182
+ "शुरू_से": "startsWith",
183
+ "खत्म_से": "endsWith",
184
+ "दोहराओ": "repeat",
185
+ "हिस्सा": "substring",
186
+ };
187
+
188
+ function translateHindiJS(code) {
189
+ const sortedKeywords = Object.keys(hindiToJS).sort((a, b) => b.length - a.length);
190
+
191
+ const parts = [
192
+ /(?<BLOCK>\/\*[\s\S]*?\*\/)/.source,
193
+ /(?<LINE>\/\/.*)/.source,
194
+ /(?<STRING_DBL>"(?:[^"\\]|\\.)*")/.source,
195
+ /(?<STRING_SGL>'(?:[^'\\]|\\.)*')/.source,
196
+ /(?<BACKTICK>`[\s\S]*?`)/.source,
197
+ /(?<REGEX>\/(?![*\/])(?:[^\/\\\n]|\\.)*?\/[gimuy]*)/.source,
198
+ `(?<KEYWORD>(?<![\\u0900-\\u097F])(?:${sortedKeywords.join("|")})(?![\\u0900-\\u097F]))`
199
+ ];
200
+
201
+ const masterRegex = new RegExp(parts.join("|"), "g");
202
+
203
+ return code.replace(masterRegex, (...args) => {
204
+ const groups = args[args.length - 1];
205
+ const { BACKTICK, KEYWORD } = groups;
206
+
207
+ if (KEYWORD && hindiToJS[KEYWORD]) {
208
+ return hindiToJS[KEYWORD];
209
+ }
210
+
211
+ if (BACKTICK) {
212
+ return BACKTICK.replace(/\${([\s\S]*?)}/g, (m, inner) => {
213
+ return `${"$"}{${translateHindiJS(inner)}}`;
214
+ });
215
+ }
216
+
217
+ return args[0];
218
+ });
219
+ }
220
+
221
+ // Custom require hook for `.hindi.js` files
222
+ require.extensions[".hindi.js"] = function (module, filename) {
223
+ try {
224
+ let content = fs.readFileSync(filename, "utf8").trim();
225
+ content = translateHindiJS(content);
226
+ module._compile(content, filename);
227
+ } catch (error) {
228
+ console.error("❌ Hindi Transpiler Error:", error);
229
+ }
230
+ };
231
+
232
+ module.exports = { translateHindiJS };
package/package.json CHANGED
@@ -1,12 +1,42 @@
1
1
  {
2
2
  "name": "hindicode",
3
- "version": "1.0.3",
3
+ "version": "1.2.0",
4
+ "description": "Run JavaScript with Hindi keywords",
4
5
  "main": "index.js",
6
+ "types": "index.d.ts",
5
7
  "scripts": {
6
8
  "test": "echo \"Error: no test specified\" && exit 1"
7
9
  },
8
- "keywords": [],
9
- "author": "",
10
+ "keywords": [
11
+ "hindi",
12
+ "javascript",
13
+ "transpiler",
14
+ "compiler",
15
+ "hindi-js",
16
+ "programming",
17
+ "education"
18
+ ],
19
+ "author": "Ujjwal-08",
10
20
  "license": "ISC",
11
- "description": "Run JavaScript with Hindi keywords"
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/Ujjwal-08/hindicode.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/Ujjwal-08/hindicode/issues"
27
+ },
28
+ "homepage": "https://github.com/Ujjwal-08/hindicode#readme",
29
+ "files": [
30
+ "index.js",
31
+ "index.d.ts",
32
+ "README.md",
33
+ "LICENSE"
34
+ ],
35
+ "devDependencies": {
36
+ "@semantic-release/commit-analyzer": "^13.0.1",
37
+ "@semantic-release/github": "^12.0.6",
38
+ "@semantic-release/npm": "^13.1.5",
39
+ "@semantic-release/release-notes-generator": "^14.1.0",
40
+ "semantic-release": "^25.0.3"
41
+ }
12
42
  }