Skip to content

tsoniclang/js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@tsonic/js

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.

Prerequisites

Quick Start

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 dev

Existing project

npx --yes tsonic@latest add npm @tsonic/js

Versioning

This repo is versioned by runtime major:

  • 10versions/10/ → npm: @tsonic/js@10.x

When publishing, run: npm publish versions/10 --access public

Core APIs (what you get)

  • console (JS-style console)
  • JSON (parse / stringify)
  • Map, Set, WeakMap, WeakSet
  • Date, Math, RegExp, Number, String
  • Timers via Timers.setTimeout / Timers.setInterval
  • JS-style Array via JSArray<T>
  • Common globals (e.g. parseInt, parseFloat, encodeURI, …)

Usage

console + JSON

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));
}

Timers

import { Timers, console } from "@tsonic/js/index.js";

export function main(): void {
  Timers.setTimeout(() => console.log("later"), 250);
}

Collections (Map / Set)

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");

JSArray

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;

Relationship to @tsonic/nodejs

If you want Node-style modules (fs, path, crypto, http, …), use @tsonic/nodejs.

Naming Conventions

  • @tsonic/js intentionally uses JavaScript-style naming (camelCase members).

Development

See __build/ for regeneration scripts.

License

MIT

About

d.ts files for the js runtime

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages