json-as 0.5.23 → 0.5.25

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.
@@ -39,7 +39,7 @@ export namespace JSON {
39
39
  */
40
40
  export function stringify<T>(data: T): string {
41
41
  // String
42
- if (isString<T>()) {
42
+ if (isString<T>() && data != null) {
43
43
  let result = new StringSink("\"");
44
44
  // @ts-ignore
45
45
  for (let i = 0; i < data.length; i++) {
@@ -128,7 +128,7 @@ export namespace JSON {
128
128
  // @ts-ignore
129
129
  return data.toString();
130
130
  } else {
131
- throw new Error(`Could not serialize data of type ${nameof<T>()}. Invalid data provided.`);
131
+ throw new Error(`Could not serialize data of type ${nameof<T>()}. Make sure to add the correct decorators to classes.`);
132
132
  }
133
133
  }
134
134
  /**
@@ -165,7 +165,7 @@ export namespace JSON {
165
165
  return parseBigNum<T>(data);
166
166
  } else {
167
167
  // @ts-ignore
168
- throw new Error(`Could not deserialize data ${data} to type ${nameof<T>()}. Invalide data provided.`);
168
+ throw new Error(`Could not deserialize data ${data} to type ${nameof<T>()}. Make sure to add the correct decorators to classes.`);
169
169
  }
170
170
  }
171
171
  // @ts-ignore
@@ -194,8 +194,7 @@ export namespace JSON {
194
194
  return parseBigNum<T>(data);
195
195
  } else {
196
196
  // @ts-ignore
197
- //return null;
198
- throw new Error(`Could not deserialize data ${data} to type ${nameof<T>()}. Invalide data provided.`)
197
+ throw new Error(`Could not deserialize data ${data} to type ${nameof<T>()}. Make sure to add the correct decorators to classes.`)
199
198
  }
200
199
  }
201
200
  }
@@ -67,7 +67,7 @@ export function escapeChar(char: string): string {
67
67
  */
68
68
  export function getArrayDepth<T>(depth: i32 = 1): i32 {
69
69
  // @ts-ignore
70
- if (isArray<T>()) {
70
+ if (!isArray<T>()) {
71
71
  return 0;
72
72
  // @ts-ignore
73
73
  } else if (isArray<valueof<T>>()) {
@@ -77,4 +77,4 @@ export function getArrayDepth<T>(depth: i32 = 1): i32 {
77
77
  } else {
78
78
  return depth;
79
79
  }
80
- }
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-as",
3
- "version": "0.5.23",
3
+ "version": "0.5.25",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@json-as/transform",
3
- "version": "0.5.23",
3
+ "version": "0.5.25",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
File without changes