summarum/src-tauri/extension-sample.js
Horizontal42 b0f6e9e89b run extensions in a quickjs wasm sandbox
replaces new Function() in the main window; per-script and per-call
interrupt deadlines, memory and stack limits, graceful skip if the
wasm module fails to load. csp script-src drops 'unsafe-eval' for
'wasm-unsafe-eval'.
2026-07-29 14:38:28 +03:00

23 lines
858 B
JavaScript

// Summarum extension example.
// Drop .js files into this folder and restart the app.
// API: numi.setVariable, numi.addUnit, numi.addFunction.
//
// Scripts run in a WebAssembly sandbox: no files, no network, no app internals,
// and no console/setTimeout/fetch — only plain JS and the numi API above.
// A global variable usable on any sheet, e.g. `salary * vat`
// numi.setVariable("vat", { "double": 20 });
// A custom unit: 1 floor = 3 meters, so `5 floors in meters` works
// numi.addUnit({
// "id": "floor",
// "phrases": "floor, floors, этаж, этажа, этажей",
// "baseUnitId": "meter",
// "format": "fl",
// "ratio": 3,
// });
// A custom function: hyp(3; 4) -> 5
// numi.addFunction({ "id": "hyp", "phrases": "hyp" }, function (values) {
// return { "double": Math.hypot(values[0].double, values[1].double) };
// });