translator-promise
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -10,3 +10,3 @@ const http = require('https') | ||
let tkkMat = body.match(/tkk:'([\d.]+)'/); | ||
tkk = tkkMat[1]; | ||
tkk = tkkMat ? tkkMat[1] : tkk; | ||
} | ||
@@ -33,11 +33,3 @@ | ||
function tk(a, tkk) { | ||
if (null !== Jo) | ||
var b = Jo; | ||
else { | ||
b = Ho(String.fromCharCode(84)); | ||
var c = Ho(String.fromCharCode(75)); | ||
b = [b(), b()]; | ||
b[1] = c(); | ||
b = (Jo = tkk || "") || ""; | ||
} | ||
var b = tkk || '' | ||
var d = Ho(String.fromCharCode(116)); | ||
@@ -69,2 +61,16 @@ c = Ho(String.fromCharCode(107)); | ||
function getCandidate(tran) { | ||
let words = [] | ||
if (tran[1]) words = words.concat(tran[1][0][1]) | ||
if (tran[5]) { | ||
let candidates = tran[5].map(tt => (tt[2] || [tt[0]]).map(t => t[0])); | ||
let maxLength = Math.max(...candidates.map(c => c.length)); | ||
for (let i = 0; i < maxLength; i++) { | ||
let candidate = candidates.map(c => c[i] || c[c.length - 1]).join('').trim(); | ||
if(words.indexOf(candidate) < 0) words.push(candidate); | ||
} | ||
} | ||
return words; | ||
} | ||
function get(url) { | ||
@@ -98,9 +104,2 @@ return new Promise(function (resolve, reject){ | ||
function getCandidate(tran) { | ||
let words = []; | ||
if(tran[1]) words = words.concat(tran[1][0][1]); | ||
if(tran[5]) words = words.concat(tran[5][0][2].map(t => t[0]).filter(t => !words.find(w => w == t))) | ||
return words; | ||
} | ||
async function translate(word, lang) { | ||
@@ -107,0 +106,0 @@ let url = `https://translate.google.cn/translate_a/single?client=webapp&sl=${lang.from}&tl=${lang.to}&hl=zh-CN&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&pc=1&otf=1&ssel=0&tsel=0&kc=1&tk=${tk(word, tkk)}&q=${encodeURIComponent(word)}` |
{ | ||
"name": "translator-promise", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A node module based on Google Translate.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
27
test.js
@@ -8,13 +8,3 @@ var test = require('tape') | ||
text: "語", | ||
candidate: [ | ||
"ワード", | ||
"単語", | ||
"語", | ||
"言葉", | ||
"語句", | ||
"伝言", | ||
"一言半句", | ||
"口舌", | ||
"一言" | ||
] | ||
candidate: ["ワード","単語","語","言葉","語句","伝言","一言半句","口舌"] | ||
}); | ||
@@ -27,5 +17,5 @@ assert.end() | ||
word: "中文", | ||
text: "중국어", | ||
text: "중국말", | ||
candidate: [ | ||
"중국어" | ||
"중국말","중국어" | ||
] | ||
@@ -50,10 +40,9 @@ }); | ||
word: '用 Google 翻译一下这条句子。', | ||
text: 'Translate this sentence with Google.', | ||
candidate: | ||
[ | ||
'Translate this sentence with Google.', | ||
'By Google translate this sentence.' | ||
] | ||
text: "Use Google to translate this sentence.", | ||
candidate:[ | ||
"Use Google to translate this sentence.", | ||
"By Google translate this sentence." | ||
] | ||
}); | ||
assert.end() | ||
}) |
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
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
8675
155