google-translate-api
Advanced tools
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 @@ ] |
12
test.js
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
0
14278
4
8
254
1
+ Addedsafe-eval@^0.3.0
+ Addedgoogle-translate-token@1.0.0(transitive)
+ Addedsafe-eval@0.3.0(transitive)