{"id":13546355,"url":"https://github.com/andrei-markeev/ts2c","last_synced_at":"2025-05-14T07:10:23.420Z","repository":{"id":37285866,"uuid":"64089592","full_name":"andrei-markeev/ts2c","owner":"andrei-markeev","description":"Convert Javascript/TypeScript to C","archived":false,"fork":false,"pushed_at":"2025-05-11T07:37:20.000Z","size":2051,"stargazers_count":1305,"open_issues_count":10,"forks_count":96,"subscribers_count":59,"default_branch":"master","last_synced_at":"2025-05-11T08:19:26.397Z","etag":null,"topics":["c","javascript","js","transpiler","typescript"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/andrei-markeev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-07-24T23:05:37.000Z","updated_at":"2025-05-08T08:08:37.000Z","dependencies_parsed_at":"2024-01-14T14:31:02.417Z","dependency_job_id":"da8d0c49-9aef-475d-9146-f0f5265d6b59","html_url":"https://github.com/andrei-markeev/ts2c","commit_stats":{"total_commits":280,"total_committers":9,"mean_commits":31.11111111111111,"dds":0.08571428571428574,"last_synced_commit":"9c54287ff80fed298c256e23cb136aff273e9101"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrei-markeev%2Fts2c","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrei-markeev%2Fts2c/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrei-markeev%2Fts2c/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andrei-markeev%2Fts2c/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andrei-markeev","download_url":"https://codeload.github.com/andrei-markeev/ts2c/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253535598,"owners_count":21923680,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","javascript","js","transpiler","typescript"],"created_at":"2024-08-01T12:00:35.801Z","updated_at":"2025-05-14T07:10:18.409Z","avatar_url":"https://github.com/andrei-markeev.png","language":"C","readme":"JavaScript/TypeScript to C transpiler\n=====================================\n\nProduces readable C89 code from JS/TS code.\n\nFor example, this JavaScript:\n\n```javascript\nconsole.log(\"Hello world!\");\n```\n\ntranspiles to the following C code:\n\n```c\n#include \u003cstdio.h\u003e\n\nint main() {\n    printf(\"Hello world!\\n\");\n    return 0;\n}\n```\n\nNo excessive code that is not actually needed is ever generated.\n\nThe output is as readable as possible and mostly maps well to the original code.\n\nAnother example:\n\n```javascript\nvar obj = { key: \"hello\" };\nobj[\"newKey\"] = \"test\";\nconsole.log(obj);\n```\n\ntranspiles to the following C code:\n\n```c\n#include \u003cstdlib.h\u003e\n#include \u003cassert.h\u003e\n#include \u003cstdio.h\u003e\n\nstruct obj_t {\n    const char * key;\n    const char * newKey;\n};\n\nstatic struct obj_t * obj;\nint main(void) {\n\n    obj = malloc(sizeof(*obj));\n    assert(obj != NULL);\n    obj-\u003ekey = \"hello\";\n    obj-\u003enewKey = \"test\";\n\n    printf(\"{ \");\n    printf(\"key: \\\"%s\\\"\", obj-\u003ekey);\n    printf(\", \");\n    printf(\"newKey: \\\"%s\\\"\", obj-\u003enewKey);\n    printf(\" }\\n\");\n\n    free(obj);\n\n    return 0;\n}\n```\n\n\nProject status\n--------------\n\n__**Work in progress:**__ it works, but only about **70% of ES3** specification is currently supported: statements and expressions - 95%, built-in objects - 17%.\n\nNotable NOT supported features include, for example: float and big numbers (all numbers are `int16_t` currently), `prototype`, `arguments` object, `eval`, `Date`, `Math`, etc.\n\nDetailed information about supported and planned features can be found in [COVERAGE.md](https://github.com/andrei-markeev/ts2c/blob/master/COVERAGE.md).\n\nContributions are welcome! See [src/README.md](https://github.com/andrei-markeev/ts2c/blob/master/src/README.md)\n\n\nLive demo\n---------\n\nYou can try it out yourself online:\n\n - https://andrei-markeev.github.io/ts2c/\n\nRationale\n---------\n\nThe main motivation behind this project was to solve problem that IoT and wearables cannot be currently efficiently\nprogrammed with JavaScript.\n\nThe thing is, for sustainable IoT devices that can work for a *long time* on single battery, things like\nRaspberry Pi won't do. You'll have to use low-power microcontrollers, which usually have very little memory available.\n\nRAM ranges literally **from 512 bytes** to 120KB, and ROM/Flash **from 1KB** to 4MB. In such conditions, even\noptimized JS interpreters like [JerryScript](https://github.com/Samsung/jerryscript),\n[Espruino](https://github.com/espruino/Espruino) or [V7](https://github.com/cesanta/v7) are sometimes too\nmuch of an overhead and usually lead to the increased battery drain and/or don't leave a lot of system\nresources to your program.\n\nOf course, transpiler cannot map 100% of the JavaScript language and some things are have to be left out,\nnotably `eval`. Still, current conclusion is, that it is possible to transpile most of the language.\n\nTargets\n-------\n\nPlanned transpilation targets:\n\n - [ESP32](https://en.wikipedia.org/wiki/ESP32) - work in progress, see project [ESP-IDF target for TS2C](https://github.com/andrei-markeev/ts2c-target-esp-idf)\n - [ESP8266](https://en.wikipedia.org/wiki/ESP8266)\n - [Atmel AVR](https://en.wikipedia.org/wiki/Atmel_AVR#Basic_families) family (used in Arduino boards)\n - [TI MSP430](https://en.wikipedia.org/wiki/TI_MSP430) family\n\n\nUsage\n-----\n\n**Command line:**\n```\nnpm install -g ts2c\n```\n\nSyntax:\n```sh\nts2c \u003cfiles to transpile\u003e\n```\n\n**Node.js:**\n```\nnpm install ts2c\n```\n\n```javascript\nconst ts2c = require(\"ts2c\");\nconst cCode = ts2c.transpile(\"console.log('Hello world!')\");\nconsole.log(cCode);\n```\n\n**In browser:**\n```html\n\u003cscript src=\"https://unpkg.com/typescript\"\u003e\u003c/script\u003e\n\u003cscript src=\"ts2c.bundle.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    var cCode = ts2c.transpile(\"console.log('Hello world!')\");\n    alert(cCode);\n\u003c/script\u003e\n```\n\n","funding_links":[],"categories":["C","TypeScript","Other Language Targets"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrei-markeev%2Fts2c","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandrei-markeev%2Fts2c","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandrei-markeev%2Fts2c/lists"}