34 lines
717 B
JavaScript
34 lines
717 B
JavaScript
import { Row_Based_Table } from '@efforting.tech/table';
|
|
import { load_raster_table } from '@efforting.tech/table/raster-table';
|
|
|
|
|
|
const t = load_raster_table(`
|
|
|
|
SKU Quantity Price
|
|
--- -------- -----
|
|
V-1 2 120_000
|
|
V-2 3 140_000
|
|
|
|
`, Row_Based_Table);
|
|
|
|
|
|
// { row_name, column_name, row_index, column_index, row, cell }
|
|
t.replace_all_cells(
|
|
({column_name, cell}) => {
|
|
const translation = {
|
|
SKU: (s) => s.trim(),
|
|
Quantity: parseInt,
|
|
Price: (p) => parseFloat(p.replace(/_/g, '')),
|
|
}[column_name];
|
|
return translation ? translation(cell) : cell;
|
|
}
|
|
);
|
|
|
|
for (const r of t) {
|
|
console.log(r.object);
|
|
}
|
|
|
|
/*
|
|
{ SKU: 'V-1', Quantity: 2, Price: 120000 }
|
|
{ SKU: 'V-2', Quantity: 3, Price: 140000 }
|
|
*/ |