Skip to content

Commit 80c7ba9

Browse files
committed
fix(feat): add missing options and types
1 parent 247acc8 commit 80c7ba9

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

src/context.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { solve, solveBatch, type Result } from './solve';
22
import { addBuiltinFunctions, type ComputeFunction } from './functions';
3-
import { renderTokensAsHTML } from './render/html';
3+
import { renderTokensAsHTML, HTMLRenderOptions } from './render/html';
44
import { tokenize } from './lexer';
5-
import { renderTokensAsLaTeX } from './render/latex';
5+
import { renderTokensAsLaTeX, LaTeXRenderOptions } from './render/latex';
66

77
type Preferences = {
88
fractionDigits: number;
99
precision: number;
1010
angles: 'rad' | 'deg';
11-
[k: string]: string | number;
1211
};
1312

1413
export type Context = {
@@ -19,10 +18,10 @@ export type Context = {
1918
};
2019

2120
export interface ContextAPI extends Context {
22-
solve: (code: string) => Result;
23-
solveBatch: (code: string) => Result[];
24-
renderAsHTML: (code: string) => string;
25-
renderAsLaTeX: (code: string) => string;
21+
solve(code: string): Result;
22+
solveBatch(code: string): Result[];
23+
renderAsHTML(code: string, options?: Partial<HTMLRenderOptions>): string;
24+
renderAsLaTeX(code: string, options?: Partial<LaTeXRenderOptions>): string;
2625
}
2726

2827
export type ContextOptions = {
@@ -58,8 +57,10 @@ export function createContext(
5857

5958
if (options?.preferences) {
6059
for (const k in ctx.preferences) {
61-
const v = options.preferences[k];
62-
if (v) ctx.preferences[k] = v;
60+
const v = (options.preferences as Record<string, string | number>)[
61+
k
62+
];
63+
if (v) (ctx.preferences as Record<string, string | number>)[k] = v;
6364
}
6465
}
6566

@@ -79,10 +80,17 @@ export function createContext(
7980

8081
return {
8182
...ctx,
82-
solve: (code: string) => solve(ctx, code),
83-
solveBatch: (code: string) => solveBatch(ctx, code),
84-
renderAsHTML: (code: string) => renderTokensAsHTML(tokenize(ctx, code)),
85-
renderAsLaTeX: (code: string) =>
86-
renderTokensAsLaTeX(tokenize(ctx, code))
83+
solve(code: string) {
84+
return solve(ctx, code);
85+
},
86+
solveBatch(code: string) {
87+
return solveBatch(ctx, code);
88+
},
89+
renderAsHTML(code: string, options?: HTMLRenderOptions) {
90+
return renderTokensAsHTML(tokenize(ctx, code), options);
91+
},
92+
renderAsLaTeX(code: string, options?: LaTeXRenderOptions) {
93+
return renderTokensAsLaTeX(tokenize(ctx, code), options);
94+
}
8795
};
8896
}

0 commit comments

Comments
 (0)