tdk-api-wrapper 1.0.1 → 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.
- package/README.md +53 -6
- package/dist/chunk-2TA5PMVZ.mjs +741 -0
- package/dist/cli.js +683 -85
- package/dist/cli.mjs +222 -37
- package/dist/index.d.mts +173 -5
- package/dist/index.d.ts +173 -5
- package/dist/index.js +471 -52
- package/dist/index.mjs +9 -3
- package/package.json +1 -1
- package/src/cli.ts +227 -36
- package/src/errors.ts +38 -0
- package/src/index.ts +1 -0
- package/src/tdk.ts +449 -61
- package/src/types.ts +36 -0
- package/dist/chunk-MGSXCUAX.mjs +0 -325
package/dist/cli.mjs
CHANGED
|
@@ -1,79 +1,264 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
TDK
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-2TA5PMVZ.mjs";
|
|
5
5
|
|
|
6
6
|
// src/cli.ts
|
|
7
|
-
var
|
|
7
|
+
var rawArgs = process.argv.slice(2);
|
|
8
|
+
var jsonMode = rawArgs.includes("--json");
|
|
9
|
+
var args = rawArgs.filter((a) => a !== "--json");
|
|
10
|
+
var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
11
|
+
"ara",
|
|
12
|
+
"anlam",
|
|
13
|
+
"koken",
|
|
14
|
+
"ornek",
|
|
15
|
+
"hece",
|
|
16
|
+
"uyum",
|
|
17
|
+
"yazim",
|
|
18
|
+
"gunun",
|
|
19
|
+
"rastgele",
|
|
20
|
+
"esanlam",
|
|
21
|
+
"karsit",
|
|
22
|
+
"yabanci",
|
|
23
|
+
"kurallar",
|
|
24
|
+
"kural",
|
|
25
|
+
"karsilastir",
|
|
26
|
+
"analiz",
|
|
27
|
+
"oneri"
|
|
28
|
+
]);
|
|
8
29
|
var command = args[0];
|
|
9
|
-
var word = args
|
|
30
|
+
var word = args.slice(1).join(" ");
|
|
31
|
+
if (command && !KNOWN_COMMANDS.has(command) && command !== "--help" && command !== "-h") {
|
|
32
|
+
word = args.join(" ");
|
|
33
|
+
command = "anlam";
|
|
34
|
+
}
|
|
35
|
+
function printResult(data, formatted) {
|
|
36
|
+
if (jsonMode) {
|
|
37
|
+
console.log(JSON.stringify(data));
|
|
38
|
+
} else {
|
|
39
|
+
formatted();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function printError(message) {
|
|
43
|
+
if (jsonMode) {
|
|
44
|
+
console.log(JSON.stringify({ error: message }));
|
|
45
|
+
} else {
|
|
46
|
+
console.log(`Hata: ${message}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
10
49
|
async function run() {
|
|
11
|
-
if (!command) {
|
|
12
|
-
console.log("Kullan\u0131m: tdk
|
|
13
|
-
console.log(
|
|
14
|
-
|
|
50
|
+
if (!command || command === "--help" || command === "-h") {
|
|
51
|
+
console.log("Kullan\u0131m: tdk [komut] <kelime> [--json]");
|
|
52
|
+
console.log(
|
|
53
|
+
"Komutlar: ara, anlam, koken, ornek, hece, uyum, yazim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri"
|
|
54
|
+
);
|
|
55
|
+
console.log("Not: Komut belirtilmezse do\u011Frudan kelime anlam\u0131 aran\u0131r (\xF6rn: tdk selam)");
|
|
56
|
+
process.exit(command ? 0 : 1);
|
|
15
57
|
}
|
|
16
58
|
TDK.enableCache(false);
|
|
17
59
|
try {
|
|
18
60
|
switch (command) {
|
|
19
61
|
case "ara":
|
|
20
|
-
case "anlam":
|
|
62
|
+
case "anlam": {
|
|
21
63
|
if (!word)
|
|
22
64
|
throw new Error("Kelime belirtmelisiniz.");
|
|
23
65
|
const meanings = await TDK.getMeanings(word);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
66
|
+
printResult(meanings, () => {
|
|
67
|
+
if (meanings.length === 0) {
|
|
68
|
+
console.log("Sonu\xE7 bulunamad\u0131.");
|
|
69
|
+
} else {
|
|
70
|
+
meanings.forEach((m, i) => console.log(`${i + 1}. ${m}`));
|
|
71
|
+
}
|
|
72
|
+
});
|
|
29
73
|
break;
|
|
30
|
-
|
|
74
|
+
}
|
|
75
|
+
case "koken": {
|
|
31
76
|
if (!word)
|
|
32
77
|
throw new Error("Kelime belirtmelisiniz.");
|
|
33
78
|
const origin = await TDK.getOrigin(word);
|
|
34
|
-
console.log(`K\xF6ken: ${origin}`);
|
|
79
|
+
printResult({ word, origin }, () => console.log(`K\xF6ken: ${origin}`));
|
|
35
80
|
break;
|
|
36
|
-
|
|
81
|
+
}
|
|
82
|
+
case "ornek": {
|
|
37
83
|
if (!word)
|
|
38
84
|
throw new Error("Kelime belirtmelisiniz.");
|
|
39
85
|
const examples = await TDK.getExamples(word);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
86
|
+
printResult(examples, () => {
|
|
87
|
+
if (examples.length === 0) {
|
|
88
|
+
console.log("\xD6rnek bulunamad\u0131.");
|
|
89
|
+
} else {
|
|
90
|
+
examples.forEach((ex, i) => {
|
|
91
|
+
const yazar = ex.author ? ` (${ex.author})` : "";
|
|
92
|
+
console.log(`${i + 1}. ${ex.sentence}${yazar}`);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
case "hece": {
|
|
50
99
|
if (!word)
|
|
51
100
|
throw new Error("Kelime belirtmelisiniz.");
|
|
52
101
|
const syllables = TDK.syllabicate(word);
|
|
53
|
-
console.log(`Heceler: ${syllables.join("-")}`);
|
|
102
|
+
printResult(syllables, () => console.log(`Heceler: ${syllables.join("-")}`));
|
|
54
103
|
break;
|
|
55
|
-
|
|
104
|
+
}
|
|
105
|
+
case "uyum": {
|
|
56
106
|
if (!word)
|
|
57
107
|
throw new Error("Kelime belirtmelisiniz.");
|
|
58
108
|
const isHarmony = TDK.checkVowelHarmony(word);
|
|
59
|
-
|
|
109
|
+
printResult(
|
|
110
|
+
{ word, harmony: isHarmony },
|
|
111
|
+
() => console.log(`B\xFCy\xFCk \xDCnl\xFC Uyumu: ${isHarmony ? "Uyar" : "Uymaz"}`)
|
|
112
|
+
);
|
|
60
113
|
break;
|
|
61
|
-
|
|
114
|
+
}
|
|
115
|
+
case "yazim": {
|
|
62
116
|
if (!word)
|
|
63
117
|
throw new Error("Kelime belirtmelisiniz.");
|
|
64
118
|
const spellResult = await TDK.checkSpelling(word);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
119
|
+
printResult(spellResult, () => {
|
|
120
|
+
if (spellResult.isCorrect) {
|
|
121
|
+
console.log("Do\u011Fru yaz\u0131m.");
|
|
122
|
+
} else {
|
|
123
|
+
console.log(`Yanl\u0131\u015F yaz\u0131m.${spellResult.suggestion ? " Do\u011Frusu: " + spellResult.suggestion : ""}`);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
case "gunun": {
|
|
129
|
+
const wotd = await TDK.getWordOfTheDay();
|
|
130
|
+
printResult(wotd, () => {
|
|
131
|
+
if (!wotd) {
|
|
132
|
+
console.log("G\xFCn\xFCn kelimesi al\u0131namad\u0131.");
|
|
133
|
+
} else {
|
|
134
|
+
console.log(`G\xFCn\xFCn kelimesi: ${wotd.word}`);
|
|
135
|
+
wotd.meanings.forEach((m, i) => console.log(`${i + 1}. ${m}`));
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case "rastgele": {
|
|
141
|
+
const pick = await TDK.getRandomWord();
|
|
142
|
+
printResult(pick, () => {
|
|
143
|
+
if (!pick) {
|
|
144
|
+
console.log("Rastgele i\xE7erik al\u0131namad\u0131.");
|
|
145
|
+
} else {
|
|
146
|
+
const label = pick.type === "kelime" ? "Kelime" : "Atas\xF6z\xFC";
|
|
147
|
+
console.log(`${label}: ${pick.madde}`);
|
|
148
|
+
console.log(pick.anlam);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case "esanlam": {
|
|
154
|
+
if (!word)
|
|
155
|
+
throw new Error("Kelime belirtmelisiniz.");
|
|
156
|
+
const synonyms = await TDK.getSynonyms(word);
|
|
157
|
+
printResult(synonyms, () => {
|
|
158
|
+
if (synonyms.length === 0) {
|
|
159
|
+
console.log("E\u015F anlaml\u0131 kelime bulunamad\u0131.");
|
|
160
|
+
} else {
|
|
161
|
+
synonyms.forEach((s, i) => console.log(`${i + 1}. ${s}`));
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
case "karsit": {
|
|
167
|
+
if (!word)
|
|
168
|
+
throw new Error("Kelime belirtmelisiniz.");
|
|
169
|
+
const antonyms = await TDK.getAntonyms(word);
|
|
170
|
+
printResult(antonyms, () => {
|
|
171
|
+
if (antonyms.length === 0) {
|
|
172
|
+
console.log("Z\u0131t anlaml\u0131 kelime bulunamad\u0131.");
|
|
173
|
+
} else {
|
|
174
|
+
antonyms.forEach((s, i) => console.log(`${i + 1}. ${s}`));
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case "yabanci": {
|
|
180
|
+
if (!word)
|
|
181
|
+
throw new Error("Kelime belirtmelisiniz.");
|
|
182
|
+
const foreign = await TDK.isForeignWord(word);
|
|
183
|
+
printResult({ word, foreign }, () => {
|
|
184
|
+
if (foreign === null) {
|
|
185
|
+
console.log("Kelime bulunamad\u0131.");
|
|
186
|
+
} else {
|
|
187
|
+
console.log(foreign ? "Yabanc\u0131 k\xF6kenli." : "T\xFCrk\xE7e k\xF6kenli.");
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case "kurallar": {
|
|
193
|
+
const rules = await TDK.getKurallar();
|
|
194
|
+
printResult(rules, () => {
|
|
195
|
+
if (rules.length === 0) {
|
|
196
|
+
console.log("Kural listesi al\u0131namad\u0131.");
|
|
197
|
+
} else {
|
|
198
|
+
rules.forEach((r, i) => console.log(`${i + 1}. ${r.adi}`));
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
case "kural": {
|
|
204
|
+
if (!word)
|
|
205
|
+
throw new Error("Kural ad\u0131 belirtmelisiniz.");
|
|
206
|
+
const rule = await TDK.getRule(word);
|
|
207
|
+
printResult(rule, () => {
|
|
208
|
+
console.log(rule ?? "Kural bulunamad\u0131.");
|
|
209
|
+
});
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
case "karsilastir": {
|
|
213
|
+
const [wordA, wordB] = args.slice(1);
|
|
214
|
+
if (!wordA || !wordB)
|
|
215
|
+
throw new Error("\u0130ki kelime belirtmelisiniz.");
|
|
216
|
+
const comparison = await TDK.compareWords(wordA, wordB);
|
|
217
|
+
printResult(comparison, () => {
|
|
218
|
+
for (const side of [comparison.a, comparison.b]) {
|
|
219
|
+
console.log(`${side.word}: ${side.meaningCount} anlam, k\xF6ken: ${side.origin ?? "bulunamad\u0131"}, hece: ${side.syllables.join("-")}, b\xFCy\xFCk \xFCnl\xFC uyumu: ${side.harmony ? "uyar" : "uymaz"}`);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
case "analiz": {
|
|
225
|
+
if (!word)
|
|
226
|
+
throw new Error("Metin belirtmelisiniz.");
|
|
227
|
+
const analysis = await TDK.analyzeText(word);
|
|
228
|
+
printResult(analysis, () => {
|
|
229
|
+
if (analysis.length === 0) {
|
|
230
|
+
console.log("Analiz edilecek kelime bulunamad\u0131.");
|
|
231
|
+
} else {
|
|
232
|
+
analysis.forEach((a) => {
|
|
233
|
+
if (a.found) {
|
|
234
|
+
console.log(`${a.word}: ${a.meaning ?? "-"} (${a.origin})`);
|
|
235
|
+
} else {
|
|
236
|
+
console.log(`${a.word}: bulunamad\u0131`);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
case "oneri": {
|
|
244
|
+
if (!word)
|
|
245
|
+
throw new Error("\xD6nek belirtmelisiniz.");
|
|
246
|
+
const suggestions = await TDK.getSuggestions(word);
|
|
247
|
+
printResult(suggestions, () => {
|
|
248
|
+
if (suggestions.length === 0) {
|
|
249
|
+
console.log("\xD6neri bulunamad\u0131.");
|
|
250
|
+
} else {
|
|
251
|
+
suggestions.forEach((s, i) => console.log(`${i + 1}. ${s}`));
|
|
252
|
+
}
|
|
253
|
+
});
|
|
70
254
|
break;
|
|
255
|
+
}
|
|
71
256
|
default:
|
|
72
|
-
|
|
257
|
+
printError("Bilinmeyen komut.");
|
|
73
258
|
}
|
|
74
259
|
} catch (error) {
|
|
75
260
|
if (error instanceof Error) {
|
|
76
|
-
|
|
261
|
+
printError(error.message);
|
|
77
262
|
}
|
|
78
263
|
}
|
|
79
264
|
}
|
package/dist/index.d.mts
CHANGED
|
@@ -96,6 +96,36 @@ interface SpellCheckResult {
|
|
|
96
96
|
word: string;
|
|
97
97
|
suggestion?: string;
|
|
98
98
|
}
|
|
99
|
+
interface WordOfTheDay {
|
|
100
|
+
word: string;
|
|
101
|
+
meanings: string[];
|
|
102
|
+
}
|
|
103
|
+
interface DailyPick {
|
|
104
|
+
type: "kelime" | "atasoz";
|
|
105
|
+
madde: string;
|
|
106
|
+
anlam: string;
|
|
107
|
+
}
|
|
108
|
+
interface TDKRule {
|
|
109
|
+
adi: string;
|
|
110
|
+
url: string;
|
|
111
|
+
}
|
|
112
|
+
interface WordComparisonSide {
|
|
113
|
+
word: string;
|
|
114
|
+
meaningCount: number;
|
|
115
|
+
origin: string | null;
|
|
116
|
+
syllables: string[];
|
|
117
|
+
harmony: boolean;
|
|
118
|
+
}
|
|
119
|
+
interface WordComparison {
|
|
120
|
+
a: WordComparisonSide;
|
|
121
|
+
b: WordComparisonSide;
|
|
122
|
+
}
|
|
123
|
+
interface WordAnalysis {
|
|
124
|
+
word: string;
|
|
125
|
+
found: boolean;
|
|
126
|
+
meaning: string | null;
|
|
127
|
+
origin: string | null;
|
|
128
|
+
}
|
|
99
129
|
type TDKResponse = WordInfo[] | {
|
|
100
130
|
error: string;
|
|
101
131
|
};
|
|
@@ -105,6 +135,7 @@ type TDKResponse = WordInfo[] | {
|
|
|
105
135
|
*/
|
|
106
136
|
declare class TDK {
|
|
107
137
|
private static readonly BASE_URL;
|
|
138
|
+
private static readonly AUDIO_API_HOST;
|
|
108
139
|
private static isCacheEnabled;
|
|
109
140
|
private static wordCache;
|
|
110
141
|
private static dailyContentCache;
|
|
@@ -127,7 +158,22 @@ declare class TDK {
|
|
|
127
158
|
*/
|
|
128
159
|
static getMeanings(word: string): Promise<string[]>;
|
|
129
160
|
/**
|
|
130
|
-
*
|
|
161
|
+
* `sozluk.gov.tr`'s dedicated `/autocomplete.json` (and `/data/autocomplete.json`)
|
|
162
|
+
* routes no longer serve JSON — they fall through to the SPA's `index.html`.
|
|
163
|
+
* The full ~81k-word headword list the site's own autocomplete UI uses is
|
|
164
|
+
* instead bundled directly into its main JS asset as a
|
|
165
|
+
* `JSON.parse(\`[{"madde":"..."}]\`)` literal, so this fetches the home
|
|
166
|
+
* page to find that asset's current hashed filename, downloads it (a few
|
|
167
|
+
* MB, only once per process), and extracts the literal out of it. Fragile
|
|
168
|
+
* scraping of an implementation detail — if TDK's build stops embedding
|
|
169
|
+
* this, this fails closed to `[]` rather than throwing.
|
|
170
|
+
*/
|
|
171
|
+
private static fetchAutocompleteData;
|
|
172
|
+
/**
|
|
173
|
+
* Returns autocomplete suggestions for a given prefix, searched over TDK's
|
|
174
|
+
* full headword list (see `fetchAutocompleteData`). The list is fetched
|
|
175
|
+
* and cached once per process regardless of `enableCache()` — the same
|
|
176
|
+
* caching behavior as before — and only cleared by `clearCache()`.
|
|
131
177
|
*/
|
|
132
178
|
static getSuggestions(prefix: string): Promise<string[]>;
|
|
133
179
|
/**
|
|
@@ -135,9 +181,21 @@ declare class TDK {
|
|
|
135
181
|
*/
|
|
136
182
|
static getProverbs(word: string): Promise<string[]>;
|
|
137
183
|
/**
|
|
138
|
-
* Returns the etymological origin of the word
|
|
184
|
+
* Returns the etymological origin of the word, or "Türkçe" if TDK doesn't
|
|
185
|
+
* record a foreign origin for it. Returns `null` only when the word itself
|
|
186
|
+
* isn't found in the dictionary at all.
|
|
139
187
|
*/
|
|
140
188
|
static getOrigin(word: string): Promise<string | null>;
|
|
189
|
+
/**
|
|
190
|
+
* Returns whether the word has a recorded foreign etymological origin.
|
|
191
|
+
* Returns `null` (instead of a boolean) when the word isn't found at all.
|
|
192
|
+
*/
|
|
193
|
+
static isForeignWord(word: string): Promise<boolean | null>;
|
|
194
|
+
/**
|
|
195
|
+
* Groups a list of words by their etymological origin. Words not found in
|
|
196
|
+
* the dictionary are grouped under "Bilinmiyor". Throttled like getWordsBatch.
|
|
197
|
+
*/
|
|
198
|
+
static groupByOrigin(words: string[]): Promise<Record<string, string[]>>;
|
|
141
199
|
/**
|
|
142
200
|
* Returns literature examples containing the word.
|
|
143
201
|
*/
|
|
@@ -146,8 +204,34 @@ declare class TDK {
|
|
|
146
204
|
author: string | null;
|
|
147
205
|
}[]>;
|
|
148
206
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
207
|
+
* Calls the `api.sozluk.gov.tr/gts-yeni` endpoint the official web UI uses
|
|
208
|
+
* internally (richer than the public `/gts`: includes `seskod`,
|
|
209
|
+
* `anlamEsAnlam`/`anlamKarsitAnlam`, etc). That endpoint 403s unless the
|
|
210
|
+
* request looks like it came from a browser tab on sozluk.gov.tr: it needs
|
|
211
|
+
* an `Origin`/`Referer` pair matching that site AND a browser-like
|
|
212
|
+
* `User-Agent` (our usual `TDK-API-Nodejs-Wrapper/…` UA gets rejected).
|
|
213
|
+
* `fetch` (undici) also strips a manually-set `Origin` header as a
|
|
214
|
+
* forbidden header name, so this uses `node:https` directly instead.
|
|
215
|
+
* This is inherently fragile scraping of an undocumented endpoint — if
|
|
216
|
+
* TDK tightens this check further, this should fail closed to `null`
|
|
217
|
+
* rather than throw.
|
|
218
|
+
*/
|
|
219
|
+
private static fetchGtsYeni;
|
|
220
|
+
private static fetchSeskod;
|
|
221
|
+
/**
|
|
222
|
+
* Returns synonyms ("eş anlamlı kelimeler") recorded for the word, pooled
|
|
223
|
+
* across all of its meanings. Uses the same undocumented `gts-yeni`
|
|
224
|
+
* endpoint as `getAudioUrl` — returns `[]` if the lookup fails.
|
|
225
|
+
*/
|
|
226
|
+
static getSynonyms(word: string): Promise<string[]>;
|
|
227
|
+
/**
|
|
228
|
+
* Returns antonyms ("zıt anlamlı kelimeler") recorded for the word, pooled
|
|
229
|
+
* across all of its meanings. Uses the same undocumented `gts-yeni`
|
|
230
|
+
* endpoint as `getAudioUrl` — returns `[]` if the lookup fails.
|
|
231
|
+
*/
|
|
232
|
+
static getAntonyms(word: string): Promise<string[]>;
|
|
233
|
+
/**
|
|
234
|
+
* Returns the direct URL of the audio pronunciation, if TDK has one recorded for this word.
|
|
151
235
|
*/
|
|
152
236
|
static getAudioUrl(word: string): Promise<string | null>;
|
|
153
237
|
/**
|
|
@@ -162,14 +246,70 @@ declare class TDK {
|
|
|
162
246
|
* Fetches daily content (word of the day, proverbs, rules, etc).
|
|
163
247
|
*/
|
|
164
248
|
static getDailyContent(): Promise<DailyContent | null>;
|
|
249
|
+
/**
|
|
250
|
+
* Returns today's word of the day along with all of its listed meanings.
|
|
251
|
+
*/
|
|
252
|
+
static getWordOfTheDay(): Promise<WordOfTheDay | null>;
|
|
253
|
+
/**
|
|
254
|
+
* Picks a random entry (word or proverb) from today's daily content.
|
|
255
|
+
* Note: this samples from today's `getDailyContent()` picks, not the full dictionary.
|
|
256
|
+
*/
|
|
257
|
+
static getRandomWord(): Promise<DailyPick | null>;
|
|
258
|
+
/**
|
|
259
|
+
* Returns the spelling-rule page(s) ("yazım kuralları") linked from TDK's
|
|
260
|
+
* `/icerik` daily-content feed, e.g. `{ adi: "Kısaltmalar", url: "https://..." }`.
|
|
261
|
+
* Note: like `getRandomWord()`, this is NOT a fixed catalog — `/icerik`
|
|
262
|
+
* appears to hand back a single randomly-rotated rule per request, so two
|
|
263
|
+
* calls a second apart can return entirely different rules.
|
|
264
|
+
*/
|
|
265
|
+
static getKurallar(): Promise<TDKRule[]>;
|
|
266
|
+
/**
|
|
267
|
+
* Fetches the full plain-text content of a named spelling rule (matched
|
|
268
|
+
* case-insensitively, substring match) from `tdk.gov.tr`. Since `/icerik`
|
|
269
|
+
* hands back a single randomly-rotated rule per request (out of a pool of
|
|
270
|
+
* roughly twenty) rather than a fixed catalog, a single `getKurallar()`
|
|
271
|
+
* draw would rarely match a given name — this re-draws (bounded, with a
|
|
272
|
+
* short delay) until it finds a match or gives up. Returns `null` if no
|
|
273
|
+
* match turns up within the attempt budget or the matched page can't be
|
|
274
|
+
* parsed.
|
|
275
|
+
*/
|
|
276
|
+
static getRule(name: string): Promise<string | null>;
|
|
277
|
+
/**
|
|
278
|
+
* `tdk.gov.tr` rule pages are WordPress/Avada-themed. The actual article
|
|
279
|
+
* text lives in `<div ... itemprop="text">...</div>` right before a
|
|
280
|
+
* `<footer class="entry...">` (share buttons, author box, structured-data
|
|
281
|
+
* spans) — cutting there avoids that trailing cruft.
|
|
282
|
+
*/
|
|
283
|
+
private static fetchRuleText;
|
|
284
|
+
private static htmlToPlainText;
|
|
165
285
|
/**
|
|
166
286
|
* Returns compound words that contain this word.
|
|
167
287
|
*/
|
|
168
288
|
static getCompoundWords(word: string): Promise<string[]>;
|
|
169
289
|
/**
|
|
170
290
|
* Returns the part of speech (isim, sıfat, zarf vb.).
|
|
291
|
+
* TDK's `ozelliklerListe` mixes grammatical categories (`tur: "3"`, e.g.
|
|
292
|
+
* sıfat/zarf/isim) with usage-register tags (`tur: "4"`, e.g. mecaz/argo)
|
|
293
|
+
* in the same list — only `tur === "3"` entries are actual parts of speech.
|
|
171
294
|
*/
|
|
172
295
|
static getPartOfSpeech(word: string): Promise<string[]>;
|
|
296
|
+
/**
|
|
297
|
+
* Compares two words side by side: meaning count, etymological origin,
|
|
298
|
+
* syllables and vowel-harmony compliance.
|
|
299
|
+
*/
|
|
300
|
+
static compareWords(a: string, b: string): Promise<WordComparison>;
|
|
301
|
+
private static readonly STOPWORDS;
|
|
302
|
+
private static firstMeaning;
|
|
303
|
+
/**
|
|
304
|
+
* Analyzes every distinct word in a text (Turkish stopwords filtered out),
|
|
305
|
+
* returning each word's first meaning and etymological origin if found.
|
|
306
|
+
* Looks each word up individually (throttled), so scales with text length.
|
|
307
|
+
*/
|
|
308
|
+
static analyzeText(text: string): Promise<WordAnalysis[]>;
|
|
309
|
+
/**
|
|
310
|
+
* Classic edit-distance between two strings.
|
|
311
|
+
*/
|
|
312
|
+
private static levenshtein;
|
|
173
313
|
/**
|
|
174
314
|
* Fetches multiple words concurrently with a small delay to avoid rate limiting.
|
|
175
315
|
*/
|
|
@@ -180,8 +320,36 @@ declare class TDK {
|
|
|
180
320
|
static syllabicate(word: string): string[];
|
|
181
321
|
/**
|
|
182
322
|
* Checks if a word follows Turkish Major Vowel Harmony (Büyük Ünlü Uyumu).
|
|
323
|
+
* Normalizes case via the Turkish locale first: a plain case-insensitive
|
|
324
|
+
* regex would fold ASCII "I" to "i", misreading the back vowel "I"
|
|
325
|
+
* (dotless) as the front vowel "i" (dotted).
|
|
183
326
|
*/
|
|
184
327
|
static checkVowelHarmony(word: string): boolean;
|
|
185
328
|
}
|
|
186
329
|
|
|
187
|
-
|
|
330
|
+
/**
|
|
331
|
+
* Base class for all errors thrown by this library.
|
|
332
|
+
*/
|
|
333
|
+
declare class TDKError extends Error {
|
|
334
|
+
constructor(message: string);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Thrown when a caller-supplied argument is invalid (e.g. an empty word).
|
|
338
|
+
*/
|
|
339
|
+
declare class TDKValidationError extends TDKError {
|
|
340
|
+
constructor(message: string);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Thrown when a request to sozluk.gov.tr fails at the network/HTTP level
|
|
344
|
+
* (connection failure, non-OK HTTP status, unparsable response, etc).
|
|
345
|
+
*/
|
|
346
|
+
declare class TDKNetworkError extends TDKError {
|
|
347
|
+
readonly status?: number;
|
|
348
|
+
readonly cause?: unknown;
|
|
349
|
+
constructor(message: string, options?: {
|
|
350
|
+
status?: number;
|
|
351
|
+
cause?: unknown;
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export { type Author, type DailyContent, type DailyPick, type Example, type Feature, type Meaning, type Proverb, type SpellCheckResult, TDK, TDKError, TDKNetworkError, type TDKResponse, type TDKRule, TDKValidationError, type WordAnalysis, type WordComparison, type WordComparisonSide, type WordInfo, type WordOfTheDay };
|