Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export csv #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions exportcsv/export_csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import fs from 'fs'
import dat from './flattening.js'

const chaves = Object.keys(dat[0])
const cabecalio = chaves.join( ',')

const data = dat.map((elemento) => Object.values(elemento).join(',')).join('\n')

const conteudo = cabecalio + '\n' + data
console.log(conteudo)



try {
fs.writeFileSync('test.csv', conteudo);
// file written successfully
} catch (err) {
console.error(err);
}
19 changes: 19 additions & 0 deletions exportcsv/flattening.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import result from "../resultado/result.js"

let data = result()

let dt = (obj, arr = []) => {
return Object.keys(obj).reduce((result, index) => {
if (typeof obj[index] !== "object") {
result[arr.concat(index).join("_")] = obj[index];
return result;
}
return Object.assign(result, dt(obj[index], arr.concat(index), result));
}, {});
}


let dat = []
dat.push(dt(data[0]))
//console.log(dat)
export default dat
7 changes: 7 additions & 0 deletions exportjson/export.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import result from "../resultado/result.js"

function teste(){
const schema = JSON.stringify(result())
console.log(schema)
}
teste()
3 changes: 3 additions & 0 deletions exportpdf/exportpdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import result from "../resultado/result";


8 changes: 8 additions & 0 deletions resultado/result.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import verifica from "../valida/validando.js"

function result(){
return verifica()
}
result()

export default result
2 changes: 2 additions & 0 deletions test.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dataLayer,objectName,keyName,status,message,partialErrors_ocurrences,partialErrors_trace
dataLayer,objectName,keyName,status,message,0,
4 changes: 1 addition & 3 deletions valida/validando.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import validationResult from "../js/validation.js";

function verifica() {
console.log(validationResult)
return validationResult()
}
verifica()



export default verifica