node-oneapi v1.0.1
OneAPI for Node []
OneAPI Sets a goal for a uniform and modern API wrapper for all public APIs while setting the following standards:
Extensive JSDocs: All needed information for using the API should be easily understood from the JSDocs including API setup, method arguments and return values
Typed: All APIs Come with .d.ts files with typings for the setup, method arguments, arguments defaults and return values
Promise based: All APIs are written promise based, ready for async-await usage
Lazy packaging: Import only what you need, OneAPI is divided so every API is an independent package.
Well tested: With OneAPI we should all stop searching for an API wrapper that is up to date and working properly
Supported APIs
- Google Cloud Tranlsation API
- Giphy API - Animated GIF search engine
Installation
npm install --save @node-oneapi/google-translate
or
yarn add @node-oneapi/google-translate
Example Usage
import googleTranslate from '@node-oneapi/google-translate';
const translateAPI = googleTranslate(apiOptions); // apiKey, etc.
console.log(await translateAPI.translate('hello', 'en', 'es')) // => 'Hola'
Sample documentation and typings
/**
* Translating strings between natural languages using Google translate API
* @param {string | string[]} strings
* A string or strings to translate
* i.e - "hello world" OR ["hello", "world"]
* @param {string} [sourceLang=null]
* Optional, The language to translate from (default is null)
* If default value of null is used, google translate will auto detect language
* supported languages listed here: https://cloud.google.com/translate/docs/languages
* or can be fetched using 'getSupportedLanguages' of this API
* @param {string} [targetLang='en']
* Optional, The language to translate to (default is 'en' - english)
* supported languages listed here: https://cloud.google.com/translate/docs/languages
* or can be fetched using 'getSupportedLanguages' of this API
* @returns {Promise<TranslationResult | TranslationResult[]>}
* Return a promise of an object or array of objects, each object contains:
* translatedText: The result of translation
* detectedSourceLanguage: The detected (or specified) source language
* originalText: The original text pre-translation
*/
function translate(
strings: string | string[],
sourceLang: string = null,
targetLang: string = 'en'
): Promise<TranslationResult | TranslationResult[]>;
Contribution
OneAPI is intended to become a strong community project. Join us in planning, maintaing and extending this library.