@tryganit/core 0.1.3 → 0.1.6
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 +123 -0
- package/ganit_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @tryganit/core
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@tryganit/core)
|
|
4
|
+
[](https://crates.io/crates/ganit-core)
|
|
5
|
+
[](https://docs.rs/ganit-core)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
|
|
8
|
+
WebAssembly-powered spreadsheet formula engine for JavaScript/TypeScript.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install @tryganit/core
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
### Node.js (CJS)
|
|
19
|
+
|
|
20
|
+
Works out of the box — no bundler configuration needed.
|
|
21
|
+
|
|
22
|
+
```js
|
|
23
|
+
const { evaluate, validate, list_functions } = require('@tryganit/core');
|
|
24
|
+
|
|
25
|
+
const result = evaluate('SUM(A1, B1)', { A1: 100, B1: 200 });
|
|
26
|
+
// => { type: 'number', value: 300 }
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Vite
|
|
30
|
+
|
|
31
|
+
Install the wasm plugin first:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
npm install -D vite-plugin-wasm
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Add it to `vite.config.js`:
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import wasm from 'vite-plugin-wasm';
|
|
41
|
+
|
|
42
|
+
export default {
|
|
43
|
+
plugins: [wasm()],
|
|
44
|
+
};
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Then import and use normally:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
import { evaluate } from '@tryganit/core';
|
|
51
|
+
|
|
52
|
+
const result = evaluate('IF(A1 > 0, "yes", "no")', { A1: 1 });
|
|
53
|
+
// => { type: 'text', value: 'yes' }
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### webpack 5
|
|
57
|
+
|
|
58
|
+
webpack 5 supports WebAssembly natively. Enable the experiment in `webpack.config.js`:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
module.exports = {
|
|
62
|
+
experiments: {
|
|
63
|
+
asyncWebAssembly: true,
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## API
|
|
69
|
+
|
|
70
|
+
### `evaluate(formula, variables)`
|
|
71
|
+
|
|
72
|
+
Evaluates a formula with the given variable bindings.
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
evaluate('SUM(A1, B1)', { A1: 100, B1: 200 })
|
|
76
|
+
// => { type: 'number', value: 300 }
|
|
77
|
+
|
|
78
|
+
evaluate('CONCAT("Hello, ", name)', { name: 'world' })
|
|
79
|
+
// => { type: 'text', value: 'Hello, world' }
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Return value shape:**
|
|
83
|
+
|
|
84
|
+
| `type` | Shape |
|
|
85
|
+
|-----------|--------------------------------------|
|
|
86
|
+
| `number` | `{ type: 'number', value: 6 }` |
|
|
87
|
+
| `text` | `{ type: 'text', value: 'yes' }` |
|
|
88
|
+
| `boolean` | `{ type: 'boolean', value: true }` |
|
|
89
|
+
| `error` | `{ type: 'error', error: '#NAME?' }` |
|
|
90
|
+
| `empty` | `{ type: 'empty', value: null }` |
|
|
91
|
+
|
|
92
|
+
### `validate(formula)`
|
|
93
|
+
|
|
94
|
+
Checks whether a formula is syntactically valid without evaluating it.
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
validate('SUM(A1, B1)') // => { valid: true }
|
|
98
|
+
validate('SUM(A1,') // => { valid: false, error: '...' }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### `list_functions()`
|
|
102
|
+
|
|
103
|
+
Returns metadata for all built-in functions as an array of `{ name, category, syntax, description }`.
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
const fns = list_functions();
|
|
107
|
+
// [
|
|
108
|
+
// { name: 'SUM', category: 'math', syntax: 'SUM(value1, ...)', description: 'Sum of all arguments' },
|
|
109
|
+
// { name: 'AVERAGE', category: 'math', syntax: 'AVERAGE(value1, ...)', description: 'Arithmetic mean of all arguments' },
|
|
110
|
+
// { name: 'IF', category: 'logical', syntax: 'IF(condition, value_if_true, value_if_false)', description: 'Conditional evaluation' },
|
|
111
|
+
// ...
|
|
112
|
+
// ]
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
**Available functions by category:**
|
|
116
|
+
|
|
117
|
+
| Category | Functions |
|
|
118
|
+
|------------|-----------|
|
|
119
|
+
| math | SUM, AVERAGE, PRODUCT, ROUND, ROUNDUP, ROUNDDOWN, INT, ABS, SIGN, MOD, POWER, SQRT, LOG, LOG10, LN, EXP, CEILING, FLOOR, RAND, RANDBETWEEN, PI, SIN, COS, TAN, QUOTIENT |
|
|
120
|
+
| logical | IF, AND, OR, NOT, IFERROR, IFNA, IFS, SWITCH, ISNUMBER, ISTEXT, ISERROR, ISBLANK, ISNA |
|
|
121
|
+
| text | LEFT, MID, RIGHT, LEN, LOWER, UPPER, TRIM, CONCATENATE, FIND, SUBSTITUTE, REPLACE, TEXT, VALUE, REPT |
|
|
122
|
+
| financial | PMT, NPV, IRR, PV, FV, RATE, NPER |
|
|
123
|
+
| statistical | COUNT, COUNTA, MAX, MIN, MEDIAN |
|
package/ganit_wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tryganit/core",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Spreadsheet formula engine for the browser — Excel-compatible formula evaluator compiled to WebAssembly",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.6",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|