{"id":22808910,"url":"https://github.com/morganney/dartscript","last_synced_at":"2025-06-22T11:09:19.025Z","repository":{"id":241234378,"uuid":"804671989","full_name":"morganney/dartscript","owner":"morganney","description":"Creates a JavaScript module from a Dart function.","archived":false,"fork":false,"pushed_at":"2024-06-05T13:52:32.000Z","size":113,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-06T17:49:38.380Z","etag":null,"topics":["commonjs","dart","esmodule","function","javascript"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/morganney.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":"2024-05-23T03:31:40.000Z","updated_at":"2024-05-30T01:34:30.000Z","dependencies_parsed_at":"2024-05-23T05:04:49.057Z","dependency_job_id":null,"html_url":"https://github.com/morganney/dartscript","commit_stats":null,"previous_names":["morganney/dartscript"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/morganney/dartscript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morganney%2Fdartscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morganney%2Fdartscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morganney%2Fdartscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morganney%2Fdartscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/morganney","download_url":"https://codeload.github.com/morganney/dartscript/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/morganney%2Fdartscript/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261282319,"owners_count":23134940,"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":["commonjs","dart","esmodule","function","javascript"],"created_at":"2024-12-12T11:12:46.872Z","updated_at":"2025-06-22T11:09:14.014Z","avatar_url":"https://github.com/morganney.png","language":"JavaScript","readme":"## [`dartscript`](https://www.npmjs.com/package/dartscript)\n\n![CI](https://github.com/morganney/dartscript/actions/workflows/ci.yml/badge.svg)\n[![NPM version](https://img.shields.io/npm/v/dartscript.svg)](https://www.npmjs.com/package/dartscript)\n\nSimple CLI utility for creacting a JavaScript module of a [Dart function](https://dart.dev/language/functions).\n\n## Requirements\n\nYou need to have the [Dart SDK installed](https://dart.dev/get-dart#choose-an-installation-option).\n\nYou need to wrap the function you want converted with [`allowInterop`](https://pub.dev/packages/js#making-a-dart-function-callable-from-javascript) from the [`dart:js`](https://api.dart.dev/stable/3.4.1/dart-js/dart-js-library.html) library within [`main()`](https://dart.dev/language/functions#the-main-function). This implies you need to `import package:js/js.dart` from the dart file passed to `dartscript`, and so will need to list it within your `pubspec.yaml` file:\n\n```yaml\ndependencies:\n  js: ^0.7.1\n```\n\n## Example\n\nGiven a file with a Dart function (that possibly calls another function)\n\n**file.dart**\n\n```dart\nimport 'package:js/js.dart';\n\n@JS('greeting')\nString greeting(String name) =\u003e '$name, hello from Dart!';\n\n@JS('say')\nString say(String from, String msg, [bool? greet]) {\n  var result = '$from says $msg';\n\n  if (greet != null \u0026\u0026 greet) {\n    result = greeting('Welcome');\n  }\n\n  return result;\n}\n\nvoid main() {\n  allowInterop(say);\n}\n```\n\nPass it to `dartscript` providing the function name to convert to a JS module\n\n```\ndartscript --func say --out say.js file.dart\n```\n\n**say.js**\n\n```js\nexport function say(from, msg, greet) {\n  var result = from + ' says ' + msg\n  return greet === true ? 'Welcome, hello from Dart!' : result\n}\n```\n\n## Options\n\nYou pass the name of the input Dart file as a positional.\n\n- `--func` The name of the function from the Dart build to extract (required)\n- `--out` The name of the build file for `dartscript` to produce (defaults to `func.js`)\n- `--module` The module system type, `es | cjs` (defaults to `es`)\n- `--default` Whether to export the function using a default export for the module system (defaults to `false`)\n\nYou can run `dartscript --help`:\n\n```console\nUsage: dartscript [options] \u003cpath-to-file.dart\u003e\n\nOptions:\n--func, -f [string] \t The name of the dart function to extract into a module. Required.\n--out, -o [path] \t Where to save the output file. Defaults to func.js.\n--module, -m \t\t What module system to use. Defaults to es. [es | cjs].\n--default, -d \t\t Whether to use a default export. Defaults to named export.\n--help, -h \t\t Print this message.\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorganney%2Fdartscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmorganney%2Fdartscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmorganney%2Fdartscript/lists"}