Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wessberg/ts-evaluator

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wessberg/ts-evaluator

An interpreter for Typescript that can evaluate an arbitrary Node within a Typescript AST

  • 0.0.29
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
250K
decreased by-28.48%
Maintainers
1
Weekly downloads
 
Created

What is @wessberg/ts-evaluator?

@wessberg/ts-evaluator is a TypeScript evaluation library that allows you to evaluate TypeScript code at compile-time. It can be used to execute TypeScript code, inspect the results, and perform various compile-time computations.

What are @wessberg/ts-evaluator's main functionalities?

Evaluate TypeScript Code

This feature allows you to evaluate TypeScript code and get the result. In this example, a simple addition function is evaluated, and the result is logged.

const { evaluate } = require('@wessberg/ts-evaluator');
const result = evaluate({
  code: 'const add = (a: number, b: number) => a + b; add(2, 3);'
});
console.log(result); // Outputs: 5

Inspect TypeScript AST

This feature allows you to inspect the Abstract Syntax Tree (AST) of the evaluated TypeScript code. By setting the `inspect` option to true, you can get detailed information about the code structure.

const { evaluate } = require('@wessberg/ts-evaluator');
const result = evaluate({
  code: 'const add = (a: number, b: number) => a + b; add(2, 3);',
  inspect: true
});
console.log(result); // Outputs the AST of the evaluated code

Compile-time Computations

This feature allows you to perform complex compile-time computations. In this example, a recursive function to calculate the factorial of a number is evaluated, and the result is logged.

const { evaluate } = require('@wessberg/ts-evaluator');
const result = evaluate({
  code: 'const factorial = (n: number): number => n <= 1 ? 1 : n * factorial(n - 1); factorial(5);'
});
console.log(result); // Outputs: 120

Other packages similar to @wessberg/ts-evaluator

Keywords

FAQs

Package last updated on 17 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc