json-as 0.4.2 → 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,18 +64,51 @@ 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
- // '{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23}'
72
+ // {
73
+ // "firstName": "Emmet",
74
+ // "lastName": "West",
75
+ // "lastActive": [8, 27, 2022],
76
+ // "age": 23,
77
+ // "pos": {
78
+ // "x": -3.4000000953674318,
79
+ // "y": 1.2000000476837159
80
+ // },
81
+ // "isVerified": true
82
+ // }
71
83
  console.log(`Stringified: ${stringified}`);
72
84
 
73
- const parsed = JSON.parse<Player>(stringified)
74
- // { firstName: "Emmet", lastName: "West", "lastActive": [8,27,2022], age: 23 }
75
- console.log(`Parsed: ${JSON.stringify(parsed)}`)
85
+ const parsed = JSON.parse<Player>(stringified);
86
+ // Player {
87
+ // firstName: "Emmet",
88
+ // lastName: "West",
89
+ // lastActive: [8, 27, 2022],
90
+ // age: 23,
91
+ // pos: {
92
+ // x: -3.4000000953674318,
93
+ // y: 1.2000000476837159
94
+ // },
95
+ // isVerified: true
96
+ // }
97
+ console.log(`Parsed: ${JSON.stringify(parsed)}`);
76
98
  ```
77
99
 
100
+ ## FAQ
101
+
102
+ - Does it support the full JSON spec?
103
+ Yes, as-json supports the full JSON specification and trys to mimic the JSON API as much as possible
104
+ - What are the differences between as-json and the JSON API?
105
+ The main difference between as-json and the JSON API is the ability to create new fields in objects during runtime. Since classes are static, Map ser/de support will be added soon allowing the user to parse and stringify dynamic objects and their properties
106
+ - Does this support nested structures?
107
+ Yes, as-json supports nested structures
108
+ - Does this support whitespace?
109
+ Yes, as-json supports whitespace!
110
+ - How fast is it?
111
+ Really fast. For example, here are some benchmarks for ser/de a Vec2 with as-json
78
112
  ## Issues
79
113
 
80
114
  Please submit an issue to https://github.com/JairusSW/as-json/issues if you find anything wrong with this library
@@ -0,0 +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"]
24
+ }
@@ -0,0 +1,30 @@
1
+ export default {
2
+ /**
3
+ * A set of globs passed to the glob package that qualify typescript files for testing.
4
+ */
5
+ entries: ["assembly/__tests__/**/*.spec.ts"],
6
+ /**
7
+ * A set of globs passed to the glob package that quality files to be added to each test.
8
+ */
9
+ include: ["assembly/__tests__/**/*.include.ts"],
10
+ /**
11
+ * A set of regexp that will disclude source files from testing.
12
+ */
13
+ disclude: [/node_modules/],
14
+ /**
15
+ * Add your required AssemblyScript imports here.
16
+ */
17
+ async instantiate(memory, createImports, instantiate, binary) {
18
+ let instance; // Imports can reference this
19
+ const myImports = {
20
+ // put your web assembly imports here, and return the module
21
+ };
22
+ return instantiate(binary, createImports(myImports));
23
+ },
24
+ /** Enable code coverage. */
25
+ // coverage: ["assembly/**/*.ts"],
26
+ /**
27
+ * Specify if the binary wasm file should be written to the file system.
28
+ */
29
+ outputBinary: false,
30
+ };
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,11 +1,12 @@
1
- import { JSON, parseBooleanArray, parseMap, parseNumberArray } from "..";
1
+ import { JSON, parseBooleanArray, parseObject, parseStringArray } from "..";
2
+
2
3
  @json
3
- class Vector {
4
+ class Vec2 {
4
5
  x: f32;
5
6
  y: f32;
6
7
  }
7
8
 
8
- const vec: Vector = blackbox<Vector>({
9
+ const vec: Vec2 = blackbox<Vec2>({
9
10
  x: 0.0,
10
11
  y: 0.0,
11
12
  });
@@ -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 Vector", () => {
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 Vector", () => {
54
- blackbox(parseMap<Map<string, f32>>(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
- parseBooleanArray<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(parseNumberArray<u32[]>(blackbox("[1,2,3,4,5]")));
65
- });
66
-
67
- bench("Parse Float Array", () => {
68
- blackbox(parseNumberArray<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
@@ -0,0 +1 @@
1
+ /// <reference types="@as-pect/assembly/types/as-pect" />
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);