Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// if they declare the lang attr, we assume they know what they are talking about
if (declaredLang) {
callback(null, declaredLang);
}
else {
let lang;
const options = {
isHTML: true,
tldHint: obj.url && TldExtract(obj.url).tld
};
// otherwise, we load the page, and use Google's cld to try to detect it
Cld.detect(html, options, (err, result) => {
if (!err && result.reliable) {
lang = result.languages[0].code;
}
else if (err) {
console.warn(err);
}
// if we were unable to identify the language, or the results are not
// considered reliable, re return undefined
// don't return the actual error as we don't want to stop parsing as a result
callback(null, lang);
});
}
};
return new Promise(function(resolve) {
// Only run the detection if it’s enabled.
if(config.secondaryCheck === true) {
cld.detect(status.text, options, function(err, result) {
if(
!err &&
result.languages[0].code === language &&
result.languages[0].score >= config.langThreshold &&
result.reliable === true
) {
resolve(status);
} else {
resolve(null);
}
});
} else {
resolve(status);
}
});
}
async.eachSeries(input, function iterator(value, nextvalue) {
cld.detect(value, function(err, result) {
console.log("detection result");
console.log(result);
sandbox.context.data.push(result);
nextvalue();
});
}, function done() {
sandbox.run.runInContext(sandbox);
return await new Promise((resolve, reject) => {
cld.detect(content, {
isHTML: true,
tldHint: tldExtract(url).tld
}, (err, result) => {
resolve(rtlDetect.isRtlLang(result.languages[0].code))
})
})
})
return new Promise((resolve) => {
cld.detect(state.rawSentence, (error, value) => {
if (!error) {
state.language = value.languages[0].code;
}
state.sentence = state.rawSentence;
resolve(state);
});
});
}
return new Promise((res,rej) => {
cld.detect(text, (err, result) => {
if (err) { rej(new Error(err.message)); return; }
if (!result.reliable || result.languages[0].percent < 85) {
rej(new Error('Not enough reliable text'));
return;
}
res(result.languages[0].code);
});
});
}
async.eachSeries(abstracts, function(item, callback) {
cld.detect(item, {
"isHTML": false,
"encodingHint": "UTF8",
}, function(err, result) {
if (err) return callback(err);
if (!result) return callback();
if (result.reliable && result.languages.length) {
if (result.languages[0].percent >= worker.resources.parameters.cld.percent && result.languages[0].code === worker.resources.parameters.cld.code) abstract = item;
}
callback();
});
}, function(err) {
if (err) {