hindicode 1.0.2 → 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/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 ADDED
@@ -0,0 +1,241 @@
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! ❤️**
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
@@ -91,54 +91,49 @@ const hindiToJS = {
91
91
  "NaN": "NaN",
92
92
  "कोड": "code",
93
93
  "संदेश": "message",
94
+ "असांयकालिक": "async",
95
+ "त्रुटि": "Error",
94
96
  };
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
- // };
97
+
108
98
  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
- });
99
+ const sortedKeywords = Object.keys(hindiToJS).sort((a, b) => b.length - a.length);
100
+
101
+ const parts = [
102
+ /(?<BLOCK>\/\*[\s\S]*?\*\/)/.source,
103
+ /(?<LINE>\/\/.*)/.source,
104
+ /(?<STRING_DBL>"(?:[^"\\]|\\.)*")/.source,
105
+ /(?<STRING_SGL>'(?:[^'\\]|\\.)*')/.source,
106
+ /(?<BACKTICK>`[\s\S]*?`)/.source,
107
+ /(?<REGEX>\/(?![*\/])(?:[^\/\\\n]|\\.)*?\/[gimuy]*)/.source,
108
+ `(?<KEYWORD>(?<![\\u0900-\\u097F])(?:${sortedKeywords.join("|")})(?![\\u0900-\\u097F]))`
109
+ ];
110
+
111
+ const masterRegex = new RegExp(parts.join("|"), "g");
115
112
 
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);
113
+ return code.replace(masterRegex, (...args) => {
114
+ const groups = args[args.length - 1];
115
+ const { BACKTICK, KEYWORD } = groups;
116
+
117
+ if (KEYWORD && hindiToJS[KEYWORD]) {
118
+ return hindiToJS[KEYWORD];
124
119
  }
125
- });
126
120
 
127
- // अब स्ट्रिंग्स को वापस लाओ
128
- code = code.replace(/___STR(\d+)___/g, (_, index) => stringLiterals[parseInt(index)]);
129
- console.log(code);
130
- return code;
131
- }
121
+ if (BACKTICK) {
122
+ return BACKTICK.replace(/\${([\s\S]*?)}/g, (m, inner) => {
123
+ return `${"$"}{${translateHindiJS(inner)}}`;
124
+ });
125
+ }
132
126
 
127
+ return args[0];
128
+ });
129
+ }
133
130
 
134
131
  // Custom require hook for `.hindi.js` files
135
132
  require.extensions[".hindi.js"] = function (module, filename) {
136
133
  try {
137
134
  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'
135
+ content = translateHindiJS(content);
136
+ module._compile(content, filename);
142
137
 
143
138
 
144
139
  // Run translated JavaScript code
@@ -147,3 +142,5 @@ require.extensions[".hindi.js"] = function (module, filename) {
147
142
  console.error("❌ Hindi Transpiler Error:", error);
148
143
  }
149
144
  };
145
+
146
+ module.exports = { translateHindiJS };
package/package.json CHANGED
@@ -1,12 +1,42 @@
1
1
  {
2
2
  "name": "hindicode",
3
- "version": "1.0.2",
3
+ "version": "1.1.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
  }