{"id":27070287,"url":"https://github.com/henryquan/dartinjs","last_synced_at":"2026-04-07T08:32:03.474Z","repository":{"id":286279985,"uuid":"960942922","full_name":"HenryQuan/DartInJS","owner":"HenryQuan","description":"Using Dart functions with Javascript","archived":false,"fork":false,"pushed_at":"2025-04-06T01:14:24.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T19:58:10.748Z","etag":null,"topics":["bun","dart","javascript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HenryQuan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2025-04-05T12:07:54.000Z","updated_at":"2025-04-06T01:14:27.000Z","dependencies_parsed_at":"2025-04-05T13:22:03.394Z","dependency_job_id":"8ff31f64-7de5-4d9d-a2ed-66d53dc4922e","html_url":"https://github.com/HenryQuan/DartInJS","commit_stats":null,"previous_names":["henryquan/dartinjs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenryQuan%2FDartInJS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenryQuan%2FDartInJS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenryQuan%2FDartInJS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HenryQuan%2FDartInJS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HenryQuan","download_url":"https://codeload.github.com/HenryQuan/DartInJS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248103907,"owners_count":21048245,"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":["bun","dart","javascript"],"created_at":"2025-04-05T22:20:15.559Z","updated_at":"2026-04-07T08:32:03.459Z","avatar_url":"https://github.com/HenryQuan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Dart in JS - Cross-Platform Integration\n\n\u003e Compile Dart code to JavaScript and use it in browsers, Node.js, React Native, or any JS runtime — share Dart logic across platforms without rewriting it.\n\n## Why?\n\nIf you already have Dart/Flutter business logic, this lets you **reuse it in web or React Native** projects with zero rewrites. Gradually migrate from Flutter to web or React Native by compiling shared Dart code to JS, exposing it through a typed bridge, and importing it wherever you need it. No more maintaining duplicate logic in two languages.\n\n## 🚀 Quick Start\n\n```bash\nnpm run build        # Compile Dart → JS + auto-generate TypeScript types\nnpm test             # Verify everything works (17 tests)\nnpm run dev:browser  # Browser dev server (React + Vite)\nnpm run watch        # Auto-rebuild on file changes\nnpm run example:ts   # Run Node.js TypeScript example\n```\n\u003e All commands work with **npm**, **yarn**, or **bun** on Windows, macOS, and Linux.\n\n## 🎯 Usage\n\n**TypeScript / Node.js / Bun / Deno** — import and call with full type safety:\n```typescript\nimport dartbridge from './dartloader.ts';\n\nconst sorted: number[] = dartbridge.quickSort([3, 1, 4], 0, 2);\nconst data: string = await dartbridge.fetchData();\n```\n\n**Browser / React / React Native** — same API via the shared loader:\n```typescript\nimport { getDartBridge } from '../../shared/dartloader';\nconst dartbridge = getDartBridge();\n\nconst sorted = dartbridge.quickSort([3, 1, 4, 1, 5, 9], 0, 5); // [1,1,3,4,5,9]\nconst data = JSON.parse(await dartbridge.fetchData());\n```\n\n**Adding a new Dart function** (then run `npm run build` — types auto-generate):\n```dart\n// dart/interop.dart\n@JS('globalThis.dartbridge.myFn') external set _myFn(JSFunction f);\nJSString _myFnImpl(JSString s) =\u003e s.toDart.toUpperCase().toJS;\nvoid main() { _myFn = _myFnImpl.toJS; }\n```\n```typescript\n// auto-generated dist/interop.d.ts\nexport interface DartBridge { myFn: (s: string) =\u003e string; }\n\n// usage — full IntelliSense, no casting\ndartbridge.myFn(\"hello\"); // \"HELLO\"\n```\n\n## 🏗️ How It Works\n\n1. **Write Dart** — use the full Dart SDK and packages (`dart:js_interop`, no 3rd-party deps)\n2. **Compile** — `dart2js -O4 --minify` produces an optimized JS bundle in `dist/`\n3. **Auto-type** — a type generator reads Dart signatures and emits `dist/interop.d.ts`\n4. **Load anywhere** — `shared/dartloader.ts` auto-detects browser vs Node.js and returns the typed bridge\n\n```\ndist/\n├── interop.js      # Production (188 KB minified)\n├── interop.dev.js  # Dev build with assertions\n├── interop.d.ts    # Auto-generated TypeScript definitions\n└── *.map           # Source maps\n```\n\n## 📁 Structure\n\n```\nDartInJS/\n├── dart/           # Dart source (interop.dart, quick.dart, httpin.dart)\n├── shared/         # dartloader.ts — universal typed loader (browser + Node.js)\n├── js-runtime/     # Node.js/Bun examples (example.mjs, example.ts)\n├── dartonbrowser/  # React + Vite browser example\n├── dist/           # Compiled output (auto-generated)\n└── scripts/        # Cross-platform build scripts\n```\n\n## 🛠️ Commands\n\n| Command | Description |\n|---------|-------------|\n| `npm run build` | Compile Dart + generate TypeScript types |\n| `npm run watch` | Auto-recompile on changes |\n| `npm run clean` | Remove build artifacts |\n| `npm test` | Run test suite |\n| `npm run dev:browser` | Browser dev server |\n| `npm run build:browser` | Production browser build |\n| `npm run generate-types` | Regenerate types only |\n\n## 🎓 Learn More\n\n- **[Dart JS Interop](https://dart.dev/web/js-interop)** — Official docs for native Dart-JavaScript interop\n- **[dart2js](https://dart.dev/tools/dart2js)** — Compiler reference and optimization flags (-O4, --minify)\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryquan%2Fdartinjs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhenryquan%2Fdartinjs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhenryquan%2Fdartinjs/lists"}