https://github.com/helkyle/tiny-eval
A tiny and safe eval written in TypeScript
https://github.com/helkyle/tiny-eval
Last synced: 10 months ago
JSON representation
A tiny and safe eval written in TypeScript
- Host: GitHub
- URL: https://github.com/helkyle/tiny-eval
- Owner: HelKyle
- License: mit
- Created: 2025-07-13T03:06:13.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-07-13T03:14:04.000Z (10 months ago)
- Last Synced: 2025-07-13T03:38:41.982Z (10 months ago)
- Language: TypeScript
- Size: 0 Bytes
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tiny-eval
A tiny, safe, and elegant arithmetic expression evaluator for TypeScript/JavaScript
---
## โจ Features
- **Tiny**: Minimal dependencies, fast and lightweight
- **Safe**: No use of `eval`, parses and evaluates expressions securely
- **TypeScript-first**: Written in TypeScript, with full type definitions
---
## ๐ฆ Installation
```bash
pnpm install tiny-eval
```
---
## ๐ Usage
```ts
import { evaluate } from 'tiny-eval'
console.log(evaluate('1 + 2 * 3')) // 7
console.log(evaluate('(1 + 2) * 3')) // 9
console.log(evaluate('0.1 + 0.2')) // 0.3
```
---
## ๐งช Examples
```ts
// Basic operations
evaluate('1+2') // 3
evaluate('5-3') // 2
evaluate('4*2') // 8
evaluate('8/2') // 4
// Operator precedence
evaluate('2+3*4') // 14
evaluate('2*3+4') // 10
// Parentheses
evaluate('(2+3)*4') // 20
evaluate('2*(3+4)') // 14
evaluate('((1+2)*3)+4') // 13
// Decimals
evaluate('0.1+0.2') // 0.3
evaluate('1.5*2') // 3
---
## ๐งโ๐ป Testing
```bash
pnpm test
```
---
## ๐ License
MIT License ยฉ 2025 HelKyle
---