-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (26 loc) · 1.05 KB
/
Copy pathindex.js
File metadata and controls
29 lines (26 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const getCSVAsArray = require('./getCSVAsArray.js'),
changeCSVAsArray = require('./changeCSVAsArray.js'),
writeToFile = require('./writeToFile.js'),
arrayToMatrix = require('./arrayToMatrix.js')
arrayToCSVData = require('./arrayToCSVData.js')
function csvFileAsArray(path){
this.getValues = ()=>getCSVAsArray(path).then(arrayToMatrix)
this.changeValues = (changer,newPath)=>changeCSVAsArray(path,changer,newPath)
this.getValuesAsObj = (header)=>getCSVAsArray(path).then(arrayToMatrix).then(mat=>{
if(header != undefined && header.length != mat[0].length){
return console.error("Header array too short.")
}
header = header != undefined ? header : mat.shift()
return mat.map(
row=>{
var tempObj = {}
row.forEach((item,i)=>{tempObj[header[i]] = item})
return tempObj
}
)
})
}
function arrayToCSVFile(path,arr){
writeToFile(path)(arrayToCSVData(arrayToMatrix(arr))).then((vals)=>{console.log('success')},console.error)
}
module.exports = {csvFileAsArray:csvFileAsArray,arrayToCSVFile:arrayToCSVFile}