Skip to content

Commit

Permalink
Update type definitions
Browse files Browse the repository at this point in the history
Minor changes to make the type definitions more accurate

Add boolean and array to `Value` type, since `evaluate` can return those
```js
Parser.evaluate("true") // returns boolean
Parser.evaluate("[1,2,3]") // returns array
```

Update `evaluate`'s and `simplify`'s definition to only take an object of
`Value`s instead of a `Value` (which can also be array/boolean/etc.)
Update `evaluate` to return a `Value` type instead of just `number`

Add `operators.array` to the `ParserOptions`
  • Loading branch information
jesse-r-s-hines committed Nov 12, 2021
1 parent 6e889e0 commit 5282c73
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions parser.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export type Value = number
| string
| boolean
| ((...args: Value[]) => Value)
| Value[]
| { [propertyName: string]: Value };

export interface Values {
Expand Down Expand Up @@ -51,6 +53,7 @@ export interface ParserOptions {
max?: boolean,
assignment?: boolean,
fndef?: boolean,
array?: boolean
cbrt?: boolean,
expm1?: boolean,
log1p?: boolean,
Expand All @@ -65,16 +68,16 @@ export class Parser {
functions: any;
consts: any;
parse(expression: string): Expression;
evaluate(expression: string, values?: Value): number;
evaluate(expression: string, values?: Values): Value;
static parse(expression: string): Expression;
static evaluate(expression: string, values?: Value): number;
static evaluate(expression: string, values?: Values): Value;
}

export interface Expression {
simplify(values?: Value): Expression;
evaluate(values?: Value): any;
simplify(values?: Values): Expression;
evaluate(values?: Values): Value;
substitute(variable: string, value: Expression | string | number): Expression;
symbols(options?: { withMembers?: boolean }): string[];
variables(options?: { withMembers?: boolean }): string[];
toJSFunction(params: string | string[], values?: Value): (...args: any[]) => number;
toJSFunction(params: string | string[], values?: Values): (...args: any[]) => Value;
}

0 comments on commit 5282c73

Please sign in to comment.