deepl-node
Version:
deepl-node is the official DeepL Node.js client library
95 lines (94 loc) • 4.54 kB
TypeScript
/// <reference types="node" />
/// <reference types="node" />
/// <reference types="node" />
import { Formality, GlossaryInfo, GlossaryId, LanguageCode, NonRegionalLanguageCode, RequestParameters, TranslateTextOptions, MultilingualGlossaryInfo, MultilingualGlossaryDictionaryEntries } from './types';
export declare function logDebug(message: string, args?: object): void;
export declare function logInfo(message: string, args?: object): void;
/**
* Converts contents of given stream to a Buffer.
* @private
*/
export declare function streamToBuffer(stream: NodeJS.ReadableStream): Promise<Buffer>;
/**
* Converts contents of given stream to a string using UTF-8 encoding.
* @private
*/
export declare function streamToString(stream: NodeJS.ReadableStream): Promise<string>;
export declare const timeout: (ms: number) => Promise<unknown>;
/**
* Returns true if the given argument is a string.
* @param arg Argument to check.
*/
export declare function isString(arg: any): arg is string;
/**
* Returns '1' if the given arg is truthy, '0' otherwise.
* @param arg Argument to check.
*/
export declare function toBoolString(arg: any): string;
/**
* Returns true if the specified DeepL Authentication Key is associated with a free account,
* otherwise false.
* @param authKey The authentication key to check.
* @return True if the key is associated with a free account, otherwise false.
*/
export declare function isFreeAccountAuthKey(authKey: string): boolean;
/**
* Changes the upper- and lower-casing of the given language code to match ISO 639-1 with an
* optional regional code from ISO 3166-1.
* For example, input 'EN-US' returns 'en-US'.
* @param langCode String containing language code to standardize.
* @return Standardized language code.
*/
export declare function standardizeLanguageCode(langCode: string): LanguageCode;
/**
* Removes the regional variant from a language, for example inputs 'en' and 'en-US' both return
* 'en'.
* @param langCode String containing language code to convert.
* @return Language code with regional variant removed.
*/
export declare function nonRegionalLanguageCode(langCode: string): NonRegionalLanguageCode;
/**
* Validates and prepares URLSearchParams for arguments common to text and document translation.
* @private
*/
export declare function buildURLSearchParams(sourceLang: LanguageCode | null, targetLang: LanguageCode, formality: Formality | undefined, glossary: GlossaryId | GlossaryInfo | MultilingualGlossaryInfo | undefined, extraRequestParameters: RequestParameters | undefined): URLSearchParams;
/**
* Validates and appends texts to HTTP request parameters, and returns whether a single text
* argument was provided.
* @param data Parameters for HTTP request.
* @param texts User-supplied texts to be checked.
* @return True if only a single text was provided.
* @private
*/
export declare function appendTextsAndReturnIsSingular(data: URLSearchParams, texts: string | string[]): boolean;
/**
* Validates and appends text options to HTTP request parameters.
* @param data Parameters for HTTP request.
* @param options Options for translate text request.
* Note the formality and glossaryId options are handled separately, because these options
* overlap with the translateDocument function.
* @private
*/
export declare function validateAndAppendTextOptions(data: URLSearchParams, options?: TranslateTextOptions): void;
/**
* Appends glossary dictionaries to HTTP request parameters.
* @param data URL-encoded parameters for a HTTP request.
* @param dictionaries Glossary dictionaries to append.
* @private
*/
export declare function appendDictionaryEntries(data: URLSearchParams, dictionaries: MultilingualGlossaryDictionaryEntries[]): void;
/**
* Appends a glossary dictionary with CSV entries to HTTP request parameters.
* @param data URL-encoded parameters for a HTTP request.
* @param sourceLanguageCode Source language code of the dictionary.
* @param targetLanguageCode Target language code of the dictionary.
* @param csvContent CSV-formatted string containing the dictionary entries.
* @private
*/
export declare function appendCsvDictionaryEntries(data: URLSearchParams, sourceLanguageCode: string, targetLanguageCode: string, csvContent: string): void;
/**
* Extract the glossary ID from the argument.
* @param glossary The glossary as a string, GlossaryInfo, or MultilingualGlossaryInfo.
* @private
*/
export declare function extractGlossaryId(glossary: GlossaryId | GlossaryInfo | MultilingualGlossaryInfo): string;