@boenfu/tsmonkey
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

🐒 TSMonkey

npm install @boenfu/tsmonkey

Eval

import type { Eval } from '@boenfu/tsmonkey'

Eval<'4 + 8'> // 12
Eval<'2 * (4 + 8)'> // 24
Eval<'!99'> // false

Eval<'(3 + 2) * 5 == 25'> // true
Eval<'(3 > 2) != (2 > 3)'> // true

Eval<'7 && 9'> // 9
Eval<'false || 0'> // 0

variable declaration

Eval<`
let a = 2
let b = 3
let c = a * b
c * c
`> // 36

if else

Eval<`
let a = 2
let b = 3

if(a >= b) {
  return "a is greater than b"
} else {
  return "a is less than b"
}
`> // "a is less than b"

function

Eval<`
let a = 5
let b = 10

function foo(a, b) {
  return a - b
}

foo(b, a)
`> // 5

fibonacci

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

import type { Parser } from '@boenfu/tsmonkey'
Parser<'let a = "如果你要写年"'>
// Program<[LetStatement<Identifier<"a">, StringLiteral<"如果你要写年">>]>

Lexer

import type { Lexer } from '@boenfu/tsmonkey'
Lexer<'let a = "如果你要写年"'>
// [
//   Token<TokenType.LET, "let">,
//   Token<TokenType.IDENT, "a">,
//   Token<TokenType.ASSIGN, "=">,
//   Token<TokenType.STRING, "如果你要写年">,
//   Token<TokenType.EOF, "">
// ]

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.00latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.00

Package Sidebar

Install

npm i @boenfu/tsmonkey

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

32.8 kB

Total Files

12

Last publish

Collaborators

  • boenfu