calcwright 0.0.0-stage → 0.1.1

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/README.md CHANGED
@@ -1,3 +1,36 @@
1
- # Temporary Holding Version
1
+ # Calcwright
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Calculate Excel workbooks without Excel.** Load an .xlsx, set the inputs, read the outputs, and get the numbers
4
+ Excel would give: on a server, with no Office licence and no LibreOffice.
5
+
6
+ ```js
7
+ const { Workbook, installLicence } = require("calcwright");
8
+ const fs = require("node:fs");
9
+
10
+ const wb = Workbook.fromBytes(fs.readFileSync("pricing-model.xlsx"));
11
+ wb.set("Inputs!B2", 120000); // "=..." sets a formula
12
+ console.log(wb.get("Quote!C10")); // recalculated on read; errors are {error:"#N/A"}
13
+ fs.writeFileSync("quote-1042.xlsx", wb.toBytes());
14
+ ```
15
+
16
+ Runs anywhere Node 18+ runs (WebAssembly, no native build).
17
+
18
+ ## Judged by Excel
19
+
20
+ Every workbook Excel saves stores the value it computed for each formula. Across the 15,871-workbook Enron corpus,
21
+ Calcwright reproduces Excel's value for **99.924% of 15,403,944 formula cells**. On the same 1,000 workbooks,
22
+ LibreOffice in headless mode reproduces 97.35%. Method and per-function results:
23
+ https://github.com/Huckcity/calcwright/blob/main/BENCHMARK.md
24
+
25
+ 473 functions, including XLOOKUP, FILTER, SORT, UNIQUE, LET and LAMBDA, plus array and dynamic-array formulas,
26
+ structured table references, names, 3D references, data tables and Excel's number formats.
27
+
28
+ ## Licence
29
+
30
+ Free for workbooks of up to 2,000 formula cells. A Developer licence ($249) or Team licence ($990), each a one-time
31
+ payment with 12 months of updates, removes the limit and covers commercial use: https://calcwright.dev/#pricing.
32
+ Install a key with `installLicence(key)`. Keys are
33
+ checked offline.
34
+
35
+ Made by ALGD LTD (NI744090). Microsoft Excel is a trademark of Microsoft Corporation; Calcwright is not affiliated
36
+ with Microsoft.
package/package.json CHANGED
@@ -1,6 +1,26 @@
1
1
  {
2
2
  "name": "calcwright",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Calculate Excel workbooks without Excel: an Excel-compatible formula engine (WebAssembly) judged against Excel itself",
5
+ "main": "pkg/calcwright_wasm.js",
6
+ "types": "pkg/calcwright_wasm.d.ts",
7
+ "files": [
8
+ "pkg/",
9
+ "README.md"
10
+ ],
11
+ "keywords": [
12
+ "excel",
13
+ "xlsx",
14
+ "formula",
15
+ "spreadsheet",
16
+ "calculation",
17
+ "recalculate",
18
+ "xlookup",
19
+ "sheetjs"
20
+ ],
21
+ "homepage": "https://calcwright.dev",
22
+ "license": "SEE LICENSE IN README.md",
23
+ "engines": {
24
+ "node": ">=18"
25
+ }
26
+ }
@@ -0,0 +1,42 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class Workbook {
5
+ private constructor();
6
+ free(): void;
7
+ [Symbol.dispose](): void;
8
+ /**
9
+ * Recalculate every formula (licence limit applies).
10
+ */
11
+ calculate(): number;
12
+ /**
13
+ * Load a workbook from the bytes of an .xlsx file.
14
+ */
15
+ static fromBytes(data: Uint8Array | number[]): Workbook;
16
+ get(address: string): any;
17
+ /**
18
+ * Set a value; strings starting with "=" set a formula.
19
+ */
20
+ set(address: string, value: any): void;
21
+ sheetNames(): Array<any>;
22
+ /**
23
+ * Save as .xlsx bytes with recalculated values.
24
+ */
25
+ toBytes(): Uint8Array;
26
+ readonly formulaCount: number;
27
+ }
28
+
29
+ export function freeFormulaLimit(): number;
30
+
31
+ export function functions(): Array<any>;
32
+
33
+ /**
34
+ * Install a licence key. Returns { id, kind, licensedTo } or throws with a reason.
35
+ */
36
+ export function installLicence(key: string): any;
37
+
38
+ /**
39
+ * The browser checker: recompute every formula of a workbook and compare with the values Excel
40
+ * saved. Works on any size (read-only report). Returns a plain object.
41
+ */
42
+ export function verifyWorkbook(data: Uint8Array | number[], limit: number): any;
@@ -0,0 +1,369 @@
1
+ /* @ts-self-types="./calcwright_wasm.d.ts" */
2
+
3
+ class Workbook {
4
+ static __wrap(ptr) {
5
+ const obj = Object.create(Workbook.prototype);
6
+ obj.__wbg_ptr = ptr;
7
+ WorkbookFinalization.register(obj, obj.__wbg_ptr, obj);
8
+ return obj;
9
+ }
10
+ __destroy_into_raw() {
11
+ const ptr = this.__wbg_ptr;
12
+ this.__wbg_ptr = 0;
13
+ WorkbookFinalization.unregister(this);
14
+ return ptr;
15
+ }
16
+ free() {
17
+ const ptr = this.__destroy_into_raw();
18
+ wasm.__wbg_workbook_free(ptr, 0);
19
+ }
20
+ /**
21
+ * Recalculate every formula (licence limit applies).
22
+ * @returns {number}
23
+ */
24
+ calculate() {
25
+ const ret = wasm.workbook_calculate(this.__wbg_ptr);
26
+ if (ret[2]) {
27
+ throw takeFromExternrefTable0(ret[1]);
28
+ }
29
+ return ret[0] >>> 0;
30
+ }
31
+ /**
32
+ * @returns {number}
33
+ */
34
+ get formulaCount() {
35
+ const ret = wasm.workbook_formulaCount(this.__wbg_ptr);
36
+ return ret >>> 0;
37
+ }
38
+ /**
39
+ * Load a workbook from the bytes of an .xlsx file.
40
+ * @param {Uint8Array | number[]} data
41
+ * @returns {Workbook}
42
+ */
43
+ static fromBytes(data) {
44
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
45
+ const len0 = WASM_VECTOR_LEN;
46
+ const ret = wasm.workbook_fromBytes(ptr0, len0);
47
+ if (ret[2]) {
48
+ throw takeFromExternrefTable0(ret[1]);
49
+ }
50
+ return Workbook.__wrap(ret[0]);
51
+ }
52
+ /**
53
+ * @param {string} address
54
+ * @returns {any}
55
+ */
56
+ get(address) {
57
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
58
+ const len0 = WASM_VECTOR_LEN;
59
+ const ret = wasm.workbook_get(this.__wbg_ptr, ptr0, len0);
60
+ if (ret[2]) {
61
+ throw takeFromExternrefTable0(ret[1]);
62
+ }
63
+ return takeFromExternrefTable0(ret[0]);
64
+ }
65
+ /**
66
+ * Set a value; strings starting with "=" set a formula.
67
+ * @param {string} address
68
+ * @param {any} value
69
+ */
70
+ set(address, value) {
71
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
72
+ const len0 = WASM_VECTOR_LEN;
73
+ const ret = wasm.workbook_set(this.__wbg_ptr, ptr0, len0, value);
74
+ if (ret[1]) {
75
+ throw takeFromExternrefTable0(ret[0]);
76
+ }
77
+ }
78
+ /**
79
+ * @returns {Array<any>}
80
+ */
81
+ sheetNames() {
82
+ const ret = wasm.workbook_sheetNames(this.__wbg_ptr);
83
+ return ret;
84
+ }
85
+ /**
86
+ * Save as .xlsx bytes with recalculated values.
87
+ * @returns {Uint8Array}
88
+ */
89
+ toBytes() {
90
+ const ret = wasm.workbook_toBytes(this.__wbg_ptr);
91
+ if (ret[3]) {
92
+ throw takeFromExternrefTable0(ret[2]);
93
+ }
94
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
95
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
96
+ return v1;
97
+ }
98
+ }
99
+ if (Symbol.dispose) Workbook.prototype[Symbol.dispose] = Workbook.prototype.free;
100
+ exports.Workbook = Workbook;
101
+
102
+ /**
103
+ * @returns {number}
104
+ */
105
+ function freeFormulaLimit() {
106
+ const ret = wasm.freeFormulaLimit();
107
+ return ret >>> 0;
108
+ }
109
+ exports.freeFormulaLimit = freeFormulaLimit;
110
+
111
+ /**
112
+ * @returns {Array<any>}
113
+ */
114
+ function functions() {
115
+ const ret = wasm.functions();
116
+ return ret;
117
+ }
118
+ exports.functions = functions;
119
+
120
+ /**
121
+ * Install a licence key. Returns { id, kind, licensedTo } or throws with a reason.
122
+ * @param {string} key
123
+ * @returns {any}
124
+ */
125
+ function installLicence(key) {
126
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
127
+ const len0 = WASM_VECTOR_LEN;
128
+ const ret = wasm.installLicence(ptr0, len0);
129
+ if (ret[2]) {
130
+ throw takeFromExternrefTable0(ret[1]);
131
+ }
132
+ return takeFromExternrefTable0(ret[0]);
133
+ }
134
+ exports.installLicence = installLicence;
135
+
136
+ /**
137
+ * The browser checker: recompute every formula of a workbook and compare with the values Excel
138
+ * saved. Works on any size (read-only report). Returns a plain object.
139
+ * @param {Uint8Array | number[]} data
140
+ * @param {number} limit
141
+ * @returns {any}
142
+ */
143
+ function verifyWorkbook(data, limit) {
144
+ const val2 = +limit;
145
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
146
+ const len0 = WASM_VECTOR_LEN;
147
+ const ret = wasm.verifyWorkbook(ptr0, len0, val2);
148
+ if (ret[2]) {
149
+ throw takeFromExternrefTable0(ret[1]);
150
+ }
151
+ return takeFromExternrefTable0(ret[0]);
152
+ }
153
+ exports.verifyWorkbook = verifyWorkbook;
154
+ function __wbg_get_imports() {
155
+ const import0 = {
156
+ __proto__: null,
157
+ __wbg___wbindgen_boolean_get_4f1baf9a00be3c74: function(arg0) {
158
+ const v = arg0;
159
+ const ret = typeof(v) === 'boolean' ? v : undefined;
160
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
161
+ },
162
+ __wbg___wbindgen_is_null_c22311b1cc228e3a: function(arg0) {
163
+ const ret = arg0 === null;
164
+ return ret;
165
+ },
166
+ __wbg___wbindgen_is_undefined_be5b34249ff1fc15: function(arg0) {
167
+ const ret = arg0 === undefined;
168
+ return ret;
169
+ },
170
+ __wbg___wbindgen_number_get_934b640d0889af78: function(arg0, arg1) {
171
+ const obj = arg1;
172
+ const ret = typeof(obj) === 'number' ? obj : undefined;
173
+ getDataViewMemory0().setFloat64((arg0 >>> 0) + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
174
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, !isLikeNone(ret), true);
175
+ },
176
+ __wbg___wbindgen_string_get_7ce8eee7fd327545: function(arg0, arg1) {
177
+ const obj = arg1;
178
+ const ret = typeof(obj) === 'string' ? obj : undefined;
179
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
180
+ var len1 = WASM_VECTOR_LEN;
181
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
182
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
183
+ },
184
+ __wbg___wbindgen_throw_4c88d8bf264fd984: function(arg0, arg1) {
185
+ throw new Error(getStringFromWasm0(arg0, arg1));
186
+ },
187
+ __wbg_get_2080c49015e35254: function() { return handleError(function (arg0, arg1) {
188
+ const ret = Reflect.get(arg0, arg1);
189
+ return ret;
190
+ }, arguments); },
191
+ __wbg_length_b03a0fabb109b1e9: function(arg0) {
192
+ const ret = arg0.length;
193
+ return ret;
194
+ },
195
+ __wbg_new_37eb45aaf5eeb820: function() {
196
+ const ret = new Array();
197
+ return ret;
198
+ },
199
+ __wbg_new_787b9fb330d55d78: function(arg0, arg1) {
200
+ const ret = new Error(getStringFromWasm0(arg0, arg1));
201
+ return ret;
202
+ },
203
+ __wbg_new_cd4348290afae586: function() {
204
+ const ret = new Object();
205
+ return ret;
206
+ },
207
+ __wbg_now_463ac581d2fc7ea3: function() {
208
+ const ret = Date.now();
209
+ return ret;
210
+ },
211
+ __wbg_push_c9f4893fc209f768: function(arg0, arg1) {
212
+ const ret = arg0.push(arg1);
213
+ return ret;
214
+ },
215
+ __wbg_set_2793479888329cb6: function() { return handleError(function (arg0, arg1, arg2) {
216
+ const ret = Reflect.set(arg0, arg1, arg2);
217
+ return ret;
218
+ }, arguments); },
219
+ __wbindgen_generic_0000000000000001: function(arg0) {
220
+ // Cast intrinsic for `F64 -> Externref`.
221
+ const ret = arg0;
222
+ return ret;
223
+ },
224
+ __wbindgen_generic_0000000000000002: function(arg0, arg1) {
225
+ // Cast intrinsic for `Ref(String) -> Externref`.
226
+ const ret = getStringFromWasm0(arg0, arg1);
227
+ return ret;
228
+ },
229
+ __wbindgen_init_externref_table: function() {
230
+ const table = wasm.__wbindgen_externrefs;
231
+ table.set(0, undefined);
232
+ table.set(1024, undefined);
233
+ table.set(1025, null);
234
+ table.set(1026, true);
235
+ table.set(1027, false);
236
+ },
237
+ };
238
+ return {
239
+ __proto__: null,
240
+ "./calcwright_wasm_bg.js": import0,
241
+ };
242
+ }
243
+
244
+ const WorkbookFinalization = (typeof FinalizationRegistry === 'undefined')
245
+ ? { register: () => {}, unregister: () => {} }
246
+ : new FinalizationRegistry(ptr => wasm.__wbg_workbook_free(ptr, 1));
247
+
248
+ function addToExternrefTable0(obj) {
249
+ const idx = wasm.__externref_table_alloc();
250
+ wasm.__wbindgen_externrefs.set(idx, obj);
251
+ return idx;
252
+ }
253
+
254
+ function getArrayU8FromWasm0(ptr, len) {
255
+ ptr = ptr >>> 0;
256
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
257
+ }
258
+
259
+ let cachedDataViewMemory0 = null;
260
+ function getDataViewMemory0() {
261
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
262
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
263
+ }
264
+ return cachedDataViewMemory0;
265
+ }
266
+
267
+ function getStringFromWasm0(ptr, len) {
268
+ ptr = ptr >>> 0;
269
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
270
+ }
271
+
272
+ let cachedUint8ArrayMemory0 = null;
273
+ function getUint8ArrayMemory0() {
274
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
275
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
276
+ }
277
+ return cachedUint8ArrayMemory0;
278
+ }
279
+
280
+ function handleError(f, args) {
281
+ try {
282
+ return f.apply(this, args);
283
+ } catch (e) {
284
+ const idx = addToExternrefTable0(e);
285
+ wasm.__wbindgen_exn_store(idx);
286
+ }
287
+ }
288
+
289
+ function isLikeNone(x) {
290
+ return x === undefined || x === null;
291
+ }
292
+
293
+ function passArray8ToWasm0(arg, malloc) {
294
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
295
+ getUint8ArrayMemory0().set(arg, ptr / 1);
296
+ WASM_VECTOR_LEN = arg.length;
297
+ return ptr;
298
+ }
299
+
300
+ function passStringToWasm0(arg, malloc, realloc) {
301
+ if (realloc === undefined) {
302
+ const buf = cachedTextEncoder.encode(arg);
303
+ const ptr = malloc(buf.length, 1) >>> 0;
304
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
305
+ WASM_VECTOR_LEN = buf.length;
306
+ return ptr;
307
+ }
308
+
309
+ let len = arg.length;
310
+ let ptr = malloc(len, 1) >>> 0;
311
+
312
+ const mem = getUint8ArrayMemory0();
313
+
314
+ let offset = 0;
315
+
316
+ for (; offset < len; offset++) {
317
+ const code = arg.charCodeAt(offset);
318
+ if (code > 0x7F) break;
319
+ mem[ptr + offset] = code;
320
+ }
321
+ if (offset !== len) {
322
+ if (offset !== 0) {
323
+ arg = arg.slice(offset);
324
+ }
325
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
326
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
327
+ const ret = cachedTextEncoder.encodeInto(arg, view);
328
+
329
+ offset += ret.written;
330
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
331
+ }
332
+
333
+ WASM_VECTOR_LEN = offset;
334
+ return ptr;
335
+ }
336
+
337
+ function takeFromExternrefTable0(idx) {
338
+ const value = wasm.__wbindgen_externrefs.get(idx);
339
+ wasm.__externref_table_dealloc(idx);
340
+ return value;
341
+ }
342
+
343
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
344
+ cachedTextDecoder.decode();
345
+ function decodeText(bytes) {
346
+ return cachedTextDecoder.decode(bytes);
347
+ }
348
+
349
+ const cachedTextEncoder = new TextEncoder();
350
+
351
+ if (!('encodeInto' in cachedTextEncoder)) {
352
+ cachedTextEncoder.encodeInto = function (arg, view) {
353
+ const buf = cachedTextEncoder.encode(arg);
354
+ view.set(buf);
355
+ return {
356
+ read: arg.length,
357
+ written: buf.length
358
+ };
359
+ };
360
+ }
361
+
362
+ let WASM_VECTOR_LEN = 0;
363
+
364
+ const wasmPath = `${__dirname}/calcwright_wasm_bg.wasm`;
365
+ const wasmBytes = require('fs').readFileSync(wasmPath);
366
+ const wasmModule = new WebAssembly.Module(wasmBytes);
367
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
368
+ let wasm = wasmInstance.exports;
369
+ wasm.__wbindgen_start();
Binary file
@@ -0,0 +1,23 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __wbg_workbook_free: (a: number, b: number) => void;
5
+ export const freeFormulaLimit: () => number;
6
+ export const functions: () => any;
7
+ export const installLicence: (a: number, b: number) => [number, number, number];
8
+ export const verifyWorkbook: (a: number, b: number, c: number) => [number, number, number];
9
+ export const workbook_calculate: (a: number) => [number, number, number];
10
+ export const workbook_formulaCount: (a: number) => number;
11
+ export const workbook_fromBytes: (a: number, b: number) => [number, number, number];
12
+ export const workbook_get: (a: number, b: number, c: number) => [number, number, number];
13
+ export const workbook_set: (a: number, b: number, c: number, d: any) => [number, number];
14
+ export const workbook_sheetNames: (a: number) => any;
15
+ export const workbook_toBytes: (a: number) => [number, number, number, number];
16
+ export const __wbindgen_malloc: (a: number, b: number) => number;
17
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
18
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
19
+ export const __wbindgen_exn_store: (a: number) => void;
20
+ export const __externref_table_alloc: () => number;
21
+ export const __wbindgen_externrefs: WebAssembly.Table;
22
+ export const __externref_table_dealloc: (a: number) => void;
23
+ export const __wbindgen_start: () => void;