Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/boenfu/tsmonkey
https://github.com/boenfu/tsmonkey
monkey-language type-challenges typescript
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/boenfu/tsmonkey
- Owner: boenfu
- License: mit
- Created: 2024-07-05T15:41:54.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-12T01:10:05.000Z (3 months ago)
- Last Synced: 2024-10-12T05:28:45.569Z (about 1 month ago)
- Topics: monkey-language, type-challenges, typescript
- Language: TypeScript
- Homepage:
- Size: 131 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## 🐒 TSMonkey
```bash
npm install @boenfu/tsmonkey
```### Eval
```typescript
import type { Eval } from '@boenfu/tsmonkey'Eval<'4 + 8'> // 12
Eval<'2 * (4 + 8)'> // 24
Eval<'!99'> // falseEval<'(3 + 2) * 5 == 25'> // true
Eval<'(3 > 2) != (2 > 3)'> // trueEval<'7 && 9'> // 9
Eval<'false || 0'> // 0
```variable declaration
```typescript
Eval<`
let a = 2
let b = 3
let c = a * b
c * c
`> // 36
```if else
```typescript
Eval<`
let a = 2
let b = 3if(a >= b) {
return "a is greater than b"
} else {
return "a is less than b"
}
`> // "a is less than b"
```function
```typescript
Eval<`
let a = 5
let b = 10function foo(a, b) {
return a - b
}foo(b, a)
`> // 5
```fibonacci
```typescript
Eval<`
function fibonacci(n) {
if (n < 2) { return 0 }
if (n == 2) { return 1 }return fibonacci(n - 1) + fibonacci(n - 2)
}fibonacci(6)
`> // 5
```
### Parser
```typescript
import type { Parser } from '@boenfu/tsmonkey'
Parser<'let a = "如果你要写年"'>
// Program<[LetStatement, StringLiteral<"如果你要写年">>]>
```### Lexer
```typescript
import type { Lexer } from '@boenfu/tsmonkey'
Lexer<'let a = "如果你要写年"'>
// [
// Token,
// Token,
// Token,
// Token,
// Token
// ]
```