diff --git a/bom2table.js b/bom2table.js new file mode 100644 index 0000000..b55ac2a --- /dev/null +++ b/bom2table.js @@ -0,0 +1,57 @@ +const csvPicker = document.getElementById('csvFile') +csvPicker.addEventListener("change", handleFiles, false); + +function handleFiles() { + const csvFilePath = this.files[0] + let reader = new FileReader() + reader.readAsText(csvFilePath) + reader.onload = () => makeTable(reader.result) +} + +// Which components should we remove from the BOM? +const rejectedParts = [ + 'TP1', + 'TP2', + 'TP3', + 'G', + 'U$1', + 'J1', + 'J2', + 'INPUT' +] + +function generateTableHead(table, data) { + let thead = table.createTHead(); + let row = thead.insertRow(); + // Populate Header row + for (let key of data) { + let th = document.createElement("th"); + let text = document. createTextNode(key); + th.appendChild(text); + row.appendChild(th); + } +} + +// Return false if the Part value of the object passed in is in the list to remove +function isJunk (element) { + return !rejectedParts.includes(element.Part) +} + +function makeTable(csvString) { + csv({ + delimiter: ";", + includeColumns: /(Part|Value)/, + ignoreEmpty: true + }) + .fromString(csvString) + .then(jsonObj => { + // Create array containing only relevant parts + let parts = jsonObj.filter(isJunk) + console.log(parts) + }) +} + + +// let table = document.querySelector("table") +// let headerData = Object.keys(parts[0]) +// generateTableHead(table, headerData) \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..6fe4cd6 --- /dev/null +++ b/index.html @@ -0,0 +1,17 @@ + + + + + + BOM2Table + + + +

BOM to table

+ + + + + + + \ No newline at end of file