Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Tool for generating JavaScript module of a function from a Dart build.
dartscript
Simple CLI utility for creacting a JavaScript module of a Dart function.
You need to have the Dart SDK installed.
You need to wrap the function you want converted with allowInterop
from the dart:js
library within main()
. 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:
dependencies:
js: ^0.7.1
Given a file with a Dart function (that possibly calls another function)
file.dart
import 'package:js/js.dart';
@JS('greeting')
String greeting(String name) => '$name, hello from Dart!';
@JS('say')
String say(String from, String msg, [bool? greet]) {
var result = '$from says $msg';
if (greet != null && greet) {
result = greeting('Welcome');
}
return result;
}
void main() {
allowInterop(say);
}
Pass it to dartscript
providing the function name to convert to a JS module
dartscript --func say --out say.js file.dart
say.js
export function say(from, msg, greet) {
var result = from + ' says ' + msg
return greet === true ? 'Welcome, hello from Dart!' : result
}
You pass the name of the input Dart file as a positional.
--func
The name of the function from the Dart build to extract (required)--out
The name of the build file for dartscript
to produce (defaults to func.js
)--module
The module system type, es | cjs
(defaults to es
)--default
Whether to export the function using a default export for the module system (defaults to false
)You can run dartscript --help
:
Usage: dartscript [options] <path-to-file.dart>
Options:
--func, -f [string] The name of the dart function to extract into a module. Required.
--out, -o [path] Where to save the output file. Defaults to func.js.
--module, -m What module system to use. Defaults to es. [es | cjs].
--default, -d Whether to use a default export. Defaults to named export.
--help, -h Print this message.
FAQs
Tool for generating JavaScript module of a function from a Dart build.
The npm package dartscript receives a total of 3 weekly downloads. As such, dartscript popularity was classified as not popular.
We found that dartscript demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.