json-as 0.5.19 → 0.5.20

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
@@ -73,28 +73,10 @@ const stringified = JSON.stringify<Player>(player);
73
73
  const parsed = JSON.parse<Player>(stringified);
74
74
  ```
75
75
 
76
- # FAQ
76
+ # Notes
77
77
 
78
- **Does it support the JSON specification?**
78
+ Performance is nearly equal to the JavaScript JSON implementation which is in C++.
79
79
 
80
- Yes, it does. However, dynamic objects and arrays are not supported, but planned in the near future.
81
-
82
- **Is it fast?**
83
-
84
- Look below
85
-
86
- **How does it compare to other libs?**
87
-
88
- Its pretty much the same as the other libraries out there (near/assemblyscript-json and @serial-as/json), but it focuses highly on performance
89
-
90
- **Will it catch invalid JSON?**
91
-
92
- No, it does not check for invalid JSON, but gives its best shot at parsing instead. Will probably throw an error.
93
-
94
- **How does it compare performance-wise to other libraries?**
95
-
96
- In my testing, parsing a Vector 2 runs at 2.2m ops/s with as-json and around 10,000 ops/s with assemblyscript-json and @serial-as/json.
97
- Both are great libraries however.
98
80
  ## Performance
99
81
 
100
82
  **Serialize Object (Vec2):** ~7.20m ops/s
package/asconfig.json CHANGED
@@ -12,9 +12,6 @@
12
12
  "options": {
13
13
  "transform": [
14
14
  "./transform"
15
- ],
16
- "bindings": "esm",
17
- "exportStart": "_start"
18
- },
19
- "extends": "./node_modules/@assemblyscript/wasi-shim/asconfig.json"
15
+ ]
16
+ }
20
17
  }
@@ -9,9 +9,9 @@ function canSerde<T>(data: T): void {
9
9
  // @ts-ignore
10
10
  @json
11
11
  class Vec3 {
12
- x: f32;
13
- y: f32;
14
- z: f32;
12
+ x: f64;
13
+ y: f64;
14
+ z: f64;
15
15
  }
16
16
 
17
17
  // @ts-ignore
@@ -136,6 +136,7 @@ describe("Ser/de Array", () => {
136
136
  });
137
137
 
138
138
  it("should ser/de string arrays", () => {
139
+ // ["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 \\""]
139
140
  canSerde<string[]>([
140
141
  "abcdefg",
141
142
  'st"ring" w""ith quotes"',
@@ -241,7 +241,7 @@ export function parseNumber<T>(data: string): T {
241
241
  // @ts-ignore
242
242
  const type: T = 0;
243
243
  // @ts-ignore
244
- if (type instanceof f64) return f32.parse(data);
244
+ if (type instanceof f64) return f64.parse(data);
245
245
  // @ts-ignore
246
246
  else if (type instanceof f32) return f32.parse(data);
247
247
  // @ts-ignore
@@ -268,7 +268,7 @@ function parseObject<T>(data: string): T {
268
268
  let schema: nonnull<T> = changetype<nonnull<T>>(__new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
269
269
  let key = "";
270
270
  let isKey = false;
271
- let depth = 1;
271
+ let depth = 0;
272
272
  let char = 0;
273
273
  let outerLoopIndex = 1;
274
274
  for (; outerLoopIndex < data.length - 1; outerLoopIndex++) {
@@ -281,10 +281,10 @@ function parseObject<T>(data: string): T {
281
281
  ) {
282
282
  char = unsafeCharCodeAt(data, arrayValueIndex);
283
283
  if (char === leftBracketCode) {
284
- depth = depth << 1;
284
+ depth++;
285
285
  } else if (char === rightBracketCode) {
286
- depth = depth >> 1;
287
- if (depth === 1) {
286
+ depth--;
287
+ if (depth === 0) {
288
288
  ++arrayValueIndex;
289
289
  // @ts-ignore
290
290
  schema.__JSON_Set_Key(key, data.slice(outerLoopIndex, arrayValueIndex));
@@ -302,10 +302,10 @@ function parseObject<T>(data: string): T {
302
302
  ) {
303
303
  char = unsafeCharCodeAt(data, objectValueIndex);
304
304
  if (char === leftBraceCode) {
305
- depth = depth << 1;
305
+ depth++;
306
306
  } else if (char === rightBraceCode) {
307
- depth = depth >> 1;
308
- if (depth === 1) {
307
+ depth--;
308
+ if (depth === 0) {
309
309
  ++objectValueIndex;
310
310
  // @ts-ignore
311
311
  schema.__JSON_Set_Key(key, data.slice(outerLoopIndex, objectValueIndex));
package/assembly/test.ts CHANGED
@@ -1,9 +1,17 @@
1
1
  import { u128 } from "as-bignum/assembly";
2
- import { Candle } from "./Candle";
3
2
  import {
4
3
  JSON
5
4
  } from ".";
6
5
 
6
+ const exp = `["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 \\""]`;
7
+
8
+ console.log(exp);
9
+ console.log(JSON.stringify([
10
+ "abcdefg",
11
+ 'st"ring" w""ith quotes"',
12
+ 'string \t\r"with ran\tdom spa\nces and \nnewlines\n\n\n',
13
+ 'string with colon : comma , brace [ ] bracket { } and quote " and other quote "',
14
+ ]))
7
15
  // @ts-ignore
8
16
  @JSON
9
17
  class Vec3 {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-as",
3
- "version": "0.5.19",
3
+ "version": "0.5.20",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -25,7 +25,6 @@
25
25
  "@as-tral/cli": "^2.0.0",
26
26
  "@assemblyscript/loader": "^0.27.0",
27
27
  "@assemblyscript/wasi-shim": "^0.1.0",
28
- "as-bignum": "^0.2.23",
29
28
  "assemblyscript": "^0.27.0",
30
29
  "assemblyscript-prettier": "^1.0.7",
31
30
  "prettier": "^2.8.3",
@@ -34,7 +33,8 @@
34
33
  },
35
34
  "dependencies": {
36
35
  "as-string-sink": "^0.5.0",
37
- "as-variant": "^0.4.1"
36
+ "as-variant": "^0.4.1",
37
+ "as-bignum": "^0.2.23"
38
38
  },
39
39
  "repository": {
40
40
  "type": "git",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@json-as/transform",
3
- "version": "0.5.19",
3
+ "version": "0.5.20",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
@@ -1,18 +0,0 @@
1
- import {
2
- JSON
3
- } from ".";
4
- @json
5
- export class Candle {
6
- timestamp!: i64;
7
- high!: f64;
8
- low!: f64;
9
- open!: f64;
10
- close!: f64;
11
- constructor(timestamp: i64, high: f64, low: f64, open: f64, close: f64) {
12
- this.timestamp = timestamp;
13
- this.high = high;
14
- this.low = low;
15
- this.open = open;
16
- this.close = close;
17
- }
18
- }