ts2c transpiles JavaScript/TypeScript (ES3 subset) to readable C89 code for low-power microcontrollers (ESP32, ESP8266, AVR). Version 3.0.0 is under active development, supporting ~70% of ES3 (95% statements/expressions, 17% built-in objects). All numbers are int16_t; no floats, big numbers, prototype, eval, Date, or Math. Output is minimal, self-contained C with no runtime overhead. Different from JerryScript/Espruino by compiling to native C rather than interpreting, reducing memory and battery usage.
npm install ts2cNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Transpile a recursive factorial function and print C code.
Use only integer arithmetic within int16 range; avoid fractions and large constants.
Implement Date/Math functions manually or use alternative libraries; avoid prototype chaining.
Replace eval with static code; use computed property names only with known keys.
Write result to file manually: fs.writeFileSync('out.c', transpile(code));Run: npm install -g typescript
Use: import { transpile } from 'ts2c' or const { transpile } = require('ts2c')Replace with manual implementation or avoid trigonometric functions.