deeplx-lib
Version:
Powerful free DeepL API wrapper with no token required.
67 lines (58 loc) • 2.02 kB
text/typescript
// https://developers.deepl.com/docs/getting-started/supported-languages
type TLanguage = 'AR' | 'BG' | 'CS' | 'DA' | 'DE' | 'EL' | 'EN' | 'ES' | 'ET' | 'FI' | 'FR' | 'HU' | 'ID' | 'IT' | 'JA' | 'KO' | 'LT' | 'LV' | 'NB' | 'NL' | 'PL' | 'PT' | 'RO' | 'RU' | 'SK' | 'SL' | 'SV' | 'TR' | 'UK' | 'ZH'
type TSourceLanguage = 'AUTO' | TLanguage
type TTargetLanguage = TLanguage
interface IOptions {
from: TSourceLanguage
to: TTargetLanguage
text: string
}
interface IDeepLXData {
code: 200
id: number
method: 'Free'
from: TSourceLanguage
to: TTargetLanguage
source_lang: TSourceLanguage
target_lang: TTargetLanguage
data: string
alternatives: string[]
}
interface IDeepLBaseData {
jsonrpc: '2.0'
id: number
}
interface IDeepLData extends IDeepLBaseData {
result: {
texts: {
text: string
alternatives: { text: string }[]
}[]
lang: TSourceLanguage
lang_is_confident: boolean
detectedLanguages: Record<string, number>
}
}
interface IDeepLDataError extends IDeepLBaseData {
error: {
code: number
message: string
data: {
what: string
}
}
}
interface IDeepLDataError429 {
code: 429
jsonrpc: '2.0'
error: { code: number, message: string }
}
declare const DEEPL_URL = "https://www2.deepl.com/jsonrpc";
declare function translate(options: IOptions): Promise<Response>;
declare function parse2DeepLX(data: IOptions & IDeepLData): IDeepLXData;
declare function getBody({ from, to, text }: IOptions): string;
declare function handlerBodyMethod(random: number, body: string): string;
declare function getTimestamp(iCount: number): number;
declare function getICount(translate_text: string): number;
declare function getRandomNumber(): number;
export { DEEPL_URL, type IDeepLBaseData, type IDeepLData, type IDeepLDataError, type IDeepLDataError429, type IDeepLXData, type IOptions, type TLanguage, type TSourceLanguage, type TTargetLanguage, getBody, getICount, getRandomNumber, getTimestamp, handlerBodyMethod, parse2DeepLX, translate };