json-as 0.4.4 → 0.4.5

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/LICENSE CHANGED
File without changes
package/README.md CHANGED
@@ -53,6 +53,7 @@ class Player {
53
53
  lastActive: i32[]
54
54
  age: i32
55
55
  pos: Vec2
56
+ isVerified: boolean
56
57
  }
57
58
 
58
59
  const data: Player = {
@@ -63,19 +64,21 @@ const data: Player = {
63
64
  pos: {
64
65
  x: -3.4,
65
66
  y: 1.2
66
- }
67
+ },
68
+ isVerified: true
67
69
  }
68
70
 
69
71
  const stringified = JSON.stringify<Player>(data);
70
72
  // {
71
73
  // "firstName": "Emmet",
72
74
  // "lastName": "West",
73
- // "lastActive": [8, 27, 2022],
75
+ // "lastActive": [8, 27, 2022],
74
76
  // "age": 23,
75
77
  // "pos": {
76
78
  // "x": -3.4000000953674318,
77
79
  // "y": 1.2000000476837159
78
- // }
80
+ // },
81
+ // "isVerified": true
79
82
  // }
80
83
  console.log(`Stringified: ${stringified}`);
81
84
 
@@ -88,7 +91,8 @@ const parsed = JSON.parse<Player>(stringified);
88
91
  // pos: {
89
92
  // x: -3.4000000953674318,
90
93
  // y: 1.2000000476837159
91
- // }
94
+ // },
95
+ // isVerified: true
92
96
  // }
93
97
  console.log(`Parsed: ${JSON.stringify(parsed)}`);
94
98
  ```
@@ -102,7 +106,7 @@ console.log(`Parsed: ${JSON.stringify(parsed)}`);
102
106
  - Does this support nested structures?
103
107
  Yes, as-json supports nested structures
104
108
  - Does this support whitespace?
105
- Yes, as-json supports whitespace although the current implementation is deathly slow
109
+ Yes, as-json supports whitespace!
106
110
  - How fast is it?
107
111
  Really fast. For example, here are some benchmarks for ser/de a Vec2 with as-json
108
112
  ## Issues
@@ -1,24 +1,24 @@
1
- {
2
- "targets": {
3
- "coverage": {
4
- "lib": ["./node_modules/@as-covers/assembly/index.ts"],
5
- "transform": ["@as-covers/transform", "@as-pect/transform"]
6
- },
7
- "noCoverage": {
8
- "transform": ["@as-pect/transform"]
9
- }
10
- },
11
- "options": {
12
- "exportMemory": true,
13
- "outFile": "output.wasm",
14
- "textFile": "output.wat",
15
- "bindings": "raw",
16
- "exportStart": "_start",
17
- "exportRuntime": true,
18
- "use": ["RTRACE=1"],
19
- "debug": true,
20
- "exportTable": true
21
- },
22
- "extends": "./asconfig.json",
23
- "entries": ["./@as-pect/assembly/assembly/index.ts"]
1
+ {
2
+ "targets": {
3
+ "coverage": {
4
+ "lib": ["./node_modules/@as-covers/assembly/index.ts"],
5
+ "transform": ["@as-covers/transform", "@as-pect/transform"]
6
+ },
7
+ "noCoverage": {
8
+ "transform": ["@as-pect/transform"]
9
+ }
10
+ },
11
+ "options": {
12
+ "exportMemory": true,
13
+ "outFile": "output.wasm",
14
+ "textFile": "output.wat",
15
+ "bindings": "raw",
16
+ "exportStart": "_start",
17
+ "exportRuntime": true,
18
+ "use": ["RTRACE=1"],
19
+ "debug": true,
20
+ "exportTable": true
21
+ },
22
+ "extends": "./asconfig.json",
23
+ "entries": ["./@as-pect/assembly/assembly/index.ts"]
24
24
  }
package/as-pect.config.js CHANGED
File without changes
package/asconfig.json CHANGED
@@ -1,23 +1,8 @@
1
1
  {
2
2
  "targets": {
3
- "debug": {
4
- "outFile": "build/debug.wasm",
5
- "textFile": "build/debug.wat",
6
- "sourceMap": true,
7
- "debug": true
8
- },
9
- "release": {
10
- "outFile": "build/release.wasm",
11
- "textFile": "build/release.wat",
12
- "sourceMap": true,
13
- "optimizeLevel": 3,
14
- "shrinkLevel": 0,
15
- "converge": false,
16
- "noAssert": false
17
- },
18
3
  "test": {
19
4
  "outFile": "build/test.wasm",
20
- "sourceMap": true,
5
+ "sourceMap": false,
21
6
  "optimizeLevel": 0,
22
7
  "shrinkLevel": 0,
23
8
  "converge": false,
File without changes
@@ -1,4 +1,5 @@
1
- import { JSON } from "..";
1
+ import { JSON, parseBooleanArray, parseObject, parseStringArray } from "..";
2
+
2
3
  @json
3
4
  class Vec2 {
4
5
  x: f32;
@@ -14,56 +15,60 @@ bench("Stringify String", () => {
14
15
  blackbox(JSON.stringify(blackbox("Hello")));
15
16
  });
16
17
 
18
+ bench("Parse String", () => {
19
+ blackbox(JSON.parse<string>(blackbox('"Hello"')));
20
+ });
21
+
17
22
  bench("Stringify Boolean", () => {
18
23
  blackbox(JSON.stringify(blackbox(true)));
19
24
  });
20
25
 
21
- bench("Stringify Integer", () => {
22
- blackbox(JSON.stringify(blackbox(314)));
26
+ bench("Parse Boolean", () => {
27
+ blackbox(JSON.parse<boolean>(blackbox("true")));
23
28
  });
24
29
 
25
- bench("Stringify Float", () => {
26
- blackbox(JSON.stringify(blackbox(3.14)));
30
+ bench("Stringify Integer", () => {
31
+ blackbox(JSON.stringify(blackbox(314)));
27
32
  });
28
33
 
29
- bench("Stringify Object (Vec2)", () => {
30
- blackbox(JSON.stringify(vec));
34
+ bench("Parse Integer", () => {
35
+ blackbox(JSON.parse<i32>(blackbox("314")));
31
36
  });
32
37
 
33
- bench("Stringify Array", () => {
34
- blackbox(JSON.stringify(blackbox([1, 2, 3, 4, 5])));
38
+ bench("Stringify Float", () => {
39
+ blackbox(JSON.stringify(blackbox(3.14)));
35
40
  });
36
41
 
37
- bench("Parse String", () => {
38
- blackbox(JSON.parse<string>(blackbox('"Hello"')));
42
+ bench("Parse Float", () => {
43
+ blackbox(JSON.parse<f32>(blackbox("3.14")));
39
44
  });
40
45
 
41
- bench("Parse Boolean", () => {
42
- blackbox(JSON.parse<boolean>(blackbox("true")));
46
+ bench("Stringify Object (Vec2)", () => {
47
+ blackbox(JSON.stringify(vec));
43
48
  });
44
49
 
45
- bench("Parse Integer", () => {
46
- blackbox(JSON.parse<i32>(blackbox("314")));
50
+ bench("Parse Object (Vec2)", () => {
51
+ blackbox(parseObject<Vec2>(blackbox('{"x":0.0,"y":0.0}')));
47
52
  });
48
53
 
49
- bench("Parse Float", () => {
50
- blackbox(JSON.parse<f32>(blackbox("3.14")));
54
+ bench("Stringify Array", () => {
55
+ blackbox(JSON.stringify(blackbox([1, 2, 3, 4, 5])));
51
56
  });
52
57
 
53
- bench("Parse Object (Vec2)", () => {
54
- blackbox(JSON.parse<Vec2>(blackbox('{"x":0.0,"y":0.0}')));
58
+ bench("Parse Array", () => {
59
+ blackbox(JSON.parse<i32[]>(blackbox("[1,2,3,4]")));
55
60
  });
56
61
 
57
- bench("Parse Boolean Array", () => {
62
+ bench("Stringify Nested Array", () => {
58
63
  blackbox(
59
- JSON.parse<boolean[]>(blackbox("[true,false,true,false,true]"))
64
+ JSON.stringify<string[][]>(
65
+ blackbox([
66
+ ["a", "b", "c"],
67
+ ["d", "e", "f"],
68
+ ])
69
+ )
60
70
  );
61
71
  });
62
-
63
- bench("Parse Integer Array", () => {
64
- blackbox(JSON.parse<u32[]>(blackbox("[1,2,3,4,5]")));
65
- });
66
-
67
- bench("Parse Float Array", () => {
68
- blackbox(JSON.parse<f32[]>(blackbox("[1.0,2.0,3.0,4.0,5.0]")));
72
+ bench("Parse Nested Array", () => {
73
+ blackbox(JSON.parse<string[][]>(blackbox('[["a","b","c"],["d","e","f"]]')));
69
74
  });
File without changes
File without changes
package/assembly/chars.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export const commaCode = ",".charCodeAt(0);
2
- export const quoteCode = "\"".charCodeAt(0);
2
+ export const quoteCode = '"'.charCodeAt(0);
3
3
  export const backSlashCode = "\\".charCodeAt(0);
4
+ export const forwardSlashCode = "/".charCodeAt(0);
4
5
  export const leftBraceCode = "{".charCodeAt(0);
5
6
  export const rightBraceCode = "}".charCodeAt(0);
6
7
  export const leftBracketCode = "[".charCodeAt(0);