@tsonic/js 10.0.37 → 10.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,33 +1,34 @@
1
1
  # @tsonic/js
2
2
 
3
- JavaScript-style APIs for **Tsonic**.
3
+ JavaScript runtime bindings for **Tsonic**.
4
4
 
5
5
  This package is part of Tsonic: https://tsonic.org.
6
6
 
7
- 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`.
7
+ `@tsonic/js` provides JS runtime APIs (`JSON`, `console`, `Map`, `Set`, `Date`, timers, etc.) for Tsonic projects.
8
8
 
9
9
  ## Prerequisites
10
10
 
11
- - Install the .NET 10 SDK (required by Tsonic): https://dotnet.microsoft.com/download
11
+ - Install the .NET 10 SDK: https://dotnet.microsoft.com/download
12
12
  - Verify: `dotnet --version`
13
13
 
14
- ## Quick Start
14
+ ## Quick Start (surface-first, no `@tsonic/js` imports required)
15
15
 
16
16
  ```bash
17
17
  mkdir my-app && cd my-app
18
- npx --yes tsonic@latest init
18
+ npx --yes tsonic@latest init --surface js
19
19
  npx --yes tsonic@latest add npm @tsonic/js
20
+ ```
20
21
 
21
- # Replace the default App.ts with a JSRuntime example
22
- cat > packages/my-app/src/App.ts <<'EOF'
23
- import { console, JSON } from "@tsonic/js/index.js";
24
-
22
+ ```ts
25
23
  export function main(): void {
26
24
  const value = JSON.parse<{ x: number }>('{"x": 1}');
27
25
  console.log(JSON.stringify(value));
28
26
  }
29
- EOF
27
+ ```
30
28
 
29
+ Build/run:
30
+
31
+ ```bash
31
32
  npm run dev
32
33
  ```
33
34
 
@@ -37,81 +38,48 @@ npm run dev
37
38
  npx --yes tsonic@latest add npm @tsonic/js
38
39
  ```
39
40
 
40
- ## Versioning
41
-
42
- This repo is versioned by runtime major:
43
-
44
- - `10` → `versions/10/` → npm: `@tsonic/js@10.x`
45
-
46
- When publishing, run: `npm publish versions/10 --access public`
41
+ If the workspace is not already JS surface, set:
47
42
 
48
- ## Core APIs (what you get)
49
-
50
- - `console` (JS-style console)
51
- - `JSON` (`parse` / `stringify`)
52
- - `Map`, `Set`, `WeakMap`, `WeakSet`
53
- - `Date`, `Math`, `RegExp`, `Number`, `String`
54
- - Timers via `Timers.setTimeout` / `Timers.setInterval`
55
- - JS-style `Array` via `JSArray<T>`
56
- - Common globals (e.g. `parseInt`, `parseFloat`, `encodeURI`, …)
57
-
58
- ## Usage
59
-
60
- ### `console` + JSON
61
-
62
- ```typescript
63
- import { console, JSON } from "@tsonic/js/index.js";
64
-
65
- export function main(): void {
66
- const value = JSON.parse<{ x: number }>('{"x": 1}');
67
- console.log(JSON.stringify(value));
68
- }
43
+ ```bash
44
+ npx --yes tsonic@latest init --surface js
69
45
  ```
70
46
 
71
- ### Timers
47
+ ## Optional direct imports
72
48
 
73
- ```typescript
74
- import { Timers, console } from "@tsonic/js/index.js";
49
+ Surface mode enables natural JS authoring, but direct package imports remain supported:
75
50
 
76
- export function main(): void {
77
- Timers.setTimeout(() => console.log("later"), 250);
78
- }
51
+ ```ts
52
+ import { Timers, JSArray } from "@tsonic/js/index.js";
79
53
  ```
80
54
 
81
- ### Collections (`Map` / `Set`)
82
-
83
- ```typescript
84
- import { Map, Set } from "@tsonic/js/index.js";
85
-
86
- const map = new Map<string, number>();
87
- map.set("key", 42);
88
-
89
- const set = new Set<string>();
90
- set.add("value");
91
- ```
55
+ ## Core APIs
92
56
 
93
- ### JSArray
57
+ - `console`
58
+ - `JSON`
59
+ - `Map`, `Set`, `WeakMap`, `WeakSet`
60
+ - `Date`, `Math`, `RegExp`, `Number`, `String`
61
+ - `Timers`
62
+ - `JSArray<T>`
63
+ - globals like `parseInt`, `parseFloat`, `encodeURI`
94
64
 
95
- ```typescript
96
- import { JSArray } from "@tsonic/js/index.js";
65
+ ## Relationship to `@tsonic/nodejs`
97
66
 
98
- const arr = new JSArray<number>();
99
- arr.push(1, 2, 3);
100
- const mapped = arr.map((x) => x * 2);
101
- void mapped;
102
- ```
67
+ - `@tsonic/js` = JS runtime surface
68
+ - `@tsonic/nodejs` = Node-style modules (`node:fs`, `node:path`, `node:crypto`, ...)
103
69
 
104
- ## Relationship to `@tsonic/nodejs`
70
+ ## Versioning
105
71
 
106
- If you want Node-style modules (`fs`, `path`, `crypto`, `http`, …), use `@tsonic/nodejs`.
72
+ - `10` `versions/10/` npm: `@tsonic/js@10.x`
107
73
 
108
- ## Naming Conventions
74
+ Publish:
109
75
 
110
- - `@tsonic/js` intentionally uses **JavaScript-style naming** (camelCase members).
76
+ ```bash
77
+ npm publish versions/10 --access public
78
+ ```
111
79
 
112
80
  ## Development
113
81
 
114
- See `__build/` for regeneration scripts.
82
+ See `__build/`.
115
83
 
116
84
  ## License
117
85
 
package/bindings.json ADDED
@@ -0,0 +1,77 @@
1
+ {
2
+ "bindings": {
3
+ "console": {
4
+ "kind": "global",
5
+ "assembly": "Tsonic.JSRuntime",
6
+ "type": "Tsonic.JSRuntime.console"
7
+ },
8
+ "Date": {
9
+ "kind": "global",
10
+ "assembly": "Tsonic.JSRuntime",
11
+ "type": "Tsonic.JSRuntime.Date"
12
+ },
13
+ "JSON": {
14
+ "kind": "global",
15
+ "assembly": "Tsonic.JSRuntime",
16
+ "type": "Tsonic.JSRuntime.JSON"
17
+ },
18
+ "Math": {
19
+ "kind": "global",
20
+ "assembly": "Tsonic.JSRuntime",
21
+ "type": "Tsonic.JSRuntime.Math"
22
+ },
23
+ "RegExp": {
24
+ "kind": "global",
25
+ "assembly": "Tsonic.JSRuntime",
26
+ "type": "Tsonic.JSRuntime.RegExp"
27
+ },
28
+ "Map": {
29
+ "kind": "global",
30
+ "assembly": "Tsonic.JSRuntime",
31
+ "type": "Tsonic.JSRuntime.Map`2",
32
+ "csharpName": "Map"
33
+ },
34
+ "Set": {
35
+ "kind": "global",
36
+ "assembly": "Tsonic.JSRuntime",
37
+ "type": "Tsonic.JSRuntime.Set`1",
38
+ "csharpName": "Set"
39
+ },
40
+ "Array": {
41
+ "kind": "global",
42
+ "assembly": "Tsonic.JSRuntime",
43
+ "type": "Tsonic.JSRuntime.JSArray`1",
44
+ "csharpName": "JSArray"
45
+ },
46
+ "ReadonlyArray": {
47
+ "kind": "global",
48
+ "assembly": "Tsonic.JSRuntime",
49
+ "type": "Tsonic.JSRuntime.JSArray`1",
50
+ "csharpName": "JSArray"
51
+ },
52
+ "parseInt": {
53
+ "kind": "global",
54
+ "assembly": "Tsonic.JSRuntime",
55
+ "type": "Tsonic.JSRuntime.Globals",
56
+ "csharpName": "Globals.parseInt"
57
+ },
58
+ "parseFloat": {
59
+ "kind": "global",
60
+ "assembly": "Tsonic.JSRuntime",
61
+ "type": "Tsonic.JSRuntime.Globals",
62
+ "csharpName": "Globals.parseFloat"
63
+ },
64
+ "isFinite": {
65
+ "kind": "global",
66
+ "assembly": "Tsonic.JSRuntime",
67
+ "type": "Tsonic.JSRuntime.Globals",
68
+ "csharpName": "Globals.isFinite"
69
+ },
70
+ "isNaN": {
71
+ "kind": "global",
72
+ "assembly": "Tsonic.JSRuntime",
73
+ "type": "Tsonic.JSRuntime.Globals",
74
+ "csharpName": "Globals.isNaN"
75
+ }
76
+ }
77
+ }
package/globals.d.ts ADDED
@@ -0,0 +1,183 @@
1
+ import type { int, long, double } from "@tsonic/core/types.js";
2
+
3
+ declare global {
4
+ interface String {
5
+ readonly length: int;
6
+ trim(): string;
7
+ toUpperCase(): string;
8
+ toLowerCase(): string;
9
+ indexOf(searchString: string, position?: int): int;
10
+ split(separator: string, limit?: int): string[];
11
+ includes(searchString: string, position?: int): boolean;
12
+ startsWith(searchString: string, position?: int): boolean;
13
+ endsWith(searchString: string, endPosition?: int): boolean;
14
+ slice(start?: int, end?: int): string;
15
+ substring(start: int, end?: int): string;
16
+ replace(searchValue: string, replaceValue: string): string;
17
+ charAt(index: int): string;
18
+ charCodeAt(index: int): int;
19
+ }
20
+ interface Array<T> {
21
+ readonly length: int;
22
+ at(index: int): T;
23
+ concat(...items: T[]): T[];
24
+ every(callback: (value: T) => boolean): boolean;
25
+ filter(callback: (value: T) => boolean): T[];
26
+ filter(callback: (value: T, index: int) => boolean): T[];
27
+ find(callback: (value: T) => boolean): T | undefined;
28
+ find(callback: (value: T, index: int) => boolean): T | undefined;
29
+ findIndex(callback: (value: T) => boolean): int;
30
+ findIndex(callback: (value: T, index: int) => boolean): int;
31
+ findLast(callback: (value: T) => boolean): T | undefined;
32
+ findLast(callback: (value: T, index: int) => boolean): T | undefined;
33
+ findLastIndex(callback: (value: T) => boolean): int;
34
+ findLastIndex(callback: (value: T, index: int) => boolean): int;
35
+ flat(depth?: int): unknown[];
36
+ forEach(callback: (value: T) => void): void;
37
+ forEach(callback: (value: T, index: int) => void): void;
38
+ includes(searchElement: T): boolean;
39
+ includes(searchElement: T, fromIndex?: int): boolean;
40
+ indexOf(searchElement: T, fromIndex?: int): int;
41
+ join(separator?: string): string;
42
+ lastIndexOf(searchElement: T, fromIndex?: int): int;
43
+ map<TResult>(callback: (value: T) => TResult): TResult[];
44
+ map<TResult>(callback: (value: T, index: int) => TResult): TResult[];
45
+ reduce(callback: (previousValue: T, currentValue: T) => T): T;
46
+ reduce<TResult>(
47
+ callback: (previousValue: TResult, currentValue: T) => TResult,
48
+ initialValue: TResult
49
+ ): TResult;
50
+ reduceRight<TResult>(
51
+ callback: (previousValue: TResult, currentValue: T) => TResult,
52
+ initialValue: TResult
53
+ ): TResult;
54
+ slice(start?: int, end?: int): T[];
55
+ some(callback: (value: T) => boolean): boolean;
56
+ }
57
+ interface ReadonlyArray<T> {
58
+ readonly length: int;
59
+ at(index: int): T;
60
+ concat(...items: T[]): T[];
61
+ every(callback: (value: T) => boolean): boolean;
62
+ filter(callback: (value: T) => boolean): T[];
63
+ filter(callback: (value: T, index: int) => boolean): T[];
64
+ find(callback: (value: T) => boolean): T | undefined;
65
+ find(callback: (value: T, index: int) => boolean): T | undefined;
66
+ findIndex(callback: (value: T) => boolean): int;
67
+ findIndex(callback: (value: T, index: int) => boolean): int;
68
+ findLast(callback: (value: T) => boolean): T | undefined;
69
+ findLast(callback: (value: T, index: int) => boolean): T | undefined;
70
+ findLastIndex(callback: (value: T) => boolean): int;
71
+ findLastIndex(callback: (value: T, index: int) => boolean): int;
72
+ flat(depth?: int): unknown[];
73
+ forEach(callback: (value: T) => void): void;
74
+ forEach(callback: (value: T, index: int) => void): void;
75
+ includes(searchElement: T): boolean;
76
+ includes(searchElement: T, fromIndex?: int): boolean;
77
+ indexOf(searchElement: T, fromIndex?: int): int;
78
+ join(separator?: string): string;
79
+ lastIndexOf(searchElement: T, fromIndex?: int): int;
80
+ map<TResult>(callback: (value: T) => TResult): TResult[];
81
+ map<TResult>(callback: (value: T, index: int) => TResult): TResult[];
82
+ reduce(callback: (previousValue: T, currentValue: T) => T): T;
83
+ reduce<TResult>(
84
+ callback: (previousValue: TResult, currentValue: T) => TResult,
85
+ initialValue: TResult
86
+ ): TResult;
87
+ reduceRight<TResult>(
88
+ callback: (previousValue: TResult, currentValue: T) => TResult,
89
+ initialValue: TResult
90
+ ): TResult;
91
+ slice(start?: int, end?: int): T[];
92
+ some(callback: (value: T) => boolean): boolean;
93
+ }
94
+ interface Console {
95
+ log(...data: unknown[]): void;
96
+ error(...data: unknown[]): void;
97
+ warn(...data: unknown[]): void;
98
+ info(...data: unknown[]): void;
99
+ debug(...data: unknown[]): void;
100
+ }
101
+ const console: Console;
102
+ interface Date {
103
+ toISOString(): string;
104
+ getTime(): long;
105
+ }
106
+ interface DateConstructor {
107
+ new (): Date;
108
+ new (value: string | number | long): Date;
109
+ now(): long;
110
+ parse(s: string): long;
111
+ }
112
+ const Date: DateConstructor;
113
+ interface JSON {
114
+ parse<T = unknown>(text: string): T;
115
+ stringify(
116
+ value: unknown,
117
+ replacer?: unknown,
118
+ space?: string | number | int
119
+ ): string;
120
+ }
121
+ const JSON: JSON;
122
+ interface Math {
123
+ round(x: double): double;
124
+ max(...values: double[]): double;
125
+ min(...values: double[]): double;
126
+ random(): double;
127
+ }
128
+ const Math: Math;
129
+ interface RegExpMatchArray extends Array<string> {
130
+ index?: int;
131
+ input?: string;
132
+ }
133
+ interface RegExp {
134
+ exec(string: string): RegExpMatchArray | null;
135
+ test(string: string): boolean;
136
+ }
137
+ interface RegExpConstructor {
138
+ new (pattern: string | RegExp, flags?: string): RegExp;
139
+ (pattern: string | RegExp, flags?: string): RegExp;
140
+ }
141
+ const RegExp: RegExpConstructor;
142
+ interface Map<K, V> {
143
+ readonly size: int;
144
+ clear(): void;
145
+ delete(key: K): boolean;
146
+ get(key: K): V | undefined;
147
+ has(key: K): boolean;
148
+ set(key: K, value: V): this;
149
+ }
150
+ interface MapConstructor {
151
+ new <K, V>(entries?: readonly (readonly [K, V])[] | null): Map<K, V>;
152
+ }
153
+ const Map: MapConstructor;
154
+ interface Set<T> {
155
+ readonly size: int;
156
+ add(value: T): this;
157
+ clear(): void;
158
+ delete(value: T): boolean;
159
+ has(value: T): boolean;
160
+ }
161
+ interface SetConstructor {
162
+ new <T = unknown>(values?: readonly T[] | null): Set<T>;
163
+ }
164
+ const Set: SetConstructor;
165
+ function parseInt(str: string, radix?: int): long | undefined;
166
+ function parseFloat(str: string): double;
167
+ function isFinite(value: double): boolean;
168
+ function isNaN(value: double): boolean;
169
+ function setTimeout(
170
+ handler: (...args: unknown[]) => void,
171
+ timeout?: int,
172
+ ...args: unknown[]
173
+ ): int;
174
+ function clearTimeout(id: int): void;
175
+ function setInterval(
176
+ handler: (...args: unknown[]) => void,
177
+ timeout?: int,
178
+ ...args: unknown[]
179
+ ): int;
180
+ function clearInterval(id: int): void;
181
+ }
182
+
183
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsonic/js",
3
- "version": "10.0.37",
3
+ "version": "10.0.39",
4
4
  "description": "TypeScript type definitions for JavaScript Runtime (JSRuntime) library",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -1,4 +1,10 @@
1
1
  {
2
+ "bindingVersion": 1,
3
+ "packageName": "@tsonic/js",
4
+ "surfaceMode": "js",
5
+ "runtimePackages": [
6
+ "@tsonic/js"
7
+ ],
2
8
  "dotnet": {
3
9
  "packageReferences": [
4
10
  { "id": "Tsonic.JSRuntime", "version": "0.0.3", "types": "@tsonic/js" }
@@ -0,0 +1,7 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "id": "@tsonic/js",
4
+ "extends": [],
5
+ "requiredTypeRoots": ["."],
6
+ "useStandardLib": false
7
+ }