Skip to content

Instantly share code, notes, and snippets.

@Michaela-Davis
Created June 11, 2019 23:41
Show Gist options
  • Save Michaela-Davis/3fff2a7ce19b8753636e7a3c763eefde to your computer and use it in GitHub Desktop.
Save Michaela-Davis/3fff2a7ce19b8753636e7a3c763eefde to your computer and use it in GitHub Desktop.
CSV to HTML
#!/usr/bin/env node
const csv = require("csvtojson");
const fs = require('fs');
csv()
.fromFile(`${__dirname}/dependencies.csv`)
.then((json)=>{
// console.log(json);
const html = json.map(row => {
let repository = row.repository;
if (row.repository.includes("ssh://")){
repository = row.repository.replace("ssh://git@","https://www.");
}
console.log(row);
return `
<tr>
<td>${row.name} v${row.version}</td>
<td>${row.summary}</td>
<td>${repository.includes("http") ?
`<a href="${repository}">${repository}</a>` :
`none`
}</td>
</tr>
`
}).join('');
const htmlWrapped = `
<table id="dependencies">
<tbody>
<thead>
<tr>
<th>Name v#</th>
<th>License</th>
<th>Respository</th>
</tr>
</thead>
${html}
</tbody>
</table>`
fs.writeFileSync('./index.html', htmlWrapped);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment