JavaScript-style APIs for Tsonic.
This package is part of Tsonic: https://tsonic.org.
Use @tsonic/js when you want a JS-like standard library (console, JSON, Map, Set, Date, timers, etc.) while still compiling to a native binary with tsonic.
- Install the .NET 10 SDK (required by Tsonic): https://dotnet.microsoft.com/download
- Verify:
dotnet --version
mkdir my-app && cd my-app
npx --yes tsonic@latest init
npx --yes tsonic@latest add npm @tsonic/js
# Replace the default App.ts with a JSRuntime example
cat > packages/my-app/src/App.ts <<'EOF'
import { console, JSON } from "@tsonic/js/index.js";
export function main(): void {
const value = JSON.parse<{ x: number }>('{"x": 1}');
console.log(JSON.stringify(value));
}
EOF
npm run devnpx --yes tsonic@latest add npm @tsonic/jsThis repo is versioned by runtime major:
10→versions/10/→ npm:@tsonic/js@10.x
When publishing, run: npm publish versions/10 --access public
console(JS-style console)JSON(parse/stringify)Map,Set,WeakMap,WeakSetDate,Math,RegExp,Number,String- Timers via
Timers.setTimeout/Timers.setInterval - JS-style
ArrayviaJSArray<T> - Common globals (e.g.
parseInt,parseFloat,encodeURI, …)
import { console, JSON } from "@tsonic/js/index.js";
export function main(): void {
const value = JSON.parse<{ x: number }>('{"x": 1}');
console.log(JSON.stringify(value));
}import { Timers, console } from "@tsonic/js/index.js";
export function main(): void {
Timers.setTimeout(() => console.log("later"), 250);
}import { Map, Set } from "@tsonic/js/index.js";
const map = new Map<string, number>();
map.set("key", 42);
const set = new Set<string>();
set.add("value");import { JSArray } from "@tsonic/js/index.js";
const arr = new JSArray<number>();
arr.push(1, 2, 3);
const mapped = arr.map((x) => x * 2);
void mapped;If you want Node-style modules (fs, path, crypto, http, …), use @tsonic/nodejs.
@tsonic/jsintentionally uses JavaScript-style naming (camelCase members).
See __build/ for regeneration scripts.
MIT