Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default (input, allowed) => {
const detected = franc
.all(input)
.filter(lang => lang[1] >= 0.45)
.map(lang => lang[0])
.slice(0, 5);
// Library franc spits out ['und'] when unable to
// guess any languages, let it through in this case
const matches = detected[0] === 'und' || detected.indexOf(allowed) > -1;
return {
matches,
detected
};
};
entry = traverseEntriesById(entryId, Entries);
// let Entries = await localforage.getItem("entries");
let editorType = entry['editorType'];
// let library = getState("library");
let library = defaultFLib;
const Library = openDB(library);
const m_this = this;
entry['timestampLastModified'] = timestampNow;
// if (entry !== null && entry !== undefined) {
// entry['html'] = getHTMLFromContent(this.state.editorState);
entry['html'] = this.state.editorHtml;
const strippedText = HTMLToText(entry['html']);
entry['strippedText'] = strippedText;
const combinedText = entry['title'] + ' ' + strippedText;
const detectedLanguages = franc.all(combinedText).slice(0, 5);
entry['detectedLanguages'] = detectedLanguages;
entry['entities'] = {
terms: parseTextForTerms(strippedText),
topics: parseTextForTopics(strippedText),
people: parseTextForPeople(strippedText),
dates: parseTextForDates(strippedText),
organizations: parseTextForOrganizations(strippedText),
places: parseTextForPlaces(strippedText),
phoneNumbers: parseTextForPhoneNumbers(strippedText),
urls: parseTextForURLs(strippedText),
hashtags: parseTextForHashtags(strippedText),
quotes: parseTextForQuotes(strippedText),
statements: parseTextForStatements(strippedText),
questions: parseTextForQuestions(strippedText),
bigrams: parseTextForBigrams(strippedText),
trigrams: parseTextForTrigrams(strippedText)
} catch (err) {
editorType = "flow";
setState("editorType", "flow");
}
const showAnalysisOverlay = nextProps.showAnalysisOverlay;
// if (entry['html'] !== null && entry['html'] !== undefined && entry['html'] !== ""
// && entry['html'] !== "undefined" && entry['html'] !== 'undefined' && entry['html'] !== '<p></p>'
// ) {
if (showAnalysisOverlay) {
const strippedText = HTMLToText(entry['html']);
entry['strippedText'] = strippedText;
const combinedText = entry['title'] + ' ' + strippedText;
const detectedLanguages = franc.all(combinedText).slice(0, 5);
entry['detectedLanguages'] = detectedLanguages;
entry['entities'] = {
terms: parseTextForTerms(strippedText),
topics: parseTextForTopics(strippedText),
people: parseTextForPeople(strippedText),
dates: parseTextForDates(strippedText),
organizations: parseTextForOrganizations(strippedText),
places: parseTextForPlaces(strippedText),
phoneNumbers: parseTextForPhoneNumbers(strippedText),
urls: parseTextForURLs(strippedText),
hashtags: parseTextForHashtags(strippedText),
quotes: parseTextForQuotes(strippedText),
statements: parseTextForStatements(strippedText),
questions: parseTextForQuestions(strippedText),
bigrams: parseTextForBigrams(strippedText),
trigrams: parseTextForTrigrams(strippedText)
export function detectIso6393(text) {
// franc returns ISO 639-3 codes, including 'und' for undetermined
return franc(text);
}
function detect(value) {
var options = {
minLength: flags.minLength,
only: flags.only,
ignore: flags.ignore
}
if (flags.all) {
franc.all(value, options).forEach(function(language) {
console.log(language[0] + ' ' + language[1])
})
} else {
console.log(franc(value, options))
}
}
function query(text, cb) {
if (!cb) return new Error('Please provide a callback to process the returned response');
if (!text) return cb(new Error('Please provide a text'));
//confirm language: requires conversion between iso-639-3 (lang3) and iso-639-1
var lang3 = langs.where("1", lang)['3'];
var detectedLang = franc.all(text,{'whitelist' : ['eng',lang3], 'minLength': 3})[0][0];
console.log(`${detectedLang} detected`);
if (detectedLang != lang3 ){
if ( detectedLang != 'eng'){
return cb(new Error('Sorry we don\'t support that language at the moment.'));
}
}
translate(text, (err, translatedText) => {
if (err) return cb(err);
sendToLuis(translatedText, (err, luisResponse) => {
if (err) return cb(err);
luisResponse.translatedText = translatedText;
return cb(null, luisResponse);
});
});
}
const writeItem = (item) => {
const Key = `${item.id}.json`;
const lang = franc.all(item.title, { whitelist: ['eng', 'fin'] })[0];
if (lang[0] === 'fin') {
return 0;
}
Object.assign(item, { lang: lang[0] });
const params = {
Bucket: process.env.BLOG_BUCKET,
Key,
};
return s3.getObject(params).promise()
.then(() => item)
.catch(() =>
s3.putObject(
Object.assign(params, {
function any(node) {
patch(node, franc.all(nlcstToString(node)));
}
exports.detect = function (dateString) {
return franc.all(dateString, {
'whitelist': languageManager.getSupportedLangCodes(),
'minLength': 3
});
}
export function detectLang(input, langs) {
let res = franc(input, { whitelist: langs.map(l => langs.where('1', l)[3]) })
if (res === 'und') {
return langs[0]
}
return langs.where('3', res)[1]
}