@truecalc/core 0.4.19 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/truecalc_wasm.d.ts +23 -0
- package/truecalc_wasm.js +1 -1
- package/truecalc_wasm_bg.js +68 -0
- package/truecalc_wasm_bg.wasm +0 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@truecalc/core",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Spreadsheet formula engine for the browser — Excel-compatible formula evaluator compiled to WebAssembly",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.5.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
package/truecalc_wasm.d.ts
CHANGED
|
@@ -15,6 +15,29 @@ export interface ValidateResult {
|
|
|
15
15
|
export type EvalResult = { type: "number"; value: number } | { type: "text"; value: string } | { type: "bool"; value: boolean } | { type: "error"; error: string } | { type: "empty" };
|
|
16
16
|
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* A stateful engine bound to a conformance target.
|
|
20
|
+
*
|
|
21
|
+
* Obtained via `createEngine('google-sheets')`.
|
|
22
|
+
*/
|
|
23
|
+
export class Engine {
|
|
24
|
+
private constructor();
|
|
25
|
+
free(): void;
|
|
26
|
+
[Symbol.dispose](): void;
|
|
27
|
+
/**
|
|
28
|
+
* Evaluate a formula using this engine's conformance target.
|
|
29
|
+
*/
|
|
30
|
+
evaluate(formula: string, variables: any): EvalResult;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create an engine for a specific conformance target.
|
|
35
|
+
*
|
|
36
|
+
* Supported targets: `"google-sheets"`.
|
|
37
|
+
* Returns an error for unknown targets.
|
|
38
|
+
*/
|
|
39
|
+
export function createEngine(target: string): Engine;
|
|
40
|
+
|
|
18
41
|
/**
|
|
19
42
|
* Evaluate a formula with named variables supplied as a JS object.
|
|
20
43
|
*
|
package/truecalc_wasm.js
CHANGED
package/truecalc_wasm_bg.js
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A stateful engine bound to a conformance target.
|
|
3
|
+
*
|
|
4
|
+
* Obtained via `createEngine('google-sheets')`.
|
|
5
|
+
*/
|
|
6
|
+
export class Engine {
|
|
7
|
+
static __wrap(ptr) {
|
|
8
|
+
ptr = ptr >>> 0;
|
|
9
|
+
const obj = Object.create(Engine.prototype);
|
|
10
|
+
obj.__wbg_ptr = ptr;
|
|
11
|
+
EngineFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
__destroy_into_raw() {
|
|
15
|
+
const ptr = this.__wbg_ptr;
|
|
16
|
+
this.__wbg_ptr = 0;
|
|
17
|
+
EngineFinalization.unregister(this);
|
|
18
|
+
return ptr;
|
|
19
|
+
}
|
|
20
|
+
free() {
|
|
21
|
+
const ptr = this.__destroy_into_raw();
|
|
22
|
+
wasm.__wbg_engine_free(ptr, 0);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Evaluate a formula using this engine's conformance target.
|
|
26
|
+
* @param {string} formula
|
|
27
|
+
* @param {any} variables
|
|
28
|
+
* @returns {EvalResult}
|
|
29
|
+
*/
|
|
30
|
+
evaluate(formula, variables) {
|
|
31
|
+
const ptr0 = passStringToWasm0(formula, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
32
|
+
const len0 = WASM_VECTOR_LEN;
|
|
33
|
+
const ret = wasm.wasmengine_evaluate(this.__wbg_ptr, ptr0, len0, addHeapObject(variables));
|
|
34
|
+
return takeObject(ret);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (Symbol.dispose) Engine.prototype[Symbol.dispose] = Engine.prototype.free;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create an engine for a specific conformance target.
|
|
41
|
+
*
|
|
42
|
+
* Supported targets: `"google-sheets"`.
|
|
43
|
+
* Returns an error for unknown targets.
|
|
44
|
+
* @param {string} target
|
|
45
|
+
* @returns {Engine}
|
|
46
|
+
*/
|
|
47
|
+
export function createEngine(target) {
|
|
48
|
+
try {
|
|
49
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
50
|
+
const ptr0 = passStringToWasm0(target, wasm.__wbindgen_export, wasm.__wbindgen_export2);
|
|
51
|
+
const len0 = WASM_VECTOR_LEN;
|
|
52
|
+
wasm.createEngine(retptr, ptr0, len0);
|
|
53
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
54
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
55
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
56
|
+
if (r2) {
|
|
57
|
+
throw takeObject(r1);
|
|
58
|
+
}
|
|
59
|
+
return Engine.__wrap(r0);
|
|
60
|
+
} finally {
|
|
61
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
1
65
|
/**
|
|
2
66
|
* Evaluate a formula with named variables supplied as a JS object.
|
|
3
67
|
*
|
|
@@ -238,6 +302,10 @@ export function __wbindgen_object_clone_ref(arg0) {
|
|
|
238
302
|
export function __wbindgen_object_drop_ref(arg0) {
|
|
239
303
|
takeObject(arg0);
|
|
240
304
|
}
|
|
305
|
+
const EngineFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
306
|
+
? { register: () => {}, unregister: () => {} }
|
|
307
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_engine_free(ptr >>> 0, 1));
|
|
308
|
+
|
|
241
309
|
function addHeapObject(obj) {
|
|
242
310
|
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
243
311
|
const idx = heap_next;
|
package/truecalc_wasm_bg.wasm
CHANGED
|
Binary file
|