Add type definitions for math-expression-evaluator (#43009)

Co-authored-by: Adam Zerella <adamzerella@users.noreply.github.com>
This commit is contained in:
Adam Zerella 2020-03-15 12:41:16 +10:30 committed by GitHub
parent 9582dc2bb7
commit 3cbb889216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,24 @@
// Type definitions for math-expression-evaluator 1.2
// Project: https://github.com/bugwheels94/math-expression-evaluator
// Definitions by: Adam Zerella <https://github.com/adamzerella>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
interface Token {
token: string;
type: number;
value?: string|((a: number, b?: number) => number);
show: string;
preced?: number;
}
declare class Mexp {
static lex(inp: string, tokens?: Token[]): Mexp;
formulaEval(): Mexp;
toPostfix(): Mexp;
postfixEval(pair?: object): number|string;
static eval(exp: string, tokens?: Token[], pair?: object): string;
static eval(exp: string, mexp?: object): string;
static addToken(tokens: Token[]): void;
}
export = Mexp;

View File

@ -0,0 +1,36 @@
import Mexp = require("math-expression-evaluator");
Mexp.eval("5*.8");
Mexp.eval("5*.8", { mexp: 5 });
Mexp.eval("mexp(3)", [{
type: 0,
show: "mexp(\",value:function(a){return 5*a;}",
preced: 11,
token: "mexp"
}]);
Mexp.eval("mexp(3)", [{
type: 0,
token: "inverse",
show: "inverse",
value: (a => 1 / a)
}]);
Mexp.addToken([{
type: 3,
token: "git",
show: "git",
value: "git"
}]);
Mexp.eval("mexp*3", { mexp: 5 });
Mexp.addToken([{
type: 0,
show: "mexp",
value: (a => 5 * a),
preced: 11,
token: "mexp"
}]);
Mexp.lex("mexp3").toPostfix().postfixEval();
Mexp.lex('mexp3').toPostfix();
Mexp.lex('mexp3').toPostfix().formulaEval();

View File

@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [
],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"math-expression-evaluator-tests.ts"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}