Socket
Socket
Sign inDemoInstall

google-translate-api

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

google-translate-api - npm Package Compare versions

Comparing version 2.0.3 to 2.1.0

21

index.js

@@ -1,12 +0,9 @@

/**
* Created by Matheus Fernandes on 5/11/16.
*/
var querystring = require('querystring');
var got = require('got');
var tk = require('./tk');
var token = require('google-translate-token');
var safeEval = require('safe-eval');
function translate(text, opts) {
opts = opts || {};
return tk(text).then(function (tk) {
return token.get(text).then(function (token) {
var url = 'https://translate.google.com/translate_a/single';

@@ -25,5 +22,5 @@ var data = {

kc: 7,
tk: opts.tk || tk,
q: text
};
data[token.name] = token.value;

@@ -53,3 +50,4 @@ return url + '?' + querystring.stringify(data);

var body = eval(res.body);
var body = safeEval(res.body);
console.log(require('util').inspect(body, { showHidden: false, depth: null }));
body[0].forEach(function (obj) {

@@ -86,11 +84,9 @@ if (obj[0] !== undefined) {

var e;
e = new Error();
if (err.statusCode !== undefined && err.statusCode !== 200) {
e = new Error();
e.code = 'BAD_REQUEST';
throw e;
} else {
e = new Error();
e.code = 'BAD_NETWORK';
throw e;
}
throw e;
});

@@ -101,1 +97,2 @@ });

module.exports = translate;
translate('hi', {to: 'nl'});
/**
* Created by matheus on 5/15/16.
*

@@ -4,0 +3,0 @@ * Generated from https://translate.google.com

{
"name": "google-translate-api",
"version": "2.0.3",
"version": "2.1.0",
"description": "A free and unlimited API for Google Translate",

@@ -35,3 +35,5 @@ "main": "index.js",

"configstore": "^2.0.0",
"got": "^6.3.0"
"google-translate-token": "latest",
"got": "^6.3.0",
"safe-eval": "^0.3.0"
},

@@ -47,7 +49,3 @@ "devDependencies": {

"space": 4,
"rules": {
"no-eval": 1
},
"ignores": [
"tk.js",
"languages.js"

@@ -54,0 +52,0 @@ ]

@@ -1,5 +0,1 @@

/**
* Created by matheus on 5/14/16.
*/
import test from 'ava';

@@ -63,10 +59,2 @@ import translate from './index';

test('translate some text with an invalid tk', async t => {
try {
await translate('vertaler', {tk: 0});
} catch (err) {
t.is(err.code, 'BAD_REQUEST');
}
});
test.todo('try to translate some text without an internet connection');

@@ -73,0 +61,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc