andrei-markeev/ts2c logo

andrei-markeev/ts2c

Free

Convert Javascript/TypeScript to C

FreeFree tier
Type
Open Source

About andrei-markeev/ts2c

ts2c is an open-source transpiler that converts JavaScript and TypeScript code into readable C89 code. It generates minimal, clean C output that maps closely to the original source, avoiding excessive boilerplate. Currently supporting approximately 70% of the ES3 specification, it includes robust handling of statements and expressions (95%) but limited built-in object support (17%). The project is designed to enable efficient programming of low-power microcontrollers and IoT devices where JavaScript interpreters are too resource-intensive. It offers command-line usage via npm, a Node.js API, and a browser-based live demo. Planned targets include ESP32, ESP8266, Atmel AVR, and TI MSP430 families.

Key Features

Transpiles JavaScript and TypeScript to readable C89 code
Generates minimal, clean output with no excessive boilerplate
Supports approximately 70% of ES3 specification (statements/expressions 95%, built-in objects 17%)
Includes command-line interface, Node.js API, and browser-based live demo
Open source with contributions welcome
Targeted for IoT and low-power microcontroller programming (ESP32, ESP8266, Atmel AVR, TI MSP430)

Pros & Cons

Pros
  • Produces human-readable C code that mirrors original logic
  • Minimal runtime overhead compared to JavaScript interpreters
  • Multiple interfaces: CLI, Node.js, and browser
  • Active open-source project with clear coverage documentation
  • Live demo available for quick testing
Cons
  • Only about 70% of ES3 specification is supported
  • Built-in object support is limited (17%), lacking Date, Math, eval, etc.
  • All numbers are treated as int16_t (no float or big number support)
  • Prototype chain not supported
  • Work in progress; not yet production-ready for full JavaScript compatibility

Best For

Programming IoT devices with JavaScript/TypeScriptDeveloping firmware for low-power microcontrollersTranspiling existing JavaScript code to C for embedded systemsEducational tool for learning C code generation from high-level languagesRapid prototyping on resource-constrained hardware

FAQ

What is ts2c?
ts2c is an open-source transpiler that converts JavaScript and TypeScript code into C89 code, designed primarily for low-power IoT and embedded systems.
How do I use ts2c?
You can install it via npm with 'npm install -g ts2c' and use the command line, require it as a Node.js module, or use the browser bundle via unpkg.
What features of JavaScript are not supported?
Notable unsupported features include floating-point and big numbers (all numbers are int16_t), prototype chains, eval, Date, Math, and other built-in objects. See COVERAGE.md for details.
What hardware targets are planned?
The project plans to support ESP32 (in progress), ESP8266, Atmel AVR (used in Arduino), and TI MSP430 families.