-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add type definitions for math-expression-evaluator (#43009)
Co-authored-by: Adam Zerella <adamzerella@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
36
types/math-expression-evaluator/math-expression-evaluator-tests.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "dtslint/dt.json" | ||
} |