@tsonic/js 10.0.12 → 10.0.16
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 +50 -40
- package/package.json +3 -3
- package/tsonic.bindings.json +8 -0
package/README.md
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
# @tsonic/js
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
JavaScript-style APIs for **Tsonic** (TypeScript → .NET).
|
|
4
|
+
|
|
5
|
+
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`.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
### New project
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
mkdir my-app && cd my-app
|
|
13
|
+
tsonic init
|
|
14
|
+
tsonic add npm @tsonic/js
|
|
15
|
+
npm run dev
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Existing project
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
tsonic add npm @tsonic/js
|
|
22
|
+
```
|
|
4
23
|
|
|
5
24
|
## Versioning
|
|
6
25
|
|
|
@@ -10,46 +29,43 @@ This repo is versioned by **.NET major**:
|
|
|
10
29
|
|
|
11
30
|
When publishing, run: `npm publish versions/10 --access public`
|
|
12
31
|
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
- **JavaScript-like APIs for .NET** - Array, Map, Set, Date, Math, JSON, and more
|
|
16
|
-
- **Global functions** - `parseInt`, `parseFloat`, `encodeURI`, etc. as top-level exports
|
|
17
|
-
- **camelCase members** - TypeScript-friendly naming conventions
|
|
18
|
-
- **Primitive aliases** - `int`, `long`, etc. via `@tsonic/core`
|
|
19
|
-
- **Full type safety** - Complete TypeScript declarations
|
|
32
|
+
## Core APIs (what you get)
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
34
|
+
- `console` (JS-style console)
|
|
35
|
+
- `JSON` (`parse` / `stringify`)
|
|
36
|
+
- `Map`, `Set`, `WeakMap`, `WeakSet`
|
|
37
|
+
- `Date`, `Math`, `RegExp`, `Number`, `String`
|
|
38
|
+
- Timers via `Timers.setTimeout` / `Timers.setInterval`
|
|
39
|
+
- JS-style `Array` via `JSArray<T>`
|
|
40
|
+
- Common globals (e.g. `parseInt`, `parseFloat`, `encodeURI`, …)
|
|
26
41
|
|
|
27
42
|
## Usage
|
|
28
43
|
|
|
29
|
-
###
|
|
44
|
+
### `console` + JSON
|
|
30
45
|
|
|
31
46
|
```typescript
|
|
32
|
-
import {
|
|
47
|
+
import { console, JSON } from "@tsonic/js/index.js";
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
|
|
49
|
+
export function main(): void {
|
|
50
|
+
const value = JSON.parse<{ x: number }>('{"x": 1}');
|
|
51
|
+
console.log(JSON.stringify(value));
|
|
52
|
+
}
|
|
37
53
|
```
|
|
38
54
|
|
|
39
|
-
###
|
|
55
|
+
### Timers
|
|
40
56
|
|
|
41
57
|
```typescript
|
|
42
|
-
import {
|
|
58
|
+
import { Timers, console } from "@tsonic/js/index.js";
|
|
43
59
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
60
|
+
export function main(): void {
|
|
61
|
+
Timers.setTimeout(() => console.log("later"), 250);
|
|
62
|
+
}
|
|
47
63
|
```
|
|
48
64
|
|
|
49
|
-
### Map
|
|
65
|
+
### Collections (`Map` / `Set`)
|
|
50
66
|
|
|
51
67
|
```typescript
|
|
52
|
-
import { Map, Set } from "@tsonic/js";
|
|
68
|
+
import { Map, Set } from "@tsonic/js/index.js";
|
|
53
69
|
|
|
54
70
|
const map = new Map<string, number>();
|
|
55
71
|
map.set("key", 42);
|
|
@@ -58,30 +74,24 @@ const set = new Set<string>();
|
|
|
58
74
|
set.add("value");
|
|
59
75
|
```
|
|
60
76
|
|
|
61
|
-
###
|
|
77
|
+
### JSArray
|
|
62
78
|
|
|
63
79
|
```typescript
|
|
64
|
-
import {
|
|
80
|
+
import { JSArray } from "@tsonic/js/index.js";
|
|
65
81
|
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const
|
|
82
|
+
const arr = new JSArray<number>();
|
|
83
|
+
arr.push(1, 2, 3);
|
|
84
|
+
const mapped = arr.map((x) => x * 2);
|
|
85
|
+
void mapped;
|
|
69
86
|
```
|
|
70
87
|
|
|
71
|
-
|
|
88
|
+
## Relationship to `@tsonic/nodejs`
|
|
72
89
|
|
|
73
|
-
|
|
74
|
-
import { JSON } from "@tsonic/js";
|
|
75
|
-
|
|
76
|
-
const obj = JSON.parse('{"key": "value"}');
|
|
77
|
-
const str = JSON.stringify(obj);
|
|
78
|
-
```
|
|
90
|
+
If you want Node-style modules (`fs`, `path`, `crypto`, `http`, …), use `@tsonic/nodejs`.
|
|
79
91
|
|
|
80
92
|
## Naming Conventions
|
|
81
93
|
|
|
82
|
-
- **
|
|
83
|
-
- **Members**: camelCase (TypeScript convention)
|
|
84
|
-
- **Global functions**: camelCase (JavaScript convention)
|
|
94
|
+
- `@tsonic/js` intentionally uses **JavaScript-style naming** (camelCase members).
|
|
85
95
|
|
|
86
96
|
## Development
|
|
87
97
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsonic/js",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.16",
|
|
4
4
|
"description": "TypeScript type definitions for JavaScript Runtime (JSRuntime) library",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"url": "https://github.com/tsoniclang/js.git"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@tsonic/dotnet": "10.0.
|
|
24
|
-
"@tsonic/core": "10.0.
|
|
23
|
+
"@tsonic/dotnet": "10.0.16",
|
|
24
|
+
"@tsonic/core": "10.0.16"
|
|
25
25
|
}
|
|
26
26
|
}
|