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 }) } } export function total (row, field='Montant') { var sum = row.map(x => parseFloat(x[field])) .reduce((sum, x) => sum + x, 0) return Math.round(sum) }