tdk-api-wrapper 1.6.0 → 1.6.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/package.json +23 -3
- package/.github/workflows/publish.yml +0 -41
- package/src/cli.ts +0 -535
- package/src/errors.ts +0 -38
- package/src/index.ts +0 -4
- package/src/morphology.ts +0 -333
- package/src/tdk.ts +0 -2056
- package/src/types.ts +0 -185
- package/test/grammar.test.js +0 -52
- package/test/morphology.test.js +0 -140
- package/test/proofread.test.js +0 -88
- package/test/tools.test.js +0 -51
- package/tsconfig.json +0 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tdk-api-wrapper",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "TDK (Türk Dil Kurumu) unofficial live data API wrapper for Node.js",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -25,10 +25,30 @@
|
|
|
25
25
|
"api",
|
|
26
26
|
"turkish",
|
|
27
27
|
"dictionary",
|
|
28
|
-
"turkce"
|
|
28
|
+
"turkce",
|
|
29
|
+
"sozluk.gov.tr",
|
|
30
|
+
"spell-check",
|
|
31
|
+
"morphology",
|
|
32
|
+
"kubbealti",
|
|
33
|
+
"nisanyan",
|
|
34
|
+
"wiktionary"
|
|
29
35
|
],
|
|
30
|
-
"author": "",
|
|
36
|
+
"author": "cemyilmazzzz122 <cemyleo12@icloud.com> (https://github.com/cemyilmazzzz122)",
|
|
31
37
|
"license": "MIT",
|
|
38
|
+
"homepage": "https://github.com/cemyilmazzzz122/tdk-api#readme",
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/cemyilmazzzz122/tdk-api.git"
|
|
42
|
+
},
|
|
43
|
+
"bugs": {
|
|
44
|
+
"url": "https://github.com/cemyilmazzzz122/tdk-api/issues"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=18"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist"
|
|
51
|
+
],
|
|
32
52
|
"devDependencies": {
|
|
33
53
|
"@types/node": "^22.0.0",
|
|
34
54
|
"tsup": "^8.0.2",
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
name: Publish to npm
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
push:
|
|
5
|
-
branches: [main]
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
publish:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
steps:
|
|
11
|
-
- uses: actions/checkout@v4
|
|
12
|
-
|
|
13
|
-
- uses: actions/setup-node@v4
|
|
14
|
-
with:
|
|
15
|
-
node-version: '20'
|
|
16
|
-
registry-url: 'https://registry.npmjs.org'
|
|
17
|
-
|
|
18
|
-
- run: npm ci
|
|
19
|
-
|
|
20
|
-
- name: Check if version changed
|
|
21
|
-
id: version-check
|
|
22
|
-
run: |
|
|
23
|
-
LOCAL_VERSION=$(node -p "require('./package.json').version")
|
|
24
|
-
PKG_NAME=$(node -p "require('./package.json').name")
|
|
25
|
-
PUBLISHED_VERSION=$(npm view "$PKG_NAME" version 2>/dev/null || echo "0.0.0")
|
|
26
|
-
echo "Local: $LOCAL_VERSION / Published: $PUBLISHED_VERSION"
|
|
27
|
-
if [ "$LOCAL_VERSION" != "$PUBLISHED_VERSION" ]; then
|
|
28
|
-
echo "changed=true" >> "$GITHUB_OUTPUT"
|
|
29
|
-
else
|
|
30
|
-
echo "changed=false" >> "$GITHUB_OUTPUT"
|
|
31
|
-
fi
|
|
32
|
-
|
|
33
|
-
- name: Build
|
|
34
|
-
if: steps.version-check.outputs.changed == 'true'
|
|
35
|
-
run: npm run build
|
|
36
|
-
|
|
37
|
-
- name: Publish
|
|
38
|
-
if: steps.version-check.outputs.changed == 'true'
|
|
39
|
-
run: npm publish
|
|
40
|
-
env:
|
|
41
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/src/cli.ts
DELETED
|
@@ -1,535 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { TDK } from "./tdk";
|
|
3
|
-
|
|
4
|
-
const rawArgs = process.argv.slice(2);
|
|
5
|
-
const jsonMode = rawArgs.includes("--json");
|
|
6
|
-
const args = rawArgs.filter((a) => a !== "--json");
|
|
7
|
-
|
|
8
|
-
const isColor = !jsonMode && Boolean(process.stdout.isTTY);
|
|
9
|
-
const c = {
|
|
10
|
-
bold: (s: string) => (isColor ? `\x1b[1m${s}\x1b[0m` : s),
|
|
11
|
-
dim: (s: string) => (isColor ? `\x1b[2m${s}\x1b[0m` : s),
|
|
12
|
-
green: (s: string) => (isColor ? `\x1b[32m${s}\x1b[0m` : s),
|
|
13
|
-
yellow: (s: string) => (isColor ? `\x1b[33m${s}\x1b[0m` : s),
|
|
14
|
-
cyan: (s: string) => (isColor ? `\x1b[36m${s}\x1b[0m` : s),
|
|
15
|
-
red: (s: string) => (isColor ? `\x1b[31m${s}\x1b[0m` : s),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const KNOWN_COMMANDS = new Set([
|
|
19
|
-
"ara",
|
|
20
|
-
"anlam",
|
|
21
|
-
"koken",
|
|
22
|
-
"ornek",
|
|
23
|
-
"hece",
|
|
24
|
-
"uyum",
|
|
25
|
-
"kucukuyum",
|
|
26
|
-
"yazim",
|
|
27
|
-
"kok",
|
|
28
|
-
"stem",
|
|
29
|
-
"deyim",
|
|
30
|
-
"gunun",
|
|
31
|
-
"rastgele",
|
|
32
|
-
"esanlam",
|
|
33
|
-
"karsit",
|
|
34
|
-
"yabanci",
|
|
35
|
-
"kurallar",
|
|
36
|
-
"kural",
|
|
37
|
-
"karsilastir",
|
|
38
|
-
"analiz",
|
|
39
|
-
"oneri",
|
|
40
|
-
"bulmaca",
|
|
41
|
-
"pattern",
|
|
42
|
-
"anagram",
|
|
43
|
-
"kafiye",
|
|
44
|
-
"rhyme",
|
|
45
|
-
"denetle",
|
|
46
|
-
"proofread",
|
|
47
|
-
"repl",
|
|
48
|
-
"kubbealti",
|
|
49
|
-
"nisanyan",
|
|
50
|
-
"viki",
|
|
51
|
-
]);
|
|
52
|
-
|
|
53
|
-
let command = args[0];
|
|
54
|
-
let word = args.slice(1).join(" ");
|
|
55
|
-
|
|
56
|
-
if (command && !KNOWN_COMMANDS.has(command) && command !== "--help" && command !== "-h" && command !== "--version" && command !== "-v") {
|
|
57
|
-
word = args.join(" ");
|
|
58
|
-
command = "anlam";
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function printResult(data: unknown, formatted: () => void) {
|
|
62
|
-
if (jsonMode) {
|
|
63
|
-
console.log(JSON.stringify(data));
|
|
64
|
-
} else {
|
|
65
|
-
formatted();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function printError(message: string) {
|
|
70
|
-
if (jsonMode) {
|
|
71
|
-
console.log(JSON.stringify({ error: message }));
|
|
72
|
-
} else {
|
|
73
|
-
console.log(c.red(`Hata: ${message}`));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function startRepl() {
|
|
78
|
-
const readline = await import("node:readline");
|
|
79
|
-
const rl = readline.createInterface({
|
|
80
|
-
input: process.stdin,
|
|
81
|
-
output: process.stdout,
|
|
82
|
-
prompt: c.cyan("tdk> "),
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
console.log(c.bold("TDK İnteraktif Sözlük Kabuğu (Çıkmak için 'exit' veya Ctrl+C)"));
|
|
86
|
-
console.log(c.dim("Komutlar: ara <kelime>, hece <kelime>, bulmaca <desen>, denetle <metin> veya doğrudan kelime"));
|
|
87
|
-
rl.prompt();
|
|
88
|
-
|
|
89
|
-
rl.on("line", async (line) => {
|
|
90
|
-
const trimmed = line.trim();
|
|
91
|
-
if (!trimmed) {
|
|
92
|
-
rl.prompt();
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
if (trimmed === "exit" || trimmed === "quit" || trimmed === ".exit") {
|
|
96
|
-
rl.close();
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const parts = trimmed.split(/\s+/);
|
|
101
|
-
let subCmd = parts[0].toLowerCase();
|
|
102
|
-
let subArg = parts.slice(1).join(" ");
|
|
103
|
-
if (!KNOWN_COMMANDS.has(subCmd)) {
|
|
104
|
-
subArg = trimmed;
|
|
105
|
-
subCmd = "anlam";
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
if (subCmd === "ara" || subCmd === "anlam") {
|
|
110
|
-
const meanings = await TDK.getMeanings(subArg);
|
|
111
|
-
if (meanings.length === 0) console.log(c.dim("Sonuç bulunamadı."));
|
|
112
|
-
else meanings.forEach((m, i) => console.log(`${i + 1}. ${c.green(m)}`));
|
|
113
|
-
} else if (subCmd === "koken") {
|
|
114
|
-
const origin = await TDK.getOrigin(subArg);
|
|
115
|
-
console.log(`Köken: ${c.cyan(origin || "Bilinmiyor")}`);
|
|
116
|
-
} else if (subCmd === "hece") {
|
|
117
|
-
const s = TDK.syllabicate(subArg);
|
|
118
|
-
console.log(`Heceler: ${c.yellow(s.join("-"))}`);
|
|
119
|
-
} else if (subCmd === "uyum") {
|
|
120
|
-
const h = TDK.checkVowelHarmony(subArg);
|
|
121
|
-
console.log(`Büyük Ünlü Uyumu: ${h ? c.green("Uyar") : c.red("Uymaz")}`);
|
|
122
|
-
} else if (subCmd === "kucukuyum") {
|
|
123
|
-
const h = TDK.checkLabialHarmony(subArg);
|
|
124
|
-
console.log(`Küçük Ünlü Uyumu: ${h ? c.green("Uyar") : c.red("Uymaz")}`);
|
|
125
|
-
} else if (subCmd === "bulmaca" || subCmd === "pattern") {
|
|
126
|
-
const matches = await TDK.patternSearch(subArg);
|
|
127
|
-
console.log(matches.slice(0, 15).join(", "));
|
|
128
|
-
} else if (subCmd === "denetle" || subCmd === "proofread") {
|
|
129
|
-
const res = await TDK.proofread(subArg);
|
|
130
|
-
if (res.isCorrect) console.log(c.green("✓ Sorun bulunamadı."));
|
|
131
|
-
else res.issues.forEach((iss) => console.log(`- ${c.yellow(iss.word)}: ${iss.message}${iss.suggestion ? " -> " + c.green(iss.suggestion) : ""}`));
|
|
132
|
-
} else {
|
|
133
|
-
console.log(c.dim("Örnek komutlar: 'ara kalem', 'hece elektrik', 'bulmaca k_l_m', 'denetle Bugün evdeyim'"));
|
|
134
|
-
}
|
|
135
|
-
} catch (e: any) {
|
|
136
|
-
console.log(c.red(`Hata: ${e?.message || e}`));
|
|
137
|
-
}
|
|
138
|
-
rl.prompt();
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async function run() {
|
|
143
|
-
if (!command) {
|
|
144
|
-
if (process.stdin.isTTY) {
|
|
145
|
-
await startRepl();
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
console.log("Kullanım: tdk [komut] <kelime> [--json]");
|
|
149
|
-
console.log(
|
|
150
|
-
"Komutlar: ara, anlam, koken, ornek, hece, uyum, kucukuyum, yazim, kok, deyim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri, bulmaca, anagram, kafiye, denetle, repl, kubbealti, nisanyan, viki"
|
|
151
|
-
);
|
|
152
|
-
console.log("Not: Komut belirtilmezse doğrudan kelime anlamı aranır (örn: tdk selam)");
|
|
153
|
-
process.exit(1);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (command === "--version" || command === "-v") {
|
|
157
|
-
console.log("tdk-api-wrapper v1.5.1");
|
|
158
|
-
process.exit(0);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (command === "--help" || command === "-h") {
|
|
162
|
-
console.log("Kullanım: tdk [komut] <kelime> [--json]");
|
|
163
|
-
console.log(
|
|
164
|
-
"Komutlar: ara, anlam, koken, ornek, hece, uyum, kucukuyum, yazim, kok, deyim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri, bulmaca, anagram, kafiye, denetle, repl, kubbealti, nisanyan, viki"
|
|
165
|
-
);
|
|
166
|
-
console.log("Not: Komut belirtilmezse doğrudan kelime anlamı aranır (örn: tdk selam)");
|
|
167
|
-
process.exit(0);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
TDK.enableCache(false);
|
|
171
|
-
|
|
172
|
-
try {
|
|
173
|
-
switch (command) {
|
|
174
|
-
case "ara":
|
|
175
|
-
case "anlam": {
|
|
176
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
177
|
-
const meanings = await TDK.getMeanings(word);
|
|
178
|
-
printResult(meanings, () => {
|
|
179
|
-
if (meanings.length === 0) {
|
|
180
|
-
console.log("Sonuç bulunamadı.");
|
|
181
|
-
} else {
|
|
182
|
-
meanings.forEach((m, i) => console.log(`${i + 1}. ${m}`));
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
case "koken": {
|
|
189
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
190
|
-
const origin = await TDK.getOrigin(word);
|
|
191
|
-
printResult({ word, origin }, () => console.log(`Köken: ${origin}`));
|
|
192
|
-
break;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
case "ornek": {
|
|
196
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
197
|
-
const examples = await TDK.getExamples(word);
|
|
198
|
-
printResult(examples, () => {
|
|
199
|
-
if (examples.length === 0) {
|
|
200
|
-
console.log("Örnek bulunamadı.");
|
|
201
|
-
} else {
|
|
202
|
-
examples.forEach((ex, i) => {
|
|
203
|
-
const yazar = ex.author ? ` (${ex.author})` : "";
|
|
204
|
-
console.log(`${i + 1}. ${ex.sentence}${yazar}`);
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
});
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
case "hece": {
|
|
212
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
213
|
-
const syllables = TDK.syllabicate(word);
|
|
214
|
-
printResult(syllables, () => console.log(`Heceler: ${syllables.join("-")}`));
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
case "uyum": {
|
|
219
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
220
|
-
const isHarmony = TDK.checkVowelHarmony(word);
|
|
221
|
-
printResult({ word, harmony: isHarmony }, () =>
|
|
222
|
-
console.log(`Büyük Ünlü Uyumu: ${isHarmony ? "Uyar" : "Uymaz"}`)
|
|
223
|
-
);
|
|
224
|
-
break;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
case "kucukuyum":
|
|
228
|
-
case "labial": {
|
|
229
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
230
|
-
const isHarmony = TDK.checkLabialHarmony(word);
|
|
231
|
-
printResult({ word, labialHarmony: isHarmony }, () =>
|
|
232
|
-
console.log(`Küçük Ünlü Uyumu: ${isHarmony ? "Uyar" : "Uymaz"}`)
|
|
233
|
-
);
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
case "yazim": {
|
|
238
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
239
|
-
const spellResult = await TDK.checkSpelling(word);
|
|
240
|
-
printResult(spellResult, () => {
|
|
241
|
-
if (spellResult.isCorrect) {
|
|
242
|
-
if (spellResult.isInflected && spellResult.root) {
|
|
243
|
-
console.log(`Doğru yazım (çekimli biçim, kök: ${spellResult.root}).`);
|
|
244
|
-
} else {
|
|
245
|
-
console.log("Doğru yazım.");
|
|
246
|
-
}
|
|
247
|
-
} else {
|
|
248
|
-
console.log(`Yanlış yazım.${spellResult.suggestion ? " Doğrusu: " + spellResult.suggestion : ""}`);
|
|
249
|
-
}
|
|
250
|
-
});
|
|
251
|
-
break;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
case "kok":
|
|
255
|
-
case "stem": {
|
|
256
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
257
|
-
const stemResult = await TDK.stem(word);
|
|
258
|
-
printResult(stemResult, () => {
|
|
259
|
-
if (!stemResult) {
|
|
260
|
-
console.log("Kök bulunamadı.");
|
|
261
|
-
} else if (stemResult.isInflected) {
|
|
262
|
-
console.log(`Kök: ${stemResult.root} (çekimli biçim)`);
|
|
263
|
-
} else {
|
|
264
|
-
console.log(`Kök: ${stemResult.root} (yalın biçim)`);
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
break;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
case "deyim": {
|
|
271
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
272
|
-
const proverbs = await TDK.getProverbs(word);
|
|
273
|
-
printResult(proverbs, () => {
|
|
274
|
-
if (proverbs.length === 0) {
|
|
275
|
-
console.log("Atasözü/deyim bulunamadı.");
|
|
276
|
-
} else {
|
|
277
|
-
proverbs.forEach((p, i) => console.log(`${i + 1}. ${p}`));
|
|
278
|
-
}
|
|
279
|
-
});
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
case "gunun": {
|
|
284
|
-
const wotd = await TDK.getWordOfTheDay();
|
|
285
|
-
printResult(wotd, () => {
|
|
286
|
-
if (!wotd) {
|
|
287
|
-
console.log("Günün kelimesi alınamadı.");
|
|
288
|
-
} else {
|
|
289
|
-
console.log(`Günün kelimesi: ${wotd.word}`);
|
|
290
|
-
wotd.meanings.forEach((m, i) => console.log(`${i + 1}. ${m}`));
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
break;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
case "rastgele": {
|
|
297
|
-
const pick = await TDK.getRandomWord();
|
|
298
|
-
printResult(pick, () => {
|
|
299
|
-
if (!pick) {
|
|
300
|
-
console.log("Rastgele içerik alınamadı.");
|
|
301
|
-
} else {
|
|
302
|
-
const label = pick.type === "kelime" ? "Kelime" : "Atasözü";
|
|
303
|
-
console.log(`${label}: ${pick.madde}`);
|
|
304
|
-
console.log(pick.anlam);
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
break;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
case "esanlam": {
|
|
311
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
312
|
-
const synonyms = await TDK.getSynonyms(word);
|
|
313
|
-
printResult(synonyms, () => {
|
|
314
|
-
if (synonyms.length === 0) {
|
|
315
|
-
console.log("Eş anlamlı kelime bulunamadı.");
|
|
316
|
-
} else {
|
|
317
|
-
synonyms.forEach((s, i) => console.log(`${i + 1}. ${s}`));
|
|
318
|
-
}
|
|
319
|
-
});
|
|
320
|
-
break;
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
case "karsit": {
|
|
324
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
325
|
-
const antonyms = await TDK.getAntonyms(word);
|
|
326
|
-
printResult(antonyms, () => {
|
|
327
|
-
if (antonyms.length === 0) {
|
|
328
|
-
console.log("Zıt anlamlı kelime bulunamadı.");
|
|
329
|
-
} else {
|
|
330
|
-
antonyms.forEach((s, i) => console.log(`${i + 1}. ${s}`));
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
break;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
case "yabanci": {
|
|
337
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
338
|
-
const foreign = await TDK.isForeignWord(word);
|
|
339
|
-
printResult({ word, foreign }, () => {
|
|
340
|
-
if (foreign === null) {
|
|
341
|
-
console.log("Kelime bulunamadı.");
|
|
342
|
-
} else {
|
|
343
|
-
console.log(foreign ? "Yabancı kökenli." : "Türkçe kökenli.");
|
|
344
|
-
}
|
|
345
|
-
});
|
|
346
|
-
break;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
case "kurallar": {
|
|
350
|
-
const rules = await TDK.getKurallar();
|
|
351
|
-
printResult(rules, () => {
|
|
352
|
-
if (rules.length === 0) {
|
|
353
|
-
console.log("Kural listesi alınamadı.");
|
|
354
|
-
} else {
|
|
355
|
-
rules.forEach((r, i) => console.log(`${i + 1}. ${r.adi}`));
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
case "kural": {
|
|
362
|
-
if (!word) throw new Error("Kural adı belirtmelisiniz.");
|
|
363
|
-
const rule = await TDK.getRule(word);
|
|
364
|
-
printResult(rule, () => {
|
|
365
|
-
console.log(rule ?? "Kural bulunamadı.");
|
|
366
|
-
});
|
|
367
|
-
break;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
case "karsilastir": {
|
|
371
|
-
const [wordA, wordB] = args.slice(1);
|
|
372
|
-
if (!wordA || !wordB) throw new Error("İki kelime belirtmelisiniz.");
|
|
373
|
-
const comparison = await TDK.compareWords(wordA, wordB);
|
|
374
|
-
printResult(comparison, () => {
|
|
375
|
-
for (const side of [comparison.a, comparison.b]) {
|
|
376
|
-
console.log(`${side.word}: ${side.meaningCount} anlam, köken: ${side.origin ?? "bulunamadı"}, hece: ${side.syllables.join("-")}, büyük ünlü uyumu: ${side.harmony ? "uyar" : "uymaz"}`);
|
|
377
|
-
}
|
|
378
|
-
});
|
|
379
|
-
break;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
case "analiz": {
|
|
383
|
-
if (!word) throw new Error("Metin belirtmelisiniz.");
|
|
384
|
-
const analysis = await TDK.analyzeText(word);
|
|
385
|
-
printResult(analysis, () => {
|
|
386
|
-
if (analysis.length === 0) {
|
|
387
|
-
console.log("Analiz edilecek kelime bulunamadı.");
|
|
388
|
-
} else {
|
|
389
|
-
analysis.forEach((a) => {
|
|
390
|
-
if (a.found) {
|
|
391
|
-
const rootLabel = a.isInflected && a.root ? ` (kök: ${a.root})` : "";
|
|
392
|
-
console.log(`${a.word}${rootLabel}: ${a.meaning ?? "-"} (${a.origin})`);
|
|
393
|
-
} else {
|
|
394
|
-
console.log(`${a.word}: bulunamadı`);
|
|
395
|
-
}
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
});
|
|
399
|
-
break;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
case "oneri": {
|
|
403
|
-
if (!word) throw new Error("Önek belirtmelisiniz.");
|
|
404
|
-
const suggestions = await TDK.getSuggestions(word);
|
|
405
|
-
printResult(suggestions, () => {
|
|
406
|
-
if (suggestions.length === 0) {
|
|
407
|
-
console.log("Öneri bulunamadı.");
|
|
408
|
-
} else {
|
|
409
|
-
suggestions.forEach((s, i) => console.log(`${i + 1}. ${s}`));
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
break;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
case "bulmaca":
|
|
416
|
-
case "pattern": {
|
|
417
|
-
if (!word) throw new Error("Desen belirtmelisiniz (örn: k_l_m).");
|
|
418
|
-
const matches = await TDK.patternSearch(word);
|
|
419
|
-
printResult(matches, () => {
|
|
420
|
-
if (matches.length === 0) {
|
|
421
|
-
console.log("Eşleşen kelime bulunamadı.");
|
|
422
|
-
} else {
|
|
423
|
-
console.log(c.bold(`Bulunan Kelimeler (${matches.length}):`));
|
|
424
|
-
matches.forEach((m, i) => console.log(`${i + 1}. ${c.cyan(m)}`));
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
break;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
case "anagram": {
|
|
431
|
-
if (!word) throw new Error("Harfler belirtmelisiniz.");
|
|
432
|
-
const anagrams = await TDK.findAnagrams(word);
|
|
433
|
-
printResult(anagrams, () => {
|
|
434
|
-
if (anagrams.length === 0) {
|
|
435
|
-
console.log("Anagram veya bu harflerle türetilebilecek kelime bulunamadı.");
|
|
436
|
-
} else {
|
|
437
|
-
const clean = word.trim().toLocaleLowerCase("tr-TR").replace(/[^a-zçğıöşüâîû]/gi, "");
|
|
438
|
-
const hasExact = anagrams.some((a) => a.length === clean.length);
|
|
439
|
-
const title = hasExact
|
|
440
|
-
? `Anagramlar (${anagrams.length}):`
|
|
441
|
-
: `Birebir anagram bulunamadı. Bu harflerle türetilen kelimeler (${anagrams.length}):`;
|
|
442
|
-
console.log(c.bold(title));
|
|
443
|
-
anagrams.forEach((a, i) => console.log(`${i + 1}. ${c.green(a)} ${c.dim(`(${a.length} harf)`)}`));
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
break;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
case "kafiye":
|
|
450
|
-
case "rhyme": {
|
|
451
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
452
|
-
const rhymes = await TDK.findRhymes(word);
|
|
453
|
-
printResult(rhymes, () => {
|
|
454
|
-
if (rhymes.length === 0) {
|
|
455
|
-
console.log("Kafiye bulunamadı.");
|
|
456
|
-
} else {
|
|
457
|
-
console.log(c.bold(`Kafiyeli Kelimeler (${rhymes.length}):`));
|
|
458
|
-
rhymes.forEach((r, i) => console.log(`${i + 1}. ${c.yellow(r)}`));
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
break;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
case "denetle":
|
|
465
|
-
case "proofread": {
|
|
466
|
-
if (!word) throw new Error("Metin belirtmelisiniz.");
|
|
467
|
-
const result = await TDK.proofread(word);
|
|
468
|
-
printResult(result, () => {
|
|
469
|
-
if (result.isCorrect) {
|
|
470
|
-
console.log(c.green("✓ Metinde imla veya bağlaç hatası tespit edilmedi."));
|
|
471
|
-
} else {
|
|
472
|
-
console.log(c.bold(c.red(`Metinde ${result.issues.length} olası sorun tespit edildi:`)));
|
|
473
|
-
result.issues.forEach((issue, i) => {
|
|
474
|
-
const label = c.yellow(`[${issue.type}]`);
|
|
475
|
-
const sug = issue.suggestion ? c.green(` -> Öneri: ${issue.suggestion}`) : "";
|
|
476
|
-
console.log(`${i + 1}. ${label} "${c.bold(issue.word)}": ${issue.message}${sug}`);
|
|
477
|
-
});
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
case "repl": {
|
|
484
|
-
await startRepl();
|
|
485
|
-
break;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
case "kubbealti": {
|
|
489
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
490
|
-
const meanings = await TDK.getKubbealtiMeanings(word);
|
|
491
|
-
printResult(meanings, () => {
|
|
492
|
-
if (!meanings) {
|
|
493
|
-
console.log("Kubbealtı Lugatı'na ulaşılamadı.");
|
|
494
|
-
} else if (meanings.length === 0) {
|
|
495
|
-
console.log("Sonuç bulunamadı.");
|
|
496
|
-
} else {
|
|
497
|
-
meanings.forEach((m, i) => console.log(`${i + 1}. ${m}`));
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
break;
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
case "nisanyan": {
|
|
504
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
505
|
-
const origin = await TDK.getNisanyan(word);
|
|
506
|
-
printResult(origin, () => console.log(origin ?? "Sonuç bulunamadı."));
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
case "viki": {
|
|
511
|
-
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
512
|
-
const entry = await TDK.getWiktionary(word);
|
|
513
|
-
printResult(entry, () => {
|
|
514
|
-
if (!entry) {
|
|
515
|
-
console.log("Sonuç bulunamadı.");
|
|
516
|
-
} else {
|
|
517
|
-
for (const [title, content] of Object.entries(entry.sections)) {
|
|
518
|
-
if (content) console.log(`-- ${title} --\n${content}\n`);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
break;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
default:
|
|
526
|
-
printError("Bilinmeyen komut.");
|
|
527
|
-
}
|
|
528
|
-
} catch (error) {
|
|
529
|
-
if (error instanceof Error) {
|
|
530
|
-
printError(error.message);
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
run();
|
package/src/errors.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base class for all errors thrown by this library.
|
|
3
|
-
*/
|
|
4
|
-
export class TDKError extends Error {
|
|
5
|
-
constructor(message: string) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = "TDKError";
|
|
8
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Thrown when a caller-supplied argument is invalid (e.g. an empty word).
|
|
14
|
-
*/
|
|
15
|
-
export class TDKValidationError extends TDKError {
|
|
16
|
-
constructor(message: string) {
|
|
17
|
-
super(message);
|
|
18
|
-
this.name = "TDKValidationError";
|
|
19
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Thrown when a request to sozluk.gov.tr fails at the network/HTTP level
|
|
25
|
-
* (connection failure, non-OK HTTP status, unparsable response, etc).
|
|
26
|
-
*/
|
|
27
|
-
export class TDKNetworkError extends TDKError {
|
|
28
|
-
public readonly status?: number;
|
|
29
|
-
public readonly cause?: unknown;
|
|
30
|
-
|
|
31
|
-
constructor(message: string, options?: { status?: number; cause?: unknown }) {
|
|
32
|
-
super(message);
|
|
33
|
-
this.name = "TDKNetworkError";
|
|
34
|
-
this.status = options?.status;
|
|
35
|
-
this.cause = options?.cause;
|
|
36
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
37
|
-
}
|
|
38
|
-
}
|
package/src/index.ts
DELETED