- 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
This commit is contained in:
53
store/utils.js
Normal file
53
store/utils.js
Normal file
@@ -0,0 +1,53 @@
|
||||
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
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user