kruti-unicode-converter 0.0.0-stage → 1.0.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.
Binary file
package/License ADDED
@@ -0,0 +1,11 @@
1
+
2
+ ---
3
+
4
+ ### 🚀 How to update it on GitHub:
5
+ 1. Go to your `kruti-unicode-converter` repo on GitHub.
6
+ 2. Click on the `README.md` file.
7
+ 3. Click the **Pencil icon** (Edit this file) in the top right.
8
+ 4. Delete everything currently in there, and paste the complete code above.
9
+ 5. Scroll down and click **Commit changes**.
10
+
11
+ Your README is now a perfect, professional-grade documentation page!
package/README.md CHANGED
@@ -1,3 +1,22 @@
1
- # Temporary Holding Version
1
+ # 🔄 Kruti Dev ↔ Unicode Converter
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A modern, standalone Node.js library and CLI tool to convert **Kruti Dev** font text to **Unicode** (Mangal) and vice versa.
4
+
5
+ ## ✨ Features
6
+ - **CLI Tool**: Convert files directly from your terminal.
7
+ - **Library Support**: Import it into your own Node.js projects.
8
+ - **Accurate Mapping**: Handles complex conjuncts, half-letters, and reph (र्) perfectly.
9
+ - **Bidirectional**: Convert both `Kruti Dev → Unicode` and `Unicode → Kruti Dev`.
10
+
11
+ ---
12
+
13
+ ## 🚀 Quick Start (CLI)
14
+
15
+ You can run this directly without installing anything globally (using `npx`):
16
+
17
+ ```bash
18
+ # Convert Kruti Dev to Unicode
19
+ npx kruti-unicode-converter -f input.txt -d kruti-to-uni -o output.txt
20
+
21
+ # Convert Unicode to Kruti Dev
22
+ npx kruti-unicode-converter -f input.txt -d uni-to-kruti -o output.txt
package/converter.js ADDED
@@ -0,0 +1,225 @@
1
+ // Core Converter Logic
2
+
3
+ const krutiToUnicodeMaps = {
4
+ array_one: [
5
+ "ñ", "Q+Z", "sas", "aa", ")Z", "ZZ", "‘", "’", "“", "”",
6
+ "å", "ƒ", "„", "…", "†", "‡", "ˆ", "‰", "Š", "‹",
7
+ "¶+", "d+", "[+k", "[+", "x+", "T+", "t+", "M+", "<+", "Q+", ";+", "j+", "u+",
8
+ "Ùk", "Ù", "ä", "–", "—", "é", "™", "=kk", "f=k",
9
+ "à", "á", "â", "ã", "ºz", "º", "í", "{k", "{", "=", "«",
10
+ "Nî", "Vî", "Bî", "Mî", "<î", "|", "K", "}",
11
+ "J", "Vª", "Mª", "<ªª", "Nª", "Ø", "Ý", "nzZ", "æ", "ç", "Á", "xz", "#", ":",
12
+ "v‚", "vks", "vkS", "vk", "v", "b±", "Ã", "bZ", "b", "m", "Å", ",s", ",", "_",
13
+ "ô", "d", "Dk", "D", "[k", "[", "x", "Xk", "X", "Ä", "?k", "?", "³",
14
+ "pkS", "p", "Pk", "P", "N", "t", "Tk", "T", ">", "÷", "¥",
15
+ "ê", "ë", "V", "B", "ì", "ï", "M+", "<+", "M", "<", ".k", ".",
16
+ "r", "Rk", "R", "Fk", "F", ")", "n", "/k", "èk", "/", "Ë", "è", "u", "Uk", "U",
17
+ "i", "Ik", "I", "Q", "¶", "c", "Ck", "C", "Hk", "H", "e", "Ek", "E",
18
+ ";", "¸", "j", "y", "Yk", "Y", "G", "o", "Ok", "O",
19
+ "'k", "'", "\"k", "\"", "l", "Lk", "L", "g",
20
+ "È", "z",
21
+ "Ì", "Í", "Î", "Ï", "Ñ", "Ò", "Ó", "Ô", "Ö", "Ø", "Ù", "Ük", "Ü",
22
+ "‚", "ks", "kS", "k", "h", "q", "w", "`", "s", "S",
23
+ "a", "¡", "%", "W", "•", "·", "∙", "·", "~j", "~", "\\", "+", " ः",
24
+ "^", "*", "Þ", "ß", "(", "¼", "½", "¿", "À", "¾", "A", "-", "&", "&", "Œ", "]", "~ ", "@"
25
+ ],
26
+ array_two: [
27
+ "॰", "QZ+", "sa", "a", "र्द्ध", "Z", "\"", "\"", "'", "'",
28
+ "०", "१", "२", "३", "४", "५", "६", "७", "८", "९",
29
+ "फ़्", "क़", "ख़", "ख़्", "ग़", "ज़्", "ज़", "ड़", "ढ़", "फ़", "य़", "ऱ", "ऩ",
30
+ "त्त", "त्त्", "क्त", "दृ", "कृ", "न्न", "न्न्", "=k", "f=",
31
+ "ह्न", "ह्य", "हृ", "ह्म", "ह्र", "ह्", "द्द", "क्ष", "क्ष्", "त्र", "त्र्",
32
+ "छ्य", "ट्य", "ठ्य", "ड्य", "ढ्य", "द्य", "ज्ञ", "द्व",
33
+ "श्र", "ट्र", "ड्र", "ढ्र", "छ्र", "क्र", "फ्र", "र्द्र", "द्र", "प्र", "प्र", "ग्र", "रु", "रू",
34
+ "ऑ", "ओ", "औ", "आ", "अ", "ईं", "ई", "ई", "इ", "उ", "ऊ", "ऐ", "ए", "ऋ",
35
+ "क्क", "क", "क", "क्", "ख", "ख्", "ग", "ग", "ग्", "घ", "घ", "घ्", "ङ",
36
+ "चै", "च", "च", "च्", "छ", "ज", "ज", "ज्", "झ", "झ्", "ञ",
37
+ "ट्ट", "ट्ठ", "ट", "ठ", "ड्ड", "ड्ढ", "ड़", "ढ़", "ड", "ढ", "ण", "ण्",
38
+ "त", "त", "त्", "थ", "थ्", "द्ध", "द", "ध", "ध", "ध्", "ध्", "ध्", "न", "न", "न्",
39
+ "प", "प", "प्", "फ", "फ्", "ब", "ब", "ब्", "भ", "भ्", "म", "म", "म्",
40
+ "य", "य्", "र", "ल", "ल", "ल्", "ळ", "व", "व", "व्",
41
+ "श", "श्", "ष", "ष्", "स", "स", "स्", "ह",
42
+ "ीं", "्र",
43
+ "द्द", "ट्ट", "ट्ठ", "ड्ड", "कृ", "भ", "्य", "ड्ढ", "झ्", "क्र", "त्त्", "श", "श्",
44
+ "ॉ", "ो", "ौ", "ा", "ी", "ु", "ू", "ृ", "े", "ै",
45
+ "ं", "ँ", "ः", "ॅ", "ऽ", "ऽ", "ऽ", "ऽ", "्र", "्", "?", "़", ":",
46
+ "‘", "’", "“", "”", ";", "(", ")", "{", "}", "=", "।", ".", "-", "µ", "॰", ",", "् ", "/"
47
+ ]
48
+ };
49
+
50
+ const unicodeToKrutiMaps = {
51
+ array_one: [
52
+ "‘", "’", "“", "”", "(", ")", "{", "}", "=", "।", "?", "-", "µ", "॰", ",", ".", "् ",
53
+ "०", "१", "२", "३", "४", "५", "६", "७", "८", "९", "x",
54
+ "फ़्", "क़", "ख़", "ग़", "ज़्", "ज़", "ड़", "ढ़", "फ़", "य़", "ऱ", "ऩ",
55
+ "त्त्", "त्त", "क्त", "दृ", "कृ",
56
+ "ह्न", "ह्य", "हृ", "ह्म", "ह्र", "ह्", "द्द", "क्ष्", "क्ष", "त्र्", "त्र", "ज्ञ",
57
+ "छ्य", "ट्य", "ठ्य", "ड्य", "ढ्य", "द्य", "द्व",
58
+ "श्र", "ट्र", "ड्र", "ढ्र", "छ्र", "क्र", "फ्र", "द्र", "प्र", "ग्र", "रु", "रू",
59
+ "्र",
60
+ "ओ", "औ", "आ", "अ", "ई", "इ", "उ", "ऊ", "ऐ", "ए", "ऋ",
61
+ "क्", "क", "क्क", "ख्", "ख", "ग्", "ग", "घ्", "घ", "ङ",
62
+ "चै", "च्", "च", "छ", "ज्", "ज", "झ्", "झ", "ञ",
63
+ "ट्ट", "ट्ठ", "ट", "ठ", "ड्ड", "ड्ढ", "ड", "ढ", "ण्", "ण",
64
+ "त्", "त", "थ्", "थ", "द्ध", "द", "ध्", "ध", "न्", "न",
65
+ "प्", "प", "फ्", "फ", "ब्", "ब", "भ्", "भ", "म्", "म",
66
+ "य्", "य", "र", "ल्", "ल", "ळ", "व्", "व",
67
+ "श्", "श", "ष्", "ष", "स्", "स", "ह",
68
+ "ऑ", "ॉ", "ो", "ौ", "ा", "ी", "ु", "ू", "ृ", "े", "ै",
69
+ "ं", "ँ", "ः", "ॅ", "ऽ", "् ", "्"
70
+ ],
71
+ array_two: [
72
+ "^", "*", "Þ", "ß", "¼", "½", "¿", "À", "¾", "A", "\\", "&", "&", "Œ", "]", "-", "~ ",
73
+ "å", "ƒ", "„", "…", "†", "‡", "ˆ", "‰", "Š", "‹", "Û",
74
+ "¶", "d", "[k", "x", "T", "t", "M+", "<+", "Q", ";", "j", "u",
75
+ "Ù", "Ùk", "ä", "–", "—",
76
+ "à", "á", "â", "ã", "ºz", "º", "í", "{", "{k", "«", "=", "K",
77
+ "Nî", "Vî", "Bî", "Mî", "<î", "|", "}",
78
+ "J", "Vª", "Mª", "<ªª", "Nª", "Ø", "Ý", "æ", "ç", "xz", "#", ":",
79
+ "z",
80
+ "vks", "vkS", "vk", "v", "bZ", "b", "m", "Å", ",s", ",", "_",
81
+ "D", "d", "ô", "[", "[k", "X", "x", "?", "?k", "³",
82
+ "pkS", "P", "p", "N", "T", "t", "÷", ">", "¥",
83
+ "ê", "ë", "V", "B", "ì", "ï", "M", "<", ".", ".k",
84
+ "R", "r", "F", "Fk", ")", "n", "/", "/k", "U", "u",
85
+ "I", "i", "¶", "Q", "C", "c", "H", "Hk", "E", "e",
86
+ "¸", ";", "j", "Y", "y", "G", "O", "o",
87
+ "'", "'k", "\"", "\"k", "L", "l", "g",
88
+ "v‚", "‚", "ks", "kS", "k", "h", "q", "w", "`", "s", "S",
89
+ "a", "¡", "%", "W", "·", "~ ", "~"
90
+ ]
91
+ };
92
+
93
+ /**
94
+ * Core replace logic for Kruti Dev -> Unicode
95
+ */
96
+ function krutiToUnicode(text) {
97
+ let modified_substring = text;
98
+ const { array_one, array_two } = krutiToUnicodeMaps;
99
+
100
+ // Substitute mapping
101
+ for (let i = 0; i < array_one.length; i++) {
102
+ while (modified_substring.includes(array_one[i])) {
103
+ modified_substring = modified_substring.replace(array_one[i], array_two[i]);
104
+ }
105
+ }
106
+
107
+ // Special Glyphs
108
+ modified_substring = modified_substring.replace(/±/g, "Zं");
109
+ modified_substring = modified_substring.replace(/Æ/g, "र्f");
110
+
111
+ let pos = modified_substring.indexOf("f");
112
+ while (pos !== -1) {
113
+ let charNext = modified_substring.charAt(pos + 1);
114
+ let toReplace = "f" + charNext;
115
+ modified_substring = modified_substring.replace(toReplace, charNext + "ि");
116
+ pos = modified_substring.search(/f/, pos + 1);
117
+ }
118
+
119
+ modified_substring = modified_substring.replace(/Ç/g, "fa");
120
+ modified_substring = modified_substring.replace(/É/g, "र्fa");
121
+
122
+ pos = modified_substring.indexOf("fa");
123
+ while (pos !== -1) {
124
+ let charNext = modified_substring.charAt(pos + 2);
125
+ let toReplace = "fa" + charNext;
126
+ modified_substring = modified_substring.replace(toReplace, charNext + "िं");
127
+ pos = modified_substring.search(/fa/, pos + 2);
128
+ }
129
+
130
+ modified_substring = modified_substring.replace(/Ê/g, "ीZ");
131
+
132
+ // Half 'i' fix
133
+ pos = modified_substring.indexOf("ि्");
134
+ while (pos !== -1) {
135
+ let charNext = modified_substring.charAt(pos + 2);
136
+ let toReplace = "ि्" + charNext;
137
+ modified_substring = modified_substring.replace(toReplace, "्" + charNext + "ि");
138
+ pos = modified_substring.search(/ि्/, pos + 2);
139
+ }
140
+
141
+ // Reph 'Z' fix
142
+ const matras = "अ आ इ ई उ ऊ ए ऐ ओ औ ा ि ी ु ू ृ े ै ो ौ ं : ँ ॅ";
143
+ let posR = modified_substring.indexOf("Z");
144
+
145
+ while (posR > 0) {
146
+ let probableHalfR = posR - 1;
147
+ let charAtProbable = modified_substring.charAt(probableHalfR);
148
+
149
+ while (matras.includes(charAtProbable)) {
150
+ probableHalfR--;
151
+ charAtProbable = modified_substring.charAt(probableHalfR);
152
+ }
153
+
154
+ let toReplace = modified_substring.substr(probableHalfR, posR - probableHalfR);
155
+ let replacement = "र्" + toReplace;
156
+ toReplace += "Z";
157
+ modified_substring = modified_substring.replace(toReplace, replacement);
158
+ posR = modified_substring.indexOf("Z");
159
+ }
160
+
161
+ return modified_substring;
162
+ }
163
+
164
+ /**
165
+ * Core replace logic for Unicode -> Kruti Dev
166
+ */
167
+ function unicodeToKruti(text) {
168
+ let modified_substring = text;
169
+ const { array_one, array_two } = unicodeToKrutiMaps;
170
+
171
+ // Nukta varNas
172
+ const nuktas = { "क़": "क़", "ख़‌": "ख़", "ग़": "ग़", "ज़": "ज़", "ड़": "ड़", "ढ़": "ढ़", "ऩ": "ऩ", "फ़": "फ़", "य़": "य़", "ऱ": "ऱ" };
173
+ for (const [key, val] of Object.entries(nuktas)) {
174
+ modified_substring = modified_substring.replace(new RegExp(key, 'g'), val);
175
+ }
176
+
177
+ // 'i' matra fix
178
+ let posF = modified_substring.indexOf("ि");
179
+ while (posF !== -1) {
180
+ let charLeft = modified_substring.charAt(posF - 1);
181
+ modified_substring = modified_substring.replace(charLeft + "ि", "f" + charLeft);
182
+ posF = posF - 1;
183
+ while ((modified_substring.charAt(posF - 1) === "्") && (posF !== 0)) {
184
+ let toReplace = modified_substring.charAt(posF - 2) + "्";
185
+ modified_substring = modified_substring.replace(toReplace + "f", "f" + toReplace);
186
+ posF = posF - 2;
187
+ }
188
+ posF = modified_substring.search(/ि/, posF + 1);
189
+ }
190
+
191
+ // Reph fix
192
+ const matras = "ािीुूृेैोौं:ँॅ";
193
+ modified_substring += ' '; // temp buffer
194
+
195
+ let posHalfR = modified_substring.indexOf("र्");
196
+ while (posHalfR > 0) {
197
+ let probableZ = posHalfR + 2;
198
+ let charRight = modified_substring.charAt(probableZ + 1);
199
+
200
+ while (matras.includes(charRight)) {
201
+ probableZ++;
202
+ charRight = modified_substring.charAt(probableZ + 1);
203
+ }
204
+
205
+ let toReplace = modified_substring.substr(posHalfR + 2, probableZ - posHalfR - 1);
206
+ modified_substring = modified_substring.replace("र्" + toReplace, toReplace + "Z");
207
+ posHalfR = modified_substring.indexOf("र्");
208
+ }
209
+
210
+ modified_substring = modified_substring.substr(0, modified_substring.length - 2); // remove temp buffer
211
+
212
+ // Substitute mapping
213
+ for (let i = 0; i < array_one.length; i++) {
214
+ while (modified_substring.includes(array_one[i])) {
215
+ modified_substring = modified_substring.replace(array_one[i], array_two[i]);
216
+ }
217
+ }
218
+
219
+ return modified_substring;
220
+ }
221
+
222
+ module.exports = {
223
+ krutiToUnicode,
224
+ unicodeToKruti
225
+ };
package/example.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Example usage of the kruti-unicode-converter library.
3
+ * Run this file to see the conversion in action!
4
+ *
5
+ * Command: node example.js
6
+ */
7
+
8
+ const { krutiToUnicode, unicodeToKruti } = require('./lib/converter');
9
+
10
+ console.log("=========================================");
11
+ console.log("🔄 Kruti Dev ↔ Unicode Converter Example");
12
+ console.log("=========================================\n");
13
+
14
+ // --- TEST 1: Kruti Dev to Unicode ---
15
+ const sampleKruti = "osYl QkWj bafM;k & ftls vkt ge ^okVj gkosZLV* ds uke ls tkurs gS";
16
+ console.log("👉 Original (Kruti Dev):");
17
+ console.log(sampleKruti);
18
+
19
+ const convertedUnicode = krutiToUnicode(sampleKruti);
20
+ console.log("\n✅ Converted (Unicode):");
21
+ console.log(convertedUnicode);
22
+ console.log("\n-----------------------------------------\n");
23
+
24
+ // --- TEST 2: Unicode to Kruti Dev ---
25
+ const sampleUnicode = "वेल्स फॉर इंडिया - जिसे आज हम 'वाटर हार्वेस्ट' के नाम से जानते है";
26
+ console.log("👉 Original (Unicode):");
27
+ console.log(sampleUnicode);
28
+
29
+ const convertedKruti = unicodeToKruti(sampleUnicode);
30
+ console.log("\n✅ Converted (Kruti Dev):");
31
+ console.log(convertedKruti);
32
+ console.log("\n=========================================");
package/index.js ADDED
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { krutiToUnicode, unicodeToKruti } = require('./lib/converter');
6
+
7
+ // Parse CLI arguments
8
+ const args = process.argv.slice(2);
9
+ const getArg = (flag) => {
10
+ const index = args.indexOf(flag);
11
+ return index !== -1 ? args[index + 1] : null;
12
+ };
13
+
14
+ const inputFile = getArg('-f') || getArg('--file');
15
+ const direction = getArg('-d') || getArg('--direction') || 'kruti-to-uni';
16
+ const outputFile = getArg('-o') || getArg('--output') || 'output.txt';
17
+
18
+ if (!inputFile) {
19
+ console.log(`
20
+ ❌ Error: No input file specified.
21
+
22
+ Usage:
23
+ node index.js -f <input.txt> -d <kruti-to-uni | uni-to-kruti> [-o <output.txt>]
24
+
25
+ Example:
26
+ node index.js -f input.txt -d kruti-to-uni
27
+ `);
28
+ process.exit(1);
29
+ }
30
+
31
+ try {
32
+ const fullPath = path.resolve(inputFile);
33
+ if (!fs.existsSync(fullPath)) {
34
+ console.error(`❌ Error: File not found: ${fullPath}`);
35
+ process.exit(1);
36
+ }
37
+
38
+ const rawText = fs.readFileSync(fullPath, 'utf8');
39
+ let convertedText = '';
40
+
41
+ if (direction === 'kruti-to-uni') {
42
+ convertedText = krutiToUnicode(rawText);
43
+ } else if (direction === 'uni-to-kruti') {
44
+ convertedText = unicodeToKruti(rawText);
45
+ } else {
46
+ console.error(`❌ Error: Invalid direction. Use 'kruti-to-uni' or 'uni-to-kruti'.`);
47
+ process.exit(1);
48
+ }
49
+
50
+ fs.writeFileSync(outputFile, convertedText, 'utf8');
51
+ console.log(`✅ Success! Converted text saved to: ${outputFile}`);
52
+
53
+ } catch (error) {
54
+ console.error(`❌ An error occurred: ${error.message}`);
55
+ }
@@ -0,0 +1,5 @@
1
+ 48104efa22f9749a6e3acd2801465e97b936c37d1122e6a097261c23147b0abb
2
+ d3a61ae5101060be95f7351deca828bc4e056bb2800a6927df2c86919ee46c76
3
+ 0ead622238cb37b2794c7f201f4cb7cbea60c888854ec7dfcb820061321a553f
4
+ b53d6fde54ef0622c2e30839fb11ea276a74743ba7a9a79e908b1f7b9e288e66
5
+ 267398be7daa2f72a8c46be2c67e8332806167f04a79c9577a918ea6530d852f
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "kruti-unicode-converter",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "A modern CLI and Node.js library to convert Kruti Dev to Unicode and vice versa.",
5
+ "main": "converter.js",
6
+ "bin": {
7
+ "kruti-convert": "index.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node example.js"
11
+ },
12
+ "keywords": [
13
+ "kruti-dev",
14
+ "unicode",
15
+ "hindi",
16
+ "converter",
17
+ "cli"
18
+ ],
19
+ "author": "Chandan Kumar Jha",
20
+ "license": "MIT"
6
21
  }