mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
* Add evaluatex * Try fixing tests * Fix linter issues * Adjust types * Fix user name * Clean up * Update types/evaluatex/evaluatex-tests.ts Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com> * Update types/evaluatex/index.d.ts Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com> * Apply feedback * Add AST * Update test * Support custom functions * Fix * Add lexer and parser * Add evaluate and simplify * Fix linter errors * Fix linter errors * Add missing variable for evaluate * Update test Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
// Type definitions for evaluatex 2.2
|
|
// Project: https://github.com/arthanzel/evaluatex
|
|
// Definitions by: Fawaz Orabi <https://github.com/forabi-cosuno>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
|
|
import _ from './dist/evaluatex';
|
|
|
|
declare namespace evaluatex {
|
|
type IncludeMethods<T> = Pick<T, { [K in keyof T]: T[K] extends (_: any) => any ? K : never }[keyof T]>;
|
|
|
|
type Variable = number;
|
|
|
|
type Variables = Record<string, Variable>;
|
|
|
|
type Constant = number | ((...args: number[]) => number);
|
|
|
|
type Constants = Record<string, Constant>;
|
|
|
|
interface Options {
|
|
latex?: boolean;
|
|
}
|
|
|
|
type AbstractSyntaxTreeNode = (
|
|
| {
|
|
type: 'FUNCTION';
|
|
value: { name?: keyof IncludeMethods<Math> } & ((...args: unknown[]) => number);
|
|
name: string | null;
|
|
}
|
|
| { type: 'SYMBOL' | 'PRODUCT' | 'SUM' | 'INVERSE' | 'NEGATE' | 'POWER'; value: string }
|
|
| { type: 'NUMBER'; value: number }
|
|
) & {
|
|
children: AbstractSyntaxTreeNode[];
|
|
name: null | string;
|
|
evaluate(variables?: Variables): number;
|
|
simplify(): AbstractSyntaxTreeNode;
|
|
};
|
|
|
|
type Token =
|
|
| {
|
|
type: 'NUMBER' | 'POWER' | 'DIVIDE' | 'LPAREN' | 'RPAREN' | 'COMMAND';
|
|
value: string | number;
|
|
name: string | null;
|
|
}
|
|
| {
|
|
type: 'COMMAND';
|
|
value(params: unknown[]): unknown;
|
|
name: string | null;
|
|
}
|
|
| { type: 'SYMBOL'; value: string; name: null };
|
|
|
|
interface EvaluatexResult {
|
|
/**
|
|
* @param variables a map of variables that can change between invocations of fn.
|
|
* @returns the numerical result of the calculation.
|
|
*/
|
|
(variables?: Variables): number;
|
|
tokens: Token[];
|
|
expression: string;
|
|
ast: AbstractSyntaxTreeNode;
|
|
}
|
|
}
|
|
|
|
declare const evaluatex: typeof _;
|
|
|
|
export = evaluatex;
|