Some checks failed
continuous-integration/drone/push Build is failing
- Complete GGZ Ecademy Nuxt.js user portal - Learning products browser and management - Member management interface - User authentication and roles - Multi-language support (NL/EN) - Vuex store for state management - Component-based architecture
53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
import isEqual from 'lodash.isequal';
|
|
|
|
// export const state = () => ({});
|
|
|
|
export const getters = {
|
|
// console.log(this.$store.getters['utils/areEquals'](1, 1)) // It works
|
|
areEquals: (state) => (input1, input2) => isEqual(input1, input2),
|
|
isNotEmptyObj: (state) => (obj) => Object.keys(obj).length > 0,
|
|
|
|
filterArrayObjsByArrayOfProperties: (state) => (arrayObjs, arrayProperties) => {
|
|
|
|
const filteredData = arrayObjs.map((row) => {
|
|
|
|
const obj = {}
|
|
|
|
arrayProperties.forEach(property => obj[property] = row[property]);
|
|
|
|
return obj;
|
|
})
|
|
|
|
return filteredData;
|
|
},
|
|
|
|
arrayOfObjectToCsv: (state) => (data) => {
|
|
const headers = Object.keys(data[0])
|
|
|
|
const csvRows = []
|
|
|
|
for (const row of data) {
|
|
const values = headers.map((header) => {
|
|
|
|
const tmpArray = []
|
|
|
|
if (row[header]) {
|
|
// Replacing commas with whitespaces
|
|
tmpArray.push(row[header].replace(/,/g, ""))
|
|
return tmpArray
|
|
}
|
|
return '-'
|
|
})
|
|
csvRows.push([values.join(',')])
|
|
}
|
|
|
|
const csvString = [
|
|
[...headers],
|
|
...csvRows,
|
|
]
|
|
.map(e => e.join(","))
|
|
.join("\n");
|
|
|
|
return csvString
|
|
},
|
|
} |