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 +0 -0
- package/README.md +9 -5
- package/as-pect.asconfig.json +23 -23
- package/as-pect.config.js +0 -0
- package/asconfig.json +1 -16
- package/assembly/__benches__/as-tral.d.ts +0 -0
- package/assembly/__benches__/benchmark.ts +33 -28
- package/assembly/__tests__/as-json.spec.ts +0 -0
- package/assembly/__tests__/as-pect.d.ts +0 -0
- package/assembly/chars.ts +2 -1
- package/assembly/index.ts +297 -156
- package/assembly/test.ts +64 -54
- package/assembly/tsconfig.json +0 -0
- package/assembly/util.ts +30 -21
- package/index.ts +0 -1
- package/package.json +4 -3
- package/tests/index.js +0 -0
- package/tests/test.js +0 -0
- package/transform/lib/index.js +74 -73
- package/transform/package.json +1 -2
- package/transform/src/index.old.js +0 -0
- package/transform/src/index.ts +109 -95
- package/transform/tsconfig.json +0 -0
- package/assembly/__tests__/example.spec.ts +0 -40
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
|
-
//
|
|
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
|
|
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
|
package/as-pect.asconfig.json
CHANGED
|
@@ -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":
|
|
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("
|
|
22
|
-
blackbox(JSON.
|
|
26
|
+
bench("Parse Boolean", () => {
|
|
27
|
+
blackbox(JSON.parse<boolean>(blackbox("true")));
|
|
23
28
|
});
|
|
24
29
|
|
|
25
|
-
bench("Stringify
|
|
26
|
-
blackbox(JSON.stringify(blackbox(
|
|
30
|
+
bench("Stringify Integer", () => {
|
|
31
|
+
blackbox(JSON.stringify(blackbox(314)));
|
|
27
32
|
});
|
|
28
33
|
|
|
29
|
-
bench("
|
|
30
|
-
blackbox(JSON.
|
|
34
|
+
bench("Parse Integer", () => {
|
|
35
|
+
blackbox(JSON.parse<i32>(blackbox("314")));
|
|
31
36
|
});
|
|
32
37
|
|
|
33
|
-
bench("Stringify
|
|
34
|
-
blackbox(JSON.stringify(blackbox(
|
|
38
|
+
bench("Stringify Float", () => {
|
|
39
|
+
blackbox(JSON.stringify(blackbox(3.14)));
|
|
35
40
|
});
|
|
36
41
|
|
|
37
|
-
bench("Parse
|
|
38
|
-
blackbox(JSON.parse<
|
|
42
|
+
bench("Parse Float", () => {
|
|
43
|
+
blackbox(JSON.parse<f32>(blackbox("3.14")));
|
|
39
44
|
});
|
|
40
45
|
|
|
41
|
-
bench("
|
|
42
|
-
blackbox(JSON.
|
|
46
|
+
bench("Stringify Object (Vec2)", () => {
|
|
47
|
+
blackbox(JSON.stringify(vec));
|
|
43
48
|
});
|
|
44
49
|
|
|
45
|
-
bench("Parse
|
|
46
|
-
blackbox(
|
|
50
|
+
bench("Parse Object (Vec2)", () => {
|
|
51
|
+
blackbox(parseObject<Vec2>(blackbox('{"x":0.0,"y":0.0}')));
|
|
47
52
|
});
|
|
48
53
|
|
|
49
|
-
bench("
|
|
50
|
-
blackbox(JSON.
|
|
54
|
+
bench("Stringify Array", () => {
|
|
55
|
+
blackbox(JSON.stringify(blackbox([1, 2, 3, 4, 5])));
|
|
51
56
|
});
|
|
52
57
|
|
|
53
|
-
bench("Parse
|
|
54
|
-
blackbox(JSON.parse<
|
|
58
|
+
bench("Parse Array", () => {
|
|
59
|
+
blackbox(JSON.parse<i32[]>(blackbox("[1,2,3,4]")));
|
|
55
60
|
});
|
|
56
61
|
|
|
57
|
-
bench("
|
|
62
|
+
bench("Stringify Nested Array", () => {
|
|
58
63
|
blackbox(
|
|
59
|
-
JSON.
|
|
64
|
+
JSON.stringify<string[][]>(
|
|
65
|
+
blackbox([
|
|
66
|
+
["a", "b", "c"],
|
|
67
|
+
["d", "e", "f"],
|
|
68
|
+
])
|
|
69
|
+
)
|
|
60
70
|
);
|
|
61
71
|
});
|
|
62
|
-
|
|
63
|
-
|
|
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 = "
|
|
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);
|