tdk-api-wrapper 1.2.2 → 1.3.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 +11 -0
- package/dist/{chunk-SNY3KUCF.mjs → chunk-SLNXKZKR.mjs} +238 -1
- package/dist/cli.js +283 -3
- package/dist/cli.mjs +46 -3
- package/dist/index.d.mts +75 -1
- package/dist/index.d.ts +75 -1
- package/dist/index.js +238 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/cli.ts +41 -1
- package/src/tdk.ts +240 -1
- package/src/types.ts +10 -0
package/dist/index.d.mts
CHANGED
|
@@ -126,6 +126,14 @@ interface WordAnalysis {
|
|
|
126
126
|
meaning: string | null;
|
|
127
127
|
origin: string | null;
|
|
128
128
|
}
|
|
129
|
+
interface KubbealtiEntry {
|
|
130
|
+
kelime: string;
|
|
131
|
+
anlam: string;
|
|
132
|
+
}
|
|
133
|
+
interface WiktionaryEntry {
|
|
134
|
+
raw: string;
|
|
135
|
+
sections: Record<string, string>;
|
|
136
|
+
}
|
|
129
137
|
type TDKResponse = WordInfo[] | {
|
|
130
138
|
error: string;
|
|
131
139
|
};
|
|
@@ -136,6 +144,20 @@ type TDKResponse = WordInfo[] | {
|
|
|
136
144
|
declare class TDK {
|
|
137
145
|
private static readonly BASE_URL;
|
|
138
146
|
private static readonly AUDIO_API_HOST;
|
|
147
|
+
private static readonly KUBBEALTI_HOST;
|
|
148
|
+
/**
|
|
149
|
+
* `eski.lugatim.com` (Kubbealtı Lugatı's data API) sends only its leaf
|
|
150
|
+
* certificate during the TLS handshake, omitting the intermediates a
|
|
151
|
+
* correctly configured server would include — a server-side misconfiguration,
|
|
152
|
+
* not something we should paper over by disabling verification. These are
|
|
153
|
+
* the two certificates the server *should* be sending (fetched from the
|
|
154
|
+
* leaf's own Authority Information Access URLs), supplied here so Node can
|
|
155
|
+
* still build a full, properly verified chain up to a root it already
|
|
156
|
+
* trusts (ISRG Root X1). If Let's Encrypt rotates this intermediate, this
|
|
157
|
+
* stops working and every Kubbealtı call fails closed to `null` — same
|
|
158
|
+
* fail-closed contract as the rest of this file's fragile integrations.
|
|
159
|
+
*/
|
|
160
|
+
private static readonly KUBBEALTI_EXTRA_CA;
|
|
139
161
|
private static isCacheEnabled;
|
|
140
162
|
private static wordCache;
|
|
141
163
|
private static dailyContentCache;
|
|
@@ -296,6 +318,58 @@ declare class TDK {
|
|
|
296
318
|
*/
|
|
297
319
|
private static fetchRuleText;
|
|
298
320
|
private static htmlToPlainText;
|
|
321
|
+
/**
|
|
322
|
+
* GETs a JSON path from Kubbealtı Lugatı's data API (`eski.lugatim.com`),
|
|
323
|
+
* supplying `KUBBEALTI_EXTRA_CA` to work around that host's incomplete
|
|
324
|
+
* certificate chain (see the constant's doc comment). Fails closed to
|
|
325
|
+
* `null` on any error — network, TLS, HTTP, or JSON parse.
|
|
326
|
+
*/
|
|
327
|
+
private static fetchKubbealtiJson;
|
|
328
|
+
/**
|
|
329
|
+
* Returns Kubbealtı Lugatı ("Misalli Büyük Türkçe Sözlük") entries for a
|
|
330
|
+
* word, scraped from the site's own data API — undocumented, and Kubbealtı
|
|
331
|
+
* Lugatı is a commercial dictionary product, unlike TDK's or Wiktionary's
|
|
332
|
+
* openly-published data, so use this in line with their terms. `anlam` is
|
|
333
|
+
* raw HTML (rich typography markup); use `getKubbealtiMeanings()` for
|
|
334
|
+
* plain text. Returns `null` on any fetch/parse failure, `[]` if the word
|
|
335
|
+
* isn't found.
|
|
336
|
+
*/
|
|
337
|
+
static getKubbealti(word: string): Promise<KubbealtiEntry[] | null>;
|
|
338
|
+
/**
|
|
339
|
+
* Same as `getKubbealti()` but with each entry's `anlam` HTML stripped to
|
|
340
|
+
* plain text via `htmlToPlainText()`.
|
|
341
|
+
*/
|
|
342
|
+
static getKubbealtiMeanings(word: string): Promise<string[] | null>;
|
|
343
|
+
/**
|
|
344
|
+
* Autocomplete suggestions from Kubbealtı Lugatı's own typeahead endpoint
|
|
345
|
+
* (separate from `getSuggestions()`, which uses TDK's data).
|
|
346
|
+
*/
|
|
347
|
+
static getKubbealtiSuggestions(prefix: string): Promise<string[]>;
|
|
348
|
+
/**
|
|
349
|
+
* Returns the etymology paragraph for a word from Nişanyan Sözlük, scraped
|
|
350
|
+
* from that page's server-rendered `<meta name="description">` tag (the
|
|
351
|
+
* page already puts the full etymology text there for SEO, so no need to
|
|
352
|
+
* parse the site's internal SvelteKit data format). Returns `null` if the
|
|
353
|
+
* word isn't found (the page falls back to a generic site tagline in that
|
|
354
|
+
* case) or the request fails.
|
|
355
|
+
*/
|
|
356
|
+
static getNisanyan(word: string): Promise<string | null>;
|
|
357
|
+
/**
|
|
358
|
+
* Returns the Turkish Wiktionary (`tr.wiktionary.org`) entry for a word,
|
|
359
|
+
* via MediaWiki's official Action API (`action=query&prop=extracts`) — no
|
|
360
|
+
* scraping involved, this is a stable, documented public API. `sections`
|
|
361
|
+
* splits the plain-text extract on its `== Heading ==`/`=== Heading ===`
|
|
362
|
+
* markers (e.g. "Köken", "Söyleniş", "Ad") for convenience; `raw` has the
|
|
363
|
+
* unsplit text. Returns `null` if the page doesn't exist or the request
|
|
364
|
+
* fails.
|
|
365
|
+
*/
|
|
366
|
+
static getWiktionary(word: string): Promise<WiktionaryEntry | null>;
|
|
367
|
+
/**
|
|
368
|
+
* Convenience filter over `getWiktionary()`: returns just one section's
|
|
369
|
+
* text (e.g. `getWiktionarySection(word, "Köken")` for etymology), matched
|
|
370
|
+
* case-insensitively. Returns `null` if the word or the section isn't found.
|
|
371
|
+
*/
|
|
372
|
+
static getWiktionarySection(word: string, sectionName: string): Promise<string | null>;
|
|
299
373
|
/**
|
|
300
374
|
* Returns compound words that contain this word.
|
|
301
375
|
*/
|
|
@@ -375,4 +449,4 @@ declare class TDKNetworkError extends TDKError {
|
|
|
375
449
|
});
|
|
376
450
|
}
|
|
377
451
|
|
|
378
|
-
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 };
|
|
452
|
+
export { type Author, type DailyContent, type DailyPick, type Example, type Feature, type KubbealtiEntry, type Meaning, type Proverb, type SpellCheckResult, TDK, TDKError, TDKNetworkError, type TDKResponse, type TDKRule, TDKValidationError, type WiktionaryEntry, type WordAnalysis, type WordComparison, type WordComparisonSide, type WordInfo, type WordOfTheDay };
|
package/dist/index.d.ts
CHANGED
|
@@ -126,6 +126,14 @@ interface WordAnalysis {
|
|
|
126
126
|
meaning: string | null;
|
|
127
127
|
origin: string | null;
|
|
128
128
|
}
|
|
129
|
+
interface KubbealtiEntry {
|
|
130
|
+
kelime: string;
|
|
131
|
+
anlam: string;
|
|
132
|
+
}
|
|
133
|
+
interface WiktionaryEntry {
|
|
134
|
+
raw: string;
|
|
135
|
+
sections: Record<string, string>;
|
|
136
|
+
}
|
|
129
137
|
type TDKResponse = WordInfo[] | {
|
|
130
138
|
error: string;
|
|
131
139
|
};
|
|
@@ -136,6 +144,20 @@ type TDKResponse = WordInfo[] | {
|
|
|
136
144
|
declare class TDK {
|
|
137
145
|
private static readonly BASE_URL;
|
|
138
146
|
private static readonly AUDIO_API_HOST;
|
|
147
|
+
private static readonly KUBBEALTI_HOST;
|
|
148
|
+
/**
|
|
149
|
+
* `eski.lugatim.com` (Kubbealtı Lugatı's data API) sends only its leaf
|
|
150
|
+
* certificate during the TLS handshake, omitting the intermediates a
|
|
151
|
+
* correctly configured server would include — a server-side misconfiguration,
|
|
152
|
+
* not something we should paper over by disabling verification. These are
|
|
153
|
+
* the two certificates the server *should* be sending (fetched from the
|
|
154
|
+
* leaf's own Authority Information Access URLs), supplied here so Node can
|
|
155
|
+
* still build a full, properly verified chain up to a root it already
|
|
156
|
+
* trusts (ISRG Root X1). If Let's Encrypt rotates this intermediate, this
|
|
157
|
+
* stops working and every Kubbealtı call fails closed to `null` — same
|
|
158
|
+
* fail-closed contract as the rest of this file's fragile integrations.
|
|
159
|
+
*/
|
|
160
|
+
private static readonly KUBBEALTI_EXTRA_CA;
|
|
139
161
|
private static isCacheEnabled;
|
|
140
162
|
private static wordCache;
|
|
141
163
|
private static dailyContentCache;
|
|
@@ -296,6 +318,58 @@ declare class TDK {
|
|
|
296
318
|
*/
|
|
297
319
|
private static fetchRuleText;
|
|
298
320
|
private static htmlToPlainText;
|
|
321
|
+
/**
|
|
322
|
+
* GETs a JSON path from Kubbealtı Lugatı's data API (`eski.lugatim.com`),
|
|
323
|
+
* supplying `KUBBEALTI_EXTRA_CA` to work around that host's incomplete
|
|
324
|
+
* certificate chain (see the constant's doc comment). Fails closed to
|
|
325
|
+
* `null` on any error — network, TLS, HTTP, or JSON parse.
|
|
326
|
+
*/
|
|
327
|
+
private static fetchKubbealtiJson;
|
|
328
|
+
/**
|
|
329
|
+
* Returns Kubbealtı Lugatı ("Misalli Büyük Türkçe Sözlük") entries for a
|
|
330
|
+
* word, scraped from the site's own data API — undocumented, and Kubbealtı
|
|
331
|
+
* Lugatı is a commercial dictionary product, unlike TDK's or Wiktionary's
|
|
332
|
+
* openly-published data, so use this in line with their terms. `anlam` is
|
|
333
|
+
* raw HTML (rich typography markup); use `getKubbealtiMeanings()` for
|
|
334
|
+
* plain text. Returns `null` on any fetch/parse failure, `[]` if the word
|
|
335
|
+
* isn't found.
|
|
336
|
+
*/
|
|
337
|
+
static getKubbealti(word: string): Promise<KubbealtiEntry[] | null>;
|
|
338
|
+
/**
|
|
339
|
+
* Same as `getKubbealti()` but with each entry's `anlam` HTML stripped to
|
|
340
|
+
* plain text via `htmlToPlainText()`.
|
|
341
|
+
*/
|
|
342
|
+
static getKubbealtiMeanings(word: string): Promise<string[] | null>;
|
|
343
|
+
/**
|
|
344
|
+
* Autocomplete suggestions from Kubbealtı Lugatı's own typeahead endpoint
|
|
345
|
+
* (separate from `getSuggestions()`, which uses TDK's data).
|
|
346
|
+
*/
|
|
347
|
+
static getKubbealtiSuggestions(prefix: string): Promise<string[]>;
|
|
348
|
+
/**
|
|
349
|
+
* Returns the etymology paragraph for a word from Nişanyan Sözlük, scraped
|
|
350
|
+
* from that page's server-rendered `<meta name="description">` tag (the
|
|
351
|
+
* page already puts the full etymology text there for SEO, so no need to
|
|
352
|
+
* parse the site's internal SvelteKit data format). Returns `null` if the
|
|
353
|
+
* word isn't found (the page falls back to a generic site tagline in that
|
|
354
|
+
* case) or the request fails.
|
|
355
|
+
*/
|
|
356
|
+
static getNisanyan(word: string): Promise<string | null>;
|
|
357
|
+
/**
|
|
358
|
+
* Returns the Turkish Wiktionary (`tr.wiktionary.org`) entry for a word,
|
|
359
|
+
* via MediaWiki's official Action API (`action=query&prop=extracts`) — no
|
|
360
|
+
* scraping involved, this is a stable, documented public API. `sections`
|
|
361
|
+
* splits the plain-text extract on its `== Heading ==`/`=== Heading ===`
|
|
362
|
+
* markers (e.g. "Köken", "Söyleniş", "Ad") for convenience; `raw` has the
|
|
363
|
+
* unsplit text. Returns `null` if the page doesn't exist or the request
|
|
364
|
+
* fails.
|
|
365
|
+
*/
|
|
366
|
+
static getWiktionary(word: string): Promise<WiktionaryEntry | null>;
|
|
367
|
+
/**
|
|
368
|
+
* Convenience filter over `getWiktionary()`: returns just one section's
|
|
369
|
+
* text (e.g. `getWiktionarySection(word, "Köken")` for etymology), matched
|
|
370
|
+
* case-insensitively. Returns `null` if the word or the section isn't found.
|
|
371
|
+
*/
|
|
372
|
+
static getWiktionarySection(word: string, sectionName: string): Promise<string | null>;
|
|
299
373
|
/**
|
|
300
374
|
* Returns compound words that contain this word.
|
|
301
375
|
*/
|
|
@@ -375,4 +449,4 @@ declare class TDKNetworkError extends TDKError {
|
|
|
375
449
|
});
|
|
376
450
|
}
|
|
377
451
|
|
|
378
|
-
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 };
|
|
452
|
+
export { type Author, type DailyContent, type DailyPick, type Example, type Feature, type KubbealtiEntry, type Meaning, type Proverb, type SpellCheckResult, TDK, TDKError, TDKNetworkError, type TDKResponse, type TDKRule, TDKValidationError, type WiktionaryEntry, type WordAnalysis, type WordComparison, type WordComparisonSide, type WordInfo, type WordOfTheDay };
|
package/dist/index.js
CHANGED
|
@@ -69,9 +69,87 @@ var fs = __toESM(require("fs"));
|
|
|
69
69
|
var path = __toESM(require("path"));
|
|
70
70
|
var os = __toESM(require("os"));
|
|
71
71
|
var https = __toESM(require("https"));
|
|
72
|
+
var tls = __toESM(require("tls"));
|
|
72
73
|
var TDK = class {
|
|
73
74
|
static BASE_URL = "https://sozluk.gov.tr";
|
|
74
75
|
static AUDIO_API_HOST = "api.sozluk.gov.tr";
|
|
76
|
+
static KUBBEALTI_HOST = "eski.lugatim.com";
|
|
77
|
+
/**
|
|
78
|
+
* `eski.lugatim.com` (Kubbealtı Lugatı's data API) sends only its leaf
|
|
79
|
+
* certificate during the TLS handshake, omitting the intermediates a
|
|
80
|
+
* correctly configured server would include — a server-side misconfiguration,
|
|
81
|
+
* not something we should paper over by disabling verification. These are
|
|
82
|
+
* the two certificates the server *should* be sending (fetched from the
|
|
83
|
+
* leaf's own Authority Information Access URLs), supplied here so Node can
|
|
84
|
+
* still build a full, properly verified chain up to a root it already
|
|
85
|
+
* trusts (ISRG Root X1). If Let's Encrypt rotates this intermediate, this
|
|
86
|
+
* stops working and every Kubbealtı call fails closed to `null` — same
|
|
87
|
+
* fail-closed contract as the rest of this file's fragile integrations.
|
|
88
|
+
*/
|
|
89
|
+
static KUBBEALTI_EXTRA_CA = [
|
|
90
|
+
`-----BEGIN CERTIFICATE-----
|
|
91
|
+
MIIE2jCCAsKgAwIBAgIQTr0klH4k05SALYSlL9WzGTANBgkqhkiG9w0BAQsFADAu
|
|
92
|
+
MQswCQYDVQQGEwJVUzENMAsGA1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bgb6dNcHkvg3NoaYA==
|
|
151
|
+
-----END CERTIFICATE-----`
|
|
152
|
+
];
|
|
75
153
|
// Cache Mechanism
|
|
76
154
|
static isCacheEnabled = false;
|
|
77
155
|
static wordCache = /* @__PURE__ */ new Map();
|
|
@@ -581,7 +659,166 @@ var TDK = class {
|
|
|
581
659
|
}
|
|
582
660
|
}
|
|
583
661
|
static htmlToPlainText(html) {
|
|
584
|
-
return html.replace(/<br\s*\/?>/gi, "\n").replace(/<\/(p|div)>/gi, "\n\n").replace(/<[^>]+>/g, "").replace(/ /gi, " ").replace(/&
|
|
662
|
+
return html.replace(/<br\s*\/?>/gi, "\n").replace(/<\/(p|div)>/gi, "\n\n").replace(/<[^>]+>/g, "").replace(/ /gi, " ").replace(/</gi, "<").replace(/>/gi, ">").replace(/"/gi, '"').replace(/'|’/gi, "'").replace(/&/gi, "&").replace(/[ \t]+/g, " ").replace(/[ \t]*\n[ \t]*/g, "\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* GETs a JSON path from Kubbealtı Lugatı's data API (`eski.lugatim.com`),
|
|
666
|
+
* supplying `KUBBEALTI_EXTRA_CA` to work around that host's incomplete
|
|
667
|
+
* certificate chain (see the constant's doc comment). Fails closed to
|
|
668
|
+
* `null` on any error — network, TLS, HTTP, or JSON parse.
|
|
669
|
+
*/
|
|
670
|
+
static fetchKubbealtiJson(path2) {
|
|
671
|
+
return new Promise((resolve) => {
|
|
672
|
+
const req = https.request(
|
|
673
|
+
{
|
|
674
|
+
hostname: this.KUBBEALTI_HOST,
|
|
675
|
+
path: path2,
|
|
676
|
+
method: "GET",
|
|
677
|
+
ca: [...tls.rootCertificates, ...this.KUBBEALTI_EXTRA_CA],
|
|
678
|
+
headers: {
|
|
679
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
|
|
680
|
+
}
|
|
681
|
+
},
|
|
682
|
+
(res) => {
|
|
683
|
+
if (res.statusCode !== 200) {
|
|
684
|
+
res.resume();
|
|
685
|
+
resolve(null);
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
let body = "";
|
|
689
|
+
res.on("data", (chunk) => body += chunk);
|
|
690
|
+
res.on("end", () => {
|
|
691
|
+
try {
|
|
692
|
+
resolve(JSON.parse(body));
|
|
693
|
+
} catch {
|
|
694
|
+
resolve(null);
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
);
|
|
699
|
+
req.on("error", () => resolve(null));
|
|
700
|
+
req.end();
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Returns Kubbealtı Lugatı ("Misalli Büyük Türkçe Sözlük") entries for a
|
|
705
|
+
* word, scraped from the site's own data API — undocumented, and Kubbealtı
|
|
706
|
+
* Lugatı is a commercial dictionary product, unlike TDK's or Wiktionary's
|
|
707
|
+
* openly-published data, so use this in line with their terms. `anlam` is
|
|
708
|
+
* raw HTML (rich typography markup); use `getKubbealtiMeanings()` for
|
|
709
|
+
* plain text. Returns `null` on any fetch/parse failure, `[]` if the word
|
|
710
|
+
* isn't found.
|
|
711
|
+
*/
|
|
712
|
+
static async getKubbealti(word) {
|
|
713
|
+
if (!word || word.trim() === "")
|
|
714
|
+
return null;
|
|
715
|
+
const data = await this.fetchKubbealtiJson(`/rest/s/${encodeURIComponent(word.trim())}/`);
|
|
716
|
+
if (!data || !Array.isArray(data.content))
|
|
717
|
+
return null;
|
|
718
|
+
return data.content.map((entry) => ({ kelime: entry.kelime, anlam: entry.anlam }));
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Same as `getKubbealti()` but with each entry's `anlam` HTML stripped to
|
|
722
|
+
* plain text via `htmlToPlainText()`.
|
|
723
|
+
*/
|
|
724
|
+
static async getKubbealtiMeanings(word) {
|
|
725
|
+
const entries = await this.getKubbealti(word);
|
|
726
|
+
if (!entries)
|
|
727
|
+
return null;
|
|
728
|
+
return entries.map((e) => this.htmlToPlainText(e.anlam));
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Autocomplete suggestions from Kubbealtı Lugatı's own typeahead endpoint
|
|
732
|
+
* (separate from `getSuggestions()`, which uses TDK's data).
|
|
733
|
+
*/
|
|
734
|
+
static async getKubbealtiSuggestions(prefix) {
|
|
735
|
+
if (!prefix || prefix.trim() === "")
|
|
736
|
+
return [];
|
|
737
|
+
const data = await this.fetchKubbealtiJson(`/rest/word-search/${encodeURIComponent(prefix.trim())}`);
|
|
738
|
+
if (!Array.isArray(data))
|
|
739
|
+
return [];
|
|
740
|
+
return data.map((item) => item.display).filter(Boolean);
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Returns the etymology paragraph for a word from Nişanyan Sözlük, scraped
|
|
744
|
+
* from that page's server-rendered `<meta name="description">` tag (the
|
|
745
|
+
* page already puts the full etymology text there for SEO, so no need to
|
|
746
|
+
* parse the site's internal SvelteKit data format). Returns `null` if the
|
|
747
|
+
* word isn't found (the page falls back to a generic site tagline in that
|
|
748
|
+
* case) or the request fails.
|
|
749
|
+
*/
|
|
750
|
+
static async getNisanyan(word) {
|
|
751
|
+
if (!word || word.trim() === "")
|
|
752
|
+
return null;
|
|
753
|
+
try {
|
|
754
|
+
const response = await fetch(
|
|
755
|
+
`https://www.nisanyansozluk.com/kelime/${encodeURIComponent(word.trim().toLocaleLowerCase("tr-TR"))}`,
|
|
756
|
+
{ headers: { "User-Agent": "TDK-API-Nodejs-Wrapper/1.0" } }
|
|
757
|
+
);
|
|
758
|
+
if (!response.ok)
|
|
759
|
+
return null;
|
|
760
|
+
const html = await response.text();
|
|
761
|
+
const match = html.match(/<meta name="description" content="([^"]*)"/);
|
|
762
|
+
if (!match)
|
|
763
|
+
return null;
|
|
764
|
+
const description = this.htmlToPlainText(match[1]);
|
|
765
|
+
if (description === "\xC7a\u011Fda\u015F T\xFCrk\xE7enin Etimolojisi")
|
|
766
|
+
return null;
|
|
767
|
+
return description;
|
|
768
|
+
} catch {
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
/**
|
|
773
|
+
* Returns the Turkish Wiktionary (`tr.wiktionary.org`) entry for a word,
|
|
774
|
+
* via MediaWiki's official Action API (`action=query&prop=extracts`) — no
|
|
775
|
+
* scraping involved, this is a stable, documented public API. `sections`
|
|
776
|
+
* splits the plain-text extract on its `== Heading ==`/`=== Heading ===`
|
|
777
|
+
* markers (e.g. "Köken", "Söyleniş", "Ad") for convenience; `raw` has the
|
|
778
|
+
* unsplit text. Returns `null` if the page doesn't exist or the request
|
|
779
|
+
* fails.
|
|
780
|
+
*/
|
|
781
|
+
static async getWiktionary(word) {
|
|
782
|
+
if (!word || word.trim() === "")
|
|
783
|
+
return null;
|
|
784
|
+
try {
|
|
785
|
+
const url = `https://tr.wiktionary.org/w/api.php?action=query&prop=extracts&titles=${encodeURIComponent(
|
|
786
|
+
word.trim()
|
|
787
|
+
)}&format=json&explaintext=1&formatversion=2`;
|
|
788
|
+
const response = await fetch(url, { headers: { "User-Agent": "TDK-API-Nodejs-Wrapper/1.0" } });
|
|
789
|
+
if (!response.ok)
|
|
790
|
+
return null;
|
|
791
|
+
const data = await response.json();
|
|
792
|
+
const page = data?.query?.pages?.[0];
|
|
793
|
+
if (!page || page.missing || !page.extract)
|
|
794
|
+
return null;
|
|
795
|
+
const raw = page.extract;
|
|
796
|
+
const sections = {};
|
|
797
|
+
const parts = raw.split(/\n(={2,4})\s*(.+?)\s*\1\n/);
|
|
798
|
+
for (let i = 1; i < parts.length; i += 3) {
|
|
799
|
+
const title = parts[i + 1]?.trim();
|
|
800
|
+
const content = parts[i + 2]?.trim();
|
|
801
|
+
if (title)
|
|
802
|
+
sections[title] = content ?? "";
|
|
803
|
+
}
|
|
804
|
+
return { raw, sections };
|
|
805
|
+
} catch {
|
|
806
|
+
return null;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Convenience filter over `getWiktionary()`: returns just one section's
|
|
811
|
+
* text (e.g. `getWiktionarySection(word, "Köken")` for etymology), matched
|
|
812
|
+
* case-insensitively. Returns `null` if the word or the section isn't found.
|
|
813
|
+
*/
|
|
814
|
+
static async getWiktionarySection(word, sectionName) {
|
|
815
|
+
const entry = await this.getWiktionary(word);
|
|
816
|
+
if (!entry)
|
|
817
|
+
return null;
|
|
818
|
+
const key = Object.keys(entry.sections).find(
|
|
819
|
+
(k) => k.toLocaleLowerCase("tr-TR") === sectionName.trim().toLocaleLowerCase("tr-TR")
|
|
820
|
+
);
|
|
821
|
+
return key ? entry.sections[key] : null;
|
|
585
822
|
}
|
|
586
823
|
/**
|
|
587
824
|
* Returns compound words that contain this word.
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -22,6 +22,9 @@ const KNOWN_COMMANDS = new Set([
|
|
|
22
22
|
"karsilastir",
|
|
23
23
|
"analiz",
|
|
24
24
|
"oneri",
|
|
25
|
+
"kubbealti",
|
|
26
|
+
"nisanyan",
|
|
27
|
+
"viki",
|
|
25
28
|
]);
|
|
26
29
|
|
|
27
30
|
let command = args[0];
|
|
@@ -52,7 +55,7 @@ async function run() {
|
|
|
52
55
|
if (!command || command === "--help" || command === "-h") {
|
|
53
56
|
console.log("Kullanım: tdk [komut] <kelime> [--json]");
|
|
54
57
|
console.log(
|
|
55
|
-
"Komutlar: ara, anlam, koken, ornek, hece, uyum, yazim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri"
|
|
58
|
+
"Komutlar: ara, anlam, koken, ornek, hece, uyum, yazim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri, kubbealti, nisanyan, viki"
|
|
56
59
|
);
|
|
57
60
|
console.log("Not: Komut belirtilmezse doğrudan kelime anlamı aranır (örn: tdk selam)");
|
|
58
61
|
process.exit(command ? 0 : 1);
|
|
@@ -259,6 +262,43 @@ async function run() {
|
|
|
259
262
|
break;
|
|
260
263
|
}
|
|
261
264
|
|
|
265
|
+
case "kubbealti": {
|
|
266
|
+
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
267
|
+
const meanings = await TDK.getKubbealtiMeanings(word);
|
|
268
|
+
printResult(meanings, () => {
|
|
269
|
+
if (!meanings) {
|
|
270
|
+
console.log("Kubbealtı Lugatı'na ulaşılamadı.");
|
|
271
|
+
} else if (meanings.length === 0) {
|
|
272
|
+
console.log("Sonuç bulunamadı.");
|
|
273
|
+
} else {
|
|
274
|
+
meanings.forEach((m, i) => console.log(`${i + 1}. ${m}`));
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
case "nisanyan": {
|
|
281
|
+
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
282
|
+
const origin = await TDK.getNisanyan(word);
|
|
283
|
+
printResult(origin, () => console.log(origin ?? "Sonuç bulunamadı."));
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
case "viki": {
|
|
288
|
+
if (!word) throw new Error("Kelime belirtmelisiniz.");
|
|
289
|
+
const entry = await TDK.getWiktionary(word);
|
|
290
|
+
printResult(entry, () => {
|
|
291
|
+
if (!entry) {
|
|
292
|
+
console.log("Sonuç bulunamadı.");
|
|
293
|
+
} else {
|
|
294
|
+
for (const [title, content] of Object.entries(entry.sections)) {
|
|
295
|
+
if (content) console.log(`-- ${title} --\n${content}\n`);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
break;
|
|
300
|
+
}
|
|
301
|
+
|
|
262
302
|
default:
|
|
263
303
|
printError("Bilinmeyen komut.");
|
|
264
304
|
}
|