Skip to content

Commit

Permalink
Add type definitions for math-expression-evaluator (#43009)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Zerella <adamzerella@users.noreply.github.com>
  • Loading branch information
azerella and Adam Zerella committed Mar 15, 2020
1 parent 9582dc2 commit 3cbb889
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
24 changes: 24 additions & 0 deletions types/math-expression-evaluator/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
36 changes: 36 additions & 0 deletions types/math-expression-evaluator/math-expression-evaluator-tests.ts
Original file line number Diff line number Diff line change
@@ -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();
25 changes: 25 additions & 0 deletions types/math-expression-evaluator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
3 changes: 3 additions & 0 deletions types/math-expression-evaluator/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}

0 comments on commit 3cbb889

Please sign in to comment.