Feat: Tag rows before storing them in vuex
This commit is contained in:
27
src/libs/data_processing.js
Normal file
27
src/libs/data_processing.js
Normal file
@@ -0,0 +1,27 @@
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user