parts = {
const rows = d3.csvParse(moc, d3.autoType)
const [key] = Object.keys(rows[0]);
return rows.flatMap(({[key]: row, ...stores}) => {
const [, part, need] = (row || '').match(/(\w+ \([^)]+\)) Need: (\d+)/) || []
return Object.entries(stores).map(([store, inventory]) => {
const [, cost, stock] = inventory ? inventory.match(/ Cost: \$([^\s]+) Stock: (\d+)/) : []
store = store.replace(/ \(.*/, '').trim()
return {
part, need: +need, store, cost: +cost, stock: +stock
}
})
.filter(d => d.cost)
})
}