Added table feature

This commit is contained in:
2026-05-04 21:39:59 +02:00
parent 7e0d220a81
commit eef2630af7
10 changed files with 342 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import { Stub } from '@efforting.tech/feature/stub';
/*
export function Stub(meta, name, description, module_name, function_name) {
return function stub() {
throw new Error(`The feature "${name}" of "${meta.url}" is not enabled. Enable it by calling "${function_name}(${this.name})" imported from "${module_name}"`); //TODO - specific error
}
}
*/
class Thing {
static from_stuff = Stub(import.meta, 'stuff-loader', 'Creates Thing from stuff', '@efforting.tech/stuff/loader', 'enable_stuff_loader');
}
Thing.from_stuff()
/*
Error: The feature "stuff-loader" of "file:///srv/Projekt/efforting.tech/nodejs.esm-library/experiments/generic-parser-2.mjs" is not enabled. Enable it by calling "enable_stuff_loader(Thing)" imported from "@efforting.tech/stuff/loader"
at Thing.stub [as from_stuff] (file:///srv/Projekt/efforting.tech/nodejs.esm-library/build/packages/feature/stub.mjs:4:9)
at file:///srv/Projekt/efforting.tech/nodejs.esm-library/experiments/generic-parser-2.mjs:10:7
at ModuleJob.run (node:internal/modules/esm/module_job:430:25)
at async node:internal/modules/esm/loader:639:26
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:101:5)
*/

View File

23
experiments/table-1.mjs Normal file
View File

@@ -0,0 +1,23 @@
import { Row_Based_Table } from '@efforting.tech/table'
const t = new Row_Based_Table({ column_names: 'SKU, Quantity, Price' });
//console.log(t.column_names_lut); /* { SKU: 0, Quantity: 1, Price: 2 } */
t.push_rows(
['VOLVO-1', 3, 120_000],
['VOLVO-2', 4, 140_000],
)
const [A] = t.read_rows(0);
const [B] = t.snapshot_rows(1);
console.log(A.value);
console.log(B.value);
A.update({Quantity: 5});
console.log(A.value);
for (const r of t) {
console.log(r.object);
}

34
experiments/table-2.mjs Normal file
View File

@@ -0,0 +1,34 @@
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 }
*/