diff --git a/@types/index.d.ts b/@types/index.d.ts new file mode 100644 index 0000000..1b61558 --- /dev/null +++ b/@types/index.d.ts @@ -0,0 +1,28 @@ +declare module 'reverso-api' { + global { + export interface ReversoResponse { + ok: boolean, + text: string, + source: string, + target: string, + translation: string[], + examples: { + id: number, + source: string, + target: string, + }[] + } + + export interface ReversoErrorResponse { + ok: boolean, + message: string, + } + } + + type CallbackFunction = (error: ReversoErrorResponse, response: ReversoResponse) => void; + + export default class Reverso { + constructor({ insecureHTTPParser = false }?: { insecureHTTPParser: boolean }); + getContext(text: string, source: string, target: string, callback?: CallbackFunction): ReversoResponse; + } +} \ No newline at end of file diff --git a/@types/reverso-api-tests.ts b/@types/reverso-api-tests.ts new file mode 100644 index 0000000..76a5280 --- /dev/null +++ b/@types/reverso-api-tests.ts @@ -0,0 +1,12 @@ +import Reverso from 'reverso-api'; + +const reverso = new Reverso(); + +export async function getContext(text: string, source: string, target: string): Promise { + try { + const response = await reverso.getContext(text, source, target); + return response; + } catch (error) { + throw error; + } +} \ No newline at end of file diff --git a/@types/tsconfig.json b/@types/tsconfig.json new file mode 100644 index 0000000..6a16236 --- /dev/null +++ b/@types/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "./" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "reverso-api-tests.ts" + ] +} \ No newline at end of file diff --git a/@types/tslint.json b/@types/tslint.json new file mode 100644 index 0000000..794cb4b --- /dev/null +++ b/@types/tslint.json @@ -0,0 +1 @@ +{ "extends": "@definitelytyped/dtslint/dt.json" } diff --git a/package.json b/package.json index 80b5131..79655d2 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "2.22.3", "description": "Unofficial Reverso API", "main": "index.js", + "types": "@types/index.d.ts", "homepage": "https://github.com/s0ftik3/reverso-api#readme", "repository": "https://github.com/s0ftik3/reverso-api", "scripts": {