Skip to content

Commit 3a1b308

Browse files
committed
Quick JS doc rewrite
1 parent 150e128 commit 3a1b308

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

expression-js/build.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@ export default {
4343
main: "./lib.js",
4444
typings: "./lib.d.ts"
4545
}, null, 4));
46+
},
47+
async "build:readme.md"(config) {
48+
await fs.writeFile(config.out.join('pkg/README.md'), await fs.readFile('./dist.md', {encoding: 'utf8'}));
4649
}
4750
}

expression-js/dist.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# expressions
2+
3+
Parser for the expression language used in the spreadsheet plugin. This document outlines the JavaScript portion of the
4+
library. For Rust see [the Rust crate](../README.md).
5+
6+
## Quickstart
7+
8+
In order to evaluate expressions, three things must happen;
9+
10+
1. A context object containing a [Data Provider](#Data Provider) must be registered
11+
2. The list of all functions, variables and operators needs to be defined
12+
3. The expression needs to be passed into the parser.
13+
14+
## Data Provider
15+
16+
A data provider is an object which converts addresses into values. Addresses are arbitrary text tokens wrapped in
17+
braces. The provider determines their meaning. [See the `repl.ts`](examples/repl.ts) for a feature-complete REPL.
18+
19+
```typescript
20+
import * as expr from 'expression';
21+
22+
class Table implements expr.DataSource {
23+
query(cx:any, query:string) {
24+
// Parse the query however you need to.
25+
// For example, the format `column:row`
26+
27+
return "Hey!";
28+
}
29+
}
30+
```
31+
32+
## Context
33+
34+
Next you'll need a context object which holds state and variables and acts as an API to the expression engine. You can
35+
define your own functions, globals and operators here.
36+
37+
```typescript
38+
import * as assert from 'node:assert';
39+
import * as expr from 'expression';
40+
41+
const cx = new expr.Context(new Table())
42+
.withGlobal("twelve", 12)
43+
.withGlobal("print", args => console.log(args));
44+
45+
assert.eq(cx.evaluateStr("twelve") == 12);
46+
```

0 commit comments

Comments
 (0)