comptes/src/libs/data_processing.js

28 lines
723 B
JavaScript

export function appendTag (row, keywords, field='Libellé') {
// Append row.tag
// if row.libellé contains one of words and not invert it gets tagged
// if row.libellé contains no words and invert it gets tagged
// according to keywords [{name: string, words: [], invert: bool}]
// row['tags'] =
row.tags = keywords.filter(k => {
return strContains(row[field], k.words, k.invert)
})
}
function strContains (string, words, invert) {
// Does a string contain one of words or the opposite
if (!words) {
return true
}
if (invert) {
return words.every(v => {
return string.indexOf(v) < 0
})
} else {
return words.some(v => {
return string.indexOf(v) >= 0
})
}
}