json-as 0.8.1 → 0.8.2

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/CHANGELOG ADDED
@@ -0,0 +1 @@
1
+ v0.8.2 - Properties starting with `static` or `private` would be ignored
package/README.md CHANGED
@@ -1,4 +1,15 @@
1
- <h1>JSON</h1>
1
+ <h3 align="center">
2
+ <pre>
3
+ █████╗ ███████╗ ██╗███████╗ ██████╗ ███╗ ██╗
4
+ ██╔══██╗██╔════╝ ██║██╔════╝██╔═══██╗████╗ ██║
5
+ ███████║███████╗█████╗ ██║███████╗██║ ██║██╔██╗ ██║
6
+ ██╔══██║╚════██║╚════╝██ ██║╚════██║██║ ██║██║╚██╗██║
7
+ ██║ ██║███████║ ╚█████╔╝███████║╚██████╔╝██║ ╚████║
8
+ ╚═╝ ╚═╝╚══════╝ ╚════╝ ╚══════╝ ╚═════╝ ╚═╝ ╚═══╝
9
+
10
+ v0.8.2
11
+ </pre>
12
+ </h3>
2
13
 
3
14
  ## Installation
4
15
 
@@ -31,9 +42,9 @@ import { JSON } from "json-as/assembly";
31
42
  // @json or @serializable work here
32
43
  @json
33
44
  class Vec3 {
34
- x!: f32;
35
- y!: f32;
36
- z!: f32;
45
+ x: f32 = 0.0;
46
+ y: f32 = 0.0;
47
+ z: f32 = 0.0;
37
48
  }
38
49
 
39
50
  @json
@@ -68,57 +79,6 @@ const parsed = JSON.parse<Player>(stringified);
68
79
  ```
69
80
 
70
81
  If you use this project in your codebase, consider dropping a [star](https://github.com/JairusSW/as-json). I would really appreciate it!
71
- ## Performance
72
-
73
- Run or view the benchmarks [here](https://github.com/JairusSW/as-json/tree/master/bench)
74
-
75
- Below are benchmark results comparing JavaScript, WAVM (WebAssembly Virtual Machine), and Wasmtime environments.
76
-
77
- JavaScript Results
78
-
79
- NodeJS v20.5.1 - TinyBench v2.5.0 (V8)
80
- ```
81
- ┌───────────────────────────┬───────────────┐
82
- │ Task Name │ ops / sec │
83
- ├───────────────────────────┼───────────────┤
84
- │ 'Stringify Object (Vec3)' │ '1,191,221' │
85
- │ 'Parse Object (Vec3)' │ '897,759' │
86
- │ 'Stringify Number Array' │ '1,552,255' │
87
- │ 'Parse Number Array' │ '1,225,325' │
88
- │ 'Stringify String' │ '1,761,011' │
89
- │ 'Parse String' │ '80,845' │
90
- └───────────────────────────┴───────────────┘
91
- ```
92
-
93
- AssemblyScript Results
94
-
95
- WAVM v0.0.0-prerelease - as-bench v0.0.0-alpha (LLVM)
96
- ```
97
- ┌───────────────────────────┬───────────────┐
98
- │ Task Name │ ops / sec │
99
- ├───────────────────────────┼───────────────┤
100
- │ 'Stringify Object (Vec3)' │ '6,270,322' │
101
- │ 'Parse Object (Vec3)' │ '8,000,195' |
102
- │ 'Stringify Number Array' │ '6,664,937' │
103
- │ 'Parse Number Array' │ '6,557,357' │
104
- │ 'Stringify String' │ '6,946,947' │
105
- │ 'Parse String' │ '10,952,502' │
106
- └───────────────────────────┴───────────────┘
107
- ```
108
-
109
- Wasmtime v11.0.1 - as-bench v0.0.0-alpha (Cranelift)
110
- ```
111
- ┌───────────────────────────┬───────────────┐
112
- │ Task Name │ ops / sec │
113
- ├───────────────────────────┼───────────────┤
114
- │ 'Stringify Object (Vec3)' │ '2,038,684' │
115
- │ 'Parse Object (Vec3)' │ '4,623,337' |
116
- │ 'Stringify Number Array' │ '2,500,947' │
117
- │ 'Parse Number Array' │ '2,959,180' │
118
- │ 'Stringify String' │ '3,236,896' │
119
- │ 'Parse String' │ '5,634,594' │
120
- └───────────────────────────┴───────────────┘
121
- ```
122
82
 
123
83
  ## Issues
124
84
 
package/assembly/test.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import { JSON } from "./src/json";
2
2
  @json
3
3
  class Person {
4
- private prng: i32 = 23;
4
+ staticprng: i32 = 23;
5
5
  public country: string = '';
6
6
 
7
7
  constructor(id: u32) {
8
- this.prng = 321;
8
+ this.staticprng = 321;
9
9
  const seed = id.toString();
10
10
  this.country = this.getCountry();
11
11
  }
@@ -17,5 +17,7 @@ class Person {
17
17
  }
18
18
 
19
19
  const person = new Person(1);
20
+ person.staticprng = 32
20
21
  let result = JSON.stringify<Person>(person);
22
+ console.log(JSON.stringify(JSON.parse<Person>(result)));
21
23
  console.log(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-as",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -71,7 +71,7 @@ class AsJSONTransform extends BaseVisitor {
71
71
  const member = mem;
72
72
  const lineText = toString(member);
73
73
  //console.log("Member: " + lineText)
74
- if (!lineText.startsWith("private") && !lineText.startsWith("static")) {
74
+ if (!lineText.startsWith("private ") && !lineText.startsWith("static ")) {
75
75
  // @ts-ignore
76
76
  let type = toString(member.type);
77
77
  const name = member.name.text;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@json-as/transform",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
@@ -86,7 +86,7 @@ class AsJSONTransform extends BaseVisitor {
86
86
  const lineText = toString(member);
87
87
  //console.log("Member: " + lineText)
88
88
 
89
- if (!lineText.startsWith("private") && !lineText.startsWith("static")) {
89
+ if (!lineText.startsWith("private ") && !lineText.startsWith("static ")) {
90
90
 
91
91
  // @ts-ignore
92
92
  let type = toString(member.type);