json-as 0.5.2 → 0.5.4

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 CHANGED
@@ -65,11 +65,12 @@ const stringified = JSON.stringify<Player>(data);
65
65
  const parsed = JSON.parse<Player>(stringified);
66
66
  ```
67
67
 
68
+
68
69
  ## Performance
69
70
 
70
- **Serialize Object (Vec2):** ~7.29m ops/s
71
+ **Serialize Object (Vec2):** ~7.20m ops/s
71
72
 
72
- **Deserialize Object (Vec2):** ~1.36m ops/s
73
+ **Deserialize Object (Vec2):** ~2.2m ops/s
73
74
 
74
75
  **Serialize Array (int[4]):** ~1.4m ops/s
75
76
 
@@ -72,4 +72,4 @@ bench("Stringify Float", () => {
72
72
 
73
73
  bench("Parse Float", () => {
74
74
  blackbox(JSON.parse<f32>(blackbox("3.14")));
75
- });
75
+ });
@@ -1,109 +1,158 @@
1
- import { JSON } from ".."
1
+ import { JSON } from "..";
2
2
  function canSerde<T>(data: T): void {
3
- const serialized = JSON.stringify<T>(data);
4
- const deserialized = JSON.stringify<T>(JSON.parse<T>(serialized));
5
- expect(serialized).toBe(deserialized);
3
+ const serialized = JSON.stringify<T>(data);
4
+ const deserialized = JSON.stringify<T>(JSON.parse<T>(serialized));
5
+ expect(serialized).toBe(deserialized);
6
6
  }
7
7
 
8
8
  // @ts-ignore
9
9
  @json
10
- class Vec2 {
11
- x: f32;
12
- y: f32;
10
+ class Vec3 {
11
+ x: f32;
12
+ y: f32;
13
+ z: f32;
14
+ }
15
+
16
+ // @ts-ignore
17
+ @json
18
+ class Player {
19
+ firstName: string;
20
+ lastName: string;
21
+ lastActive: i32[];
22
+ age: i32;
23
+ pos: Vec3 | null;
24
+ isVerified: boolean;
13
25
  }
14
26
 
15
27
  class Nullable {}
16
- type Null = Nullable | null
28
+ type Null = Nullable | null;
17
29
 
18
30
  describe("Ser/de Nulls", () => {
19
- canSerde<Null>(null)
20
- })
31
+ canSerde<Null>(null);
32
+ });
21
33
 
22
34
  describe("Ser/de Numbers", () => {
23
- it("should ser/de integers", () => {
24
- canSerde<i32>(0)
25
-
26
- canSerde<u32>(100)
27
- canSerde<u64>(101)
28
- canSerde<i32>(-100)
29
- canSerde<i64>(-101)
30
- });
31
-
32
- it("should ser/de floats", () => {
33
- canSerde<f64>(7.23)
34
- canSerde<f64>(10e2)
35
- canSerde<f64>(10E2)
36
-
37
- canSerde<f64>(123456e-5)
38
-
39
- canSerde<f64>(123456E-5)
40
-
41
- canSerde<f64>(0.0)
42
- canSerde<f64>(7.23)
43
- });
44
-
45
- it("should ser/de booleans", () => {
46
- canSerde<bool>(true)
47
- canSerde<bool>(false)
48
- canSerde<boolean>(true)
49
- canSerde<boolean>(false)
50
- });
51
-
52
- it("should ser/de strings", () => {
53
- canSerde<string>('abcdefg')
54
- canSerde<string>('st"ring" w""ith quotes"')
55
- canSerde<string>('string \t\r\\"with ran\tdom spa\nces and \nnewlines\n\n\n')
56
- canSerde<string>('string with colon : comma , brace [ ] bracket { } and quote " and other quote \\"')
57
- });
58
-
59
- })
35
+ it("should ser/de integers", () => {
36
+ canSerde<i32>(0);
37
+
38
+ canSerde<u32>(100);
39
+ canSerde<u64>(101);
40
+ canSerde<i32>(-100);
41
+ canSerde<i64>(-101);
42
+ });
43
+
44
+ it("should ser/de floats", () => {
45
+ canSerde<f64>(7.23);
46
+ canSerde<f64>(10e2);
47
+ canSerde<f64>(10e2);
48
+
49
+ canSerde<f64>(123456e-5);
50
+
51
+ canSerde<f64>(123456e-5);
52
+
53
+ canSerde<f64>(0.0);
54
+ canSerde<f64>(7.23);
55
+ });
56
+
57
+ it("should ser/de booleans", () => {
58
+ canSerde<bool>(true);
59
+ canSerde<bool>(false);
60
+ canSerde<boolean>(true);
61
+ canSerde<boolean>(false);
62
+ });
63
+
64
+ it("should ser/de strings", () => {
65
+ canSerde<string>("abcdefg");
66
+ canSerde<string>('st"ring" w""ith quotes"');
67
+ canSerde<string>(
68
+ 'string \t\r\\"with ran\tdom spa\nces and \nnewlines\n\n\n'
69
+ );
70
+ canSerde<string>(
71
+ 'string with colon : comma , brace [ ] bracket { } and quote " and other quote \\"'
72
+ );
73
+ });
74
+ });
60
75
 
61
76
  describe("Ser/de Array", () => {
62
- it("should ser/de integer arrays", () => {
63
- canSerde<u32[]>([0, 100, 101])
64
- canSerde<u64[]>([0, 100, 101])
65
-
66
- canSerde<i32[]>([0, 100, 101, -100, -101])
67
- canSerde<i64[]>([0, 100, 101, -100, -101])
68
- });
69
-
70
- it("should ser/de float arrays", () => {
71
- canSerde<f64[]>([7.23, 10e2, 10E2, 123456e-5, 123456E-5, 0.0, 7.23])
72
- })
73
-
74
- it("should ser/de boolean arrays", () => {
75
- canSerde<bool[]>([true, false])
76
- canSerde<boolean[]>([true, false])
77
- })
78
-
79
- it("should ser/de string arrays", () => {
80
- canSerde<string[]>(["abcdefg", "st\"ring\" w\"\"ith quotes\"", "string \t\r\"with ran\tdom spa\nces and \nnewlines\n\n\n", "string with colon : comma , brace [ ] bracket { } and quote \" and other quote \""])
81
- });
77
+ it("should ser/de integer arrays", () => {
78
+ canSerde<u32[]>([0, 100, 101]);
79
+ canSerde<u64[]>([0, 100, 101]);
80
+
81
+ canSerde<i32[]>([0, 100, 101, -100, -101]);
82
+ canSerde<i64[]>([0, 100, 101, -100, -101]);
83
+ });
84
+
85
+ it("should ser/de float arrays", () => {
86
+ canSerde<f64[]>([7.23, 10e2, 10e2, 123456e-5, 123456e-5, 0.0, 7.23]);
87
+ });
88
+
89
+ it("should ser/de boolean arrays", () => {
90
+ canSerde<bool[]>([true, false]);
91
+ canSerde<boolean[]>([true, false]);
92
+ });
93
+
94
+ it("should ser/de string arrays", () => {
95
+ canSerde<string[]>([
96
+ "abcdefg",
97
+ 'st"ring" w""ith quotes"',
98
+ 'string \t\r"with ran\tdom spa\nces and \nnewlines\n\n\n',
99
+ 'string with colon : comma , brace [ ] bracket { } and quote " and other quote "',
100
+ ]);
101
+ });
102
+
103
+ it("should ser/de nested integer arrays", () => {
104
+ canSerde<i64[][]>([[100, 101], [-100, -101], [0]]);
105
+ });
106
+
107
+ it("should ser/de float arrays", () => {
108
+ canSerde<f64[][]>([
109
+ [7.23],
110
+ [10e2],
111
+ [10e2],
112
+ [123456e-5],
113
+ [123456e-5],
114
+ [0.0],
115
+ [7.23],
116
+ ]);
117
+ });
118
+
119
+ it("should ser/de boolean arrays", () => {
120
+ canSerde<bool[][]>([[true], [false]]);
121
+ canSerde<boolean[][]>([[true], [false]]);
122
+ });
123
+
124
+ it("should ser/de string arrays", () => {
125
+ canSerde<string[][]>([
126
+ ["abcdefg"],
127
+ ['st"ring" w""ith quotes"'],
128
+ ['string \t\r\\"with ran\tdom spa\nces and \nnewlines\n\n\n'],
129
+ [
130
+ 'string with colon : comma , brace [ ] bracket { } and quote " and other quote \\"',
131
+ ],
132
+ ]);
133
+ });
134
+ });
82
135
 
83
- it("should ser/de nested integer arrays", () => {
84
- canSerde<i64[][]>([[100, 101], [-100, -101], [0]])
136
+ describe("Ser/de Objects", () => {
137
+ it("should ser/de Vec3 Objects", () => {
138
+ canSerde<Vec3>({
139
+ x: 3.4,
140
+ y: 1.2,
141
+ z: 8.3
85
142
  });
86
-
87
- it("should ser/de float arrays", () => {
88
- canSerde<f64[][]>([[7.23], [10e2], [10E2], [123456e-5], [123456E-5], [0.0], [7.23]])
89
- })
90
-
91
- it("should ser/de boolean arrays", () => {
92
- canSerde<bool[][]>([[true], [false]])
93
- canSerde<boolean[][]>([[true], [false]])
94
- })
95
-
96
- it("should ser/de string arrays", () => {
97
- canSerde<string[][]>([["abcdefg"], ["st\"ring\" w\"\"ith quotes\""], ["string \t\r\\\"with ran\tdom spa\nces and \nnewlines\n\n\n"], ["string with colon : comma , brace [ ] bracket { } and quote \" and other quote \\\""]])
143
+ });
144
+ it("should ser/de deep objects", () => {
145
+ canSerde<Player>({
146
+ firstName: "Emmet",
147
+ lastName: "West",
148
+ lastActive: [8, 27, 2022],
149
+ age: 23,
150
+ pos: {
151
+ x: 3.4,
152
+ y: 1.2,
153
+ z: 8.3
154
+ },
155
+ isVerified: true,
98
156
  });
157
+ });
99
158
  });
100
-
101
- describe("Ser/de Objects", () => {
102
- it("should ser/de Vec2 Objects", () => {
103
- canSerde<Vec2>({
104
- x: 3.4,
105
- y: 1.2
106
- })
107
- })
108
-
109
- })
@@ -0,0 +1,3 @@
1
+ class Dynamic {
2
+
3
+ }
package/assembly/index.ts CHANGED
@@ -1 +1 @@
1
- export { JSON } from "./json";
1
+ export { JSON } from "./src/json";