Skip to content

Commit 47eab47

Browse files
authored
docs(error-handling): add error handling docs (#1)
1 parent 5828617 commit 47eab47

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ import evalExpr from "eval-num-expr";
1313

1414
const value = evalExpr("100 + 3 * 55 + 73 - 73 * 18%");
1515
// value = 324.86
16+
17+
// With Invalid Expressions handling
18+
try {
19+
const value = evalExpr("100 + (3 * 55");
20+
} catch (e) {
21+
// Will throw an exception for invalid expressions
22+
console.error(e.message)
23+
}
1624
```
1725

1826
You can use basic operations (e.g. +, -, \*, /, %, ^ etc.) in you expressions.
@@ -27,10 +35,22 @@ You can use basic operations (e.g. +, -, \*, /, %, ^ etc.) in you expressions.
2735
2836
## Api
2937

30-
### evalExpr
38+
> This package supports TypeScript.
3139
32-
This is the default and only from this package.
40+
### evalExpr
3341

34-
```js
42+
This is the default and only export from this package.
43+
44+
```typescript
45+
/**
46+
* Evaluate numeric mathematical expression
47+
* @param string expression - The expression to evaluate ("24 + 65 * 3 - 48")
48+
* @return number - The evaluated value.
49+
*
50+
* @throws Will throw an error if the expression in invalid.
51+
*
52+
* NOTE: When passing floating points, please handle the digits after decimal point
53+
* e.g. 2 - 1.1 leads to 0.8999999999999999 intead of .9
54+
*/
3555
evalExpr(expressions: string)
3656
```

types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* @param string expression - The expression to evaluate ("24 + 65 * 3 - 48")
44
* @return number - The evaluated value.
55
*
6+
* @throws Will throw an error if the expression in invalid.
7+
*
68
* NOTE: When passing floating points, please handle the digits after decimal point
79
* e.g. 2 - 1.1 leads to 0.8999999999999999 intead of .9
810
*/

0 commit comments

Comments
 (0)