json-as 0.5.36 → 0.5.38

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.
@@ -1,20 +1,6 @@
1
1
  import { StringSink } from "as-string-sink/assembly";
2
- import { CharCode, isSpace } from "util/string";
3
- import { backSlashCode, quoteCode, rCode } from "./chars";
4
- import { u128, u128Safe, u256, u256Safe, i128, i128Safe, i256Safe } from "as-bignum/assembly";
5
-
6
- // @ts-ignore
7
- @inline
8
- export function isBigNum<T>(): boolean {
9
- if (idof<T>() == idof<u128>()) return true;
10
- if (idof<T>() == idof<u128Safe>()) return true;
11
- if (idof<T>() == idof<u256>()) return true;
12
- if (idof<T>() == idof<u256Safe>()) return true;
13
- if (idof<T>() == idof<i128>()) return true;
14
- if (idof<T>() == idof<i128Safe>()) return true;
15
- if (idof<T>() == idof<i256Safe>()) return true;
16
- return false;
17
- }
2
+ import { isSpace } from "util/string";
3
+ import { backSlashCode, quoteCode } from "./chars";
18
4
 
19
5
  // @ts-ignore
20
6
  @inline
@@ -22,6 +8,8 @@ export function unsafeCharCodeAt(data: string, pos: i32): i32 {
22
8
  return load<u16>(changetype<usize>(data) + ((<usize>pos) << 1));
23
9
  }
24
10
 
11
+ // @ts-ignore
12
+ @inline
25
13
  export function removeWhitespace(data: string): string {
26
14
  const result = new StringSink();
27
15
  let instr = false;
@@ -48,15 +36,24 @@ export function removeWhitespace(data: string): string {
48
36
  @inline
49
37
  export function escapeChar(char: string): string {
50
38
  switch (unsafeCharCodeAt(char, 0)) {
51
- case 0x22: return '\\"';
52
- case 0x5C: return "\\\\";
53
- case 0x08: return "\\b";
54
- case 0x0A: return "\\n";
55
- case 0x0D: return "\\r";
56
- case 0x09: return "\\t";
57
- case 0x0C: return "\\f";
58
- case 0x0B: return "\\u000b";
59
- default: return char;
39
+ case 0x22:
40
+ return '\\"';
41
+ case 0x5c:
42
+ return "\\\\";
43
+ case 0x08:
44
+ return "\\b";
45
+ case 0x0a:
46
+ return "\\n";
47
+ case 0x0d:
48
+ return "\\r";
49
+ case 0x09:
50
+ return "\\t";
51
+ case 0x0c:
52
+ return "\\f";
53
+ case 0x0b:
54
+ return "\\u000b";
55
+ default:
56
+ return char;
60
57
  }
61
58
  }
62
59
 
@@ -65,6 +62,9 @@ export function escapeChar(char: string): string {
65
62
  * Suffers no overhead besides function calling and a if/else.
66
63
  * @returns depth of array
67
64
  */
65
+
66
+ // @ts-ignore
67
+ @inline
68
68
  export function getArrayDepth<T>(depth: i32 = 1): i32 {
69
69
  // @ts-ignore
70
70
  if (!isArray<T>()) {
@@ -81,67 +81,64 @@ export function getArrayDepth<T>(depth: i32 = 1): i32 {
81
81
 
82
82
  /**
83
83
  * Implementation of ATOI. Can be much much faster with SIMD.
84
- * Its pretty fast. (173m ops (atoi_fast) vs 89 ops (parseInt))
85
- */
86
- @unsafe
84
+ * Benchmark: 40-46m ops/s
85
+ */
86
+
87
+ // @ts-ignore
87
88
  @inline
88
89
  export function atoi_fast<T extends number>(str: string, offset: i32 = 0): T {
89
90
  // @ts-ignore
90
91
  let val: T = 0;
91
- for (; offset < (str.length << 1); offset += 2) {
92
+ for (; offset < str.length << 1; offset += 2) {
92
93
  // @ts-ignore
93
- val = (val << 1) + (val << 3) + (load<u16>(changetype<usize>(str) + <usize>offset) - 48);
94
+ val =
95
+ (val << 1) +
96
+ (val << 3) +
97
+ (load<u16>(changetype<usize>(str) + <usize>offset) - 48);
94
98
  // We use load because in this case, there is no need to have bounds-checking
95
99
  }
96
100
  return val;
97
101
  }
98
102
 
99
103
  /**
100
- * Implementation of ATOI. Can be much much faster with SIMD.
101
- * Its pretty fast. (173m ops (atoi_fast) vs 89 ops (parseInt))
102
- */
103
- @unsafe
104
+ * Parses an integer using atoi_fast and applies the appended exponential number to it as scientific notation.
105
+ * Benchmark: Hovers around 30m ops/s
106
+ * Only safe if the string is valid.
107
+ * @param str integer to parse. example: 123e1, 123e-1, 123E100
108
+ * @returns
109
+ */
110
+
111
+ // @ts-ignore
104
112
  @inline
105
- export function parseJSONInt<T extends number>(str: string): T {
113
+ export function parseSciInteger<T extends number>(str: string): T {
106
114
  // @ts-ignore
107
115
  let val: T = 0;
108
- let char: u16 = load<u16>(changetype<usize>(str));
109
- let pos = 2;
110
- let neg = char === 45;
111
- // @ts-ignore
112
- val = (val << 1) + (val << 3) + (char - 48);
113
- for (; pos < (str.length << 1); pos += 2) {
114
- char = load<u16>(changetype<usize>(str) + <usize>pos);
116
+ let offset = 0;
117
+ for (; offset < str.length << 1; offset += 2) {
118
+ const char = load<u16>(changetype<usize>(str) + <usize>offset);
115
119
  if (char === 101 || char === 69) {
116
- char = load<u16>(changetype<usize>(str) + <usize>(pos += 2));
120
+ const char = load<u16>(changetype<usize>(str) + <usize>(offset += 2));
117
121
  if (char === 45) {
118
122
  // @ts-ignore
119
- val /= sciNote<T>(atoi_fast<T>(str, pos += 2));
120
- if (neg === true) {
121
- // @ts-ignore
122
- return ~val + 1;
123
- }
123
+ val /= sciNote<T>(atoi_fast<T>(str, (offset += 2)));
124
+ // @ts-ignore
124
125
  return val;
125
126
  } else {
126
127
  // @ts-ignore
127
- val *= sciNote<T>(atoi_fast<T>(str, pos += 2));
128
- if (neg === true) {
129
- // @ts-ignore
130
- return ~val + 1;
131
- }
128
+ val *= sciNote<T>(atoi_fast<T>(str, offset));
129
+ // @ts-ignore
132
130
  return val;
133
131
  }
134
132
  }
135
133
  // @ts-ignore
136
134
  val = (val << 1) + (val << 3) + (char - 48);
137
- }
138
- if (neg === true) {
139
- // @ts-ignore
140
- val = ~val + 1;
135
+ // We use load because in this case, there is no need to have bounds-checking
141
136
  }
142
137
  return val;
143
138
  }
144
139
 
140
+ // @ts-ignore
141
+ @inline
145
142
  function sciNote<T extends number>(num: T): T {
146
143
  let res = 1;
147
144
  if (num > 0) {
@@ -155,4 +152,4 @@ function sciNote<T extends number>(num: T): T {
155
152
  }
156
153
  // @ts-ignore
157
154
  return res;
158
- }
155
+ }
package/assembly/test.ts CHANGED
@@ -1,7 +1,6 @@
1
- import { backSlashCode, quoteCode } from "./src/chars";
2
1
  import { JSON } from "./src/json";
3
- import { atoi_fast, parseJSONInt, unsafeCharCodeAt } from "./src/util";
4
-
2
+ import { atoi_fast, parseSciInteger } from "./src/util";
3
+ import * as a from "util/number"
5
4
  @json
6
5
  class Vec3 {
7
6
  x!: f32;
@@ -27,16 +26,16 @@ const player: Player = {
27
26
  pos: {
28
27
  x: 3.4,
29
28
  y: 1.2,
30
- z: 8.3
29
+ z: 8.3,
31
30
  },
32
- isVerified: true
31
+ isVerified: true,
33
32
  };
34
33
 
35
34
  const vec: Vec3 = {
36
35
  x: 3,
37
36
  y: 1,
38
- z: 8
39
- }
37
+ z: 8,
38
+ };
40
39
 
41
40
  const serializedPlayer = JSON.stringify<Player>(player);
42
41
  console.log(serializedPlayer);
@@ -49,12 +48,195 @@ console.log(serializedVec3);
49
48
  const parsedVec3 = JSON.parse<Vec3>(serializedVec3);
50
49
  console.log(JSON.stringify(parsedVec3));
51
50
 
52
- console.log(`atoi_fast("429496729"): ${atoi_fast<i32>("429496729")}`);
51
+ console.log("atoi:");
52
+ console.log("123 - " + parseSciInteger<i32>("123").toString());
53
+ console.log("1230 - " + parseSciInteger<i32>("123e1").toString());
54
+ console.log("12300 - " + parseSciInteger<i32>("123e2").toString());
55
+ console.log("123000 - " + parseSciInteger<i32>("123e3").toString());
56
+ console.log("32 - " + parseSciInteger<i32>("123e-1").toString());
57
+
58
+ const str = changetype<string>(new ArrayBuffer(6));
59
+ console.log("istr:");
60
+ console.log("123 - " + istr8(123));
61
+ console.log("32 - " + istr8(32));
62
+ console.log("3 - " + istr8(3));
63
+
64
+ console.log(Uint8Array.wrap(changetype<ArrayBuffer>(istr8(12))).join(" "));
65
+ console.log(load<u32>(changetype<usize>(istr8(12))).toString());
66
+ @inline function istr8<T extends number>(int: T): string {
67
+ if (int >= 100) {
68
+ const str = changetype<string>(__new(6, idof<String>()));
69
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48);
70
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 2);
71
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 4);
72
+ return str;
73
+ } else if (int >= 10) {
74
+ const str = changetype<string>(__new(4, idof<String>()));
75
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48);
76
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 2);
77
+ return str;
78
+ } else {
79
+ const str = changetype<string>(__new(2, idof<String>()));
80
+ store<u16>(changetype<usize>(str), (int % 10) + 48);
81
+ return str;
82
+ }
83
+ }
84
+
85
+ export function istr16<T extends number>(int: T): string {
86
+ if (int >= 10_000) {
87
+ const str = changetype<string>(__new(10, idof<String>()));
88
+ store<u16>(changetype<usize>(str), ((int / 10000) % 10) + 48);
89
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48, 2);
90
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 4);
91
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 6);
92
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 8);
93
+ return str;
94
+ } else if (int >= 1_000) {
95
+ const str = changetype<string>(__new(8, idof<String>()));
96
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48);
97
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 2);
98
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 4);
99
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 6);
100
+ return str;
101
+ } else if (int >= 100) {
102
+ const str = changetype<string>(__new(6, idof<String>()));
103
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48);
104
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 2);
105
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 4);
106
+ return str;
107
+ } else if (int >= 10) {
108
+ const str = changetype<string>(__new(4, idof<String>()));
109
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48);
110
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 2);
111
+ return str;
112
+ } else {
113
+ const str = changetype<string>(__new(2, idof<String>()));
114
+ store<u16>(changetype<usize>(str), (int % 10) + 48);
115
+ return str;
116
+ }
117
+ }
118
+
119
+ export function istr32<T extends number>(int: T): string {
120
+ if (int >= 1_000_000_000) {
121
+ const str = changetype<string>(__new(22, idof<String>()));
122
+ store<u16>(changetype<usize>(str), ((int / 10000000000) % 10) + 48);
123
+ store<u16>(changetype<usize>(str), ((int / 1000000000) % 10) + 48, 2);
124
+ store<u16>(changetype<usize>(str), ((int / 100000000) % 10) + 48, 4);
125
+ store<u16>(changetype<usize>(str), ((int / 10000000) % 10) + 48, 6);
126
+ store<u16>(changetype<usize>(str), ((int / 1000000) % 10) + 48, 8);
127
+ store<u16>(changetype<usize>(str), ((int / 100000) % 10) + 48, 10);
128
+ store<u16>(changetype<usize>(str), ((int / 10000) % 10) + 48, 12);
129
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48, 14);
130
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 16);
131
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 18);
132
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 20);
133
+ return str;
134
+ } else if (int >= 100_000_000) {
135
+ const str = changetype<string>(__new(20, idof<String>()));
136
+ store<u16>(changetype<usize>(str), ((int / 1000000000) % 10) + 48);
137
+ store<u16>(changetype<usize>(str), ((int / 100000000) % 10) + 48, 2);
138
+ store<u16>(changetype<usize>(str), ((int / 10000000) % 10) + 48, 4);
139
+ store<u16>(changetype<usize>(str), ((int / 1000000) % 10) + 48, 6);
140
+ store<u16>(changetype<usize>(str), ((int / 100000) % 10) + 48, 8);
141
+ store<u16>(changetype<usize>(str), ((int / 10000) % 10) + 48, 10);
142
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48, 12);
143
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 14);
144
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 16);
145
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 18);
146
+ return str;
147
+ } else if (int >= 10_000_000) {
148
+ const str = changetype<string>(__new(18, idof<String>()));
149
+ store<u16>(changetype<usize>(str), ((int / 100000000) % 10) + 48);
150
+ store<u16>(changetype<usize>(str), ((int / 10000000) % 10) + 48, 2);
151
+ store<u16>(changetype<usize>(str), ((int / 1000000) % 10) + 48, 4);
152
+ store<u16>(changetype<usize>(str), ((int / 100000) % 10) + 48, 6);
153
+ store<u16>(changetype<usize>(str), ((int / 10000) % 10) + 48, 8);
154
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48, 10);
155
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 12);
156
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 14);
157
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 16);
158
+ return str;
159
+ } else if (int >= 10_000_000) {
160
+ const str = changetype<string>(__new(16, idof<String>()));
161
+ store<u16>(changetype<usize>(str), ((int / 10000000) % 10) + 48);
162
+ store<u16>(changetype<usize>(str), ((int / 1000000) % 10) + 48, 2);
163
+ store<u16>(changetype<usize>(str), ((int / 100000) % 10) + 48, 4);
164
+ store<u16>(changetype<usize>(str), ((int / 10000) % 10) + 48, 6);
165
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48, 8);
166
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 10);
167
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 12);
168
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 14);
169
+ return str;
170
+ } else if (int >= 1_000_000) {
171
+ const str = changetype<string>(__new(14, idof<String>()));
172
+ store<u16>(changetype<usize>(str), ((int / 1000000) % 10) + 48);
173
+ store<u16>(changetype<usize>(str), ((int / 100000) % 10) + 48, 2);
174
+ store<u16>(changetype<usize>(str), ((int / 10000) % 10) + 48, 4);
175
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48, 6);
176
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 8);
177
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 10);
178
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 12);
179
+ return str;
180
+ } else if (int >= 100_000) {
181
+ const str = changetype<string>(__new(12, idof<String>()));
182
+ store<u16>(changetype<usize>(str), ((int / 100000) % 10) + 48);
183
+ store<u16>(changetype<usize>(str), ((int / 10000) % 10) + 48, 2);
184
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48, 4);
185
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 6);
186
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 8);
187
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 10);
188
+ return str;
189
+ } else if (int >= 10_000) {
190
+ const str = changetype<string>(__new(10, idof<String>()));
191
+ store<u16>(changetype<usize>(str), ((int / 10000) % 10) + 48);
192
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48, 2);
193
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 4);
194
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 6);
195
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 8);
196
+ return str;
197
+ } else if (int >= 1_000) {
198
+ const str = changetype<string>(__new(8, idof<String>()));
199
+ store<u16>(changetype<usize>(str), ((int / 1000) % 10) + 48);
200
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48, 2);
201
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 4);
202
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 6);
203
+ return str;
204
+ } else if (int >= 100) {
205
+ const str = changetype<string>(__new(6, idof<String>()));
206
+ store<u16>(changetype<usize>(str), ((int / 100) % 10) + 48);
207
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48, 2);
208
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 4);
209
+ return str;
210
+ } else if (int >= 10) {
211
+ const str = changetype<string>(__new(4, idof<String>()));
212
+ store<u16>(changetype<usize>(str), ((int / 10) % 10) + 48);
213
+ store<u16>(changetype<usize>(str), (int % 10) + 48, 2);
214
+ return str;
215
+ } else {
216
+ const str = changetype<string>(__new(2, idof<String>()));
217
+ store<u16>(changetype<usize>(str), (int % 10) + 48);
218
+ return str;
219
+ }
220
+ }
221
+
222
+ export function istr64<T extends number>(int: T): string {
223
+ const val = new ArrayBuffer(6);
224
+ store<u16>(changetype<usize>(val), (int % 10) + 48, 4);
225
+ if ((int = int / 10 as T) > 0) store<u16>(changetype<usize>(val), (int % 10) + 48, 2);
226
+ else return changetype<string>(val);
227
+ if ((int = int / 10 as T) > 0) store<u16>(changetype<usize>(val), (int % 10) + 48);
228
+ return changetype<string>(val);
229
+ }
53
230
 
54
- console.log(`strtol("429496729"): ${i32.parse("429496729")}`);
231
+ // 0 = 48
232
+ // 1 = 49
233
+ // 2 = 50
234
+ // 3 = 51
235
+ // 4 = 52
236
+ // 5 = 53
237
+ // 6 = 54
238
+ // 7 = 55
239
+ // 8 = 56
240
+ // 9 = 57
55
241
 
56
- console.log(parseJSONInt<i32>("321").toString());
57
- console.log(parseJSONInt<i32>("321e1").toString());
58
- console.log(parseJSONInt<i32>("321e2").toString());
59
- console.log(parseJSONInt<i32>("321e3").toString());
60
- console.log(parseJSONInt<i32>("321e-1").toString());
242
+ console.log(JSON.stringify("h\\i from gray\bson"))
@@ -2,5 +2,98 @@
2
2
  "extends": "assemblyscript/std/assembly.json",
3
3
  "include": [
4
4
  "./**/*.ts"
5
- ]
5
+ ],
6
+ "compilerOptions": {
7
+ /* Visit https://aka.ms/tsconfig to read more about this file */
8
+ /* Projects */
9
+ // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
10
+ // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
11
+ // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
12
+ // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
13
+ // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
14
+ // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
15
+ /* Language and Environment */
16
+ "target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
17
+ // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
18
+ // "jsx": "preserve", /* Specify what JSX code is generated. */
19
+ "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
20
+ "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
21
+ // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
22
+ // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
23
+ // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
24
+ // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
25
+ // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
26
+ // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
27
+ // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
28
+ /* Modules */
29
+ "module": "commonjs" /* Specify what module code is generated. */,
30
+ // "rootDir": "./", /* Specify the root folder within your source files. */
31
+ // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
32
+ // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
33
+ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
34
+ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
35
+ // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
36
+ // "types": [], /* Specify type package names to be included without being referenced in a source file. */
37
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
38
+ // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
39
+ // "resolveJsonModule": true, /* Enable importing .json files. */
40
+ // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
41
+ /* JavaScript Support */
42
+ // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
43
+ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
44
+ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
45
+ /* Emit */
46
+ // "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
47
+ // "declarationMap": true, /* Create sourcemaps for d.ts files. */
48
+ // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
49
+ // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
50
+ // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
51
+ // "outDir": "./", /* Specify an output folder for all emitted files. */
52
+ // "removeComments": true, /* Disable emitting comments. */
53
+ // "noEmit": true, /* Disable emitting files from a compilation. */
54
+ // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
55
+ // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
56
+ // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
57
+ // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
58
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
59
+ // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
60
+ // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
61
+ // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
62
+ // "newLine": "crlf", /* Set the newline character for emitting files. */
63
+ // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
64
+ // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
65
+ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
66
+ // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
67
+ // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
68
+ // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
69
+ /* Interop Constraints */
70
+ // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
71
+ // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
72
+ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
73
+ // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
74
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
75
+ /* Type Checking */
76
+ "strict": false/* Enable all strict type-checking options. */,
77
+ // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
78
+ "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
79
+ // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
80
+ // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
81
+ // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
82
+ // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
83
+ // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
84
+ // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
85
+ "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
86
+ "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
87
+ // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
88
+ // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
89
+ // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
90
+ // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
91
+ // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
92
+ // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
93
+ // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
94
+ // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
95
+ /* Completeness */
96
+ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
97
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */
98
+ }
6
99
  }
package/index.ts CHANGED
@@ -1 +1 @@
1
- export { JSON } from "./assembly/src/json";
1
+ export { JSON } from "./assembly/src/json";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-as",
3
- "version": "0.5.36",
3
+ "version": "0.5.38",
4
4
  "description": "JSON encoder/decoder for AssemblyScript",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
@@ -13,62 +13,60 @@ const XXH32_P5 = 374761393;
13
13
  // @ts-ignore: decorator
14
14
  const XXH32_SEED = 0;
15
15
  function hash32(key, len = 4) {
16
- let h = XXH32_SEED + XXH32_P5 + len;
17
- h += key * XXH32_P3;
18
- h = rotl(h, 17) * XXH32_P4;
19
- h ^= h >> 15;
20
- h *= XXH32_P2;
21
- h ^= h >> 13;
22
- h *= XXH32_P3;
23
- h ^= h >> 16;
24
- return h;
16
+ let h = XXH32_SEED + XXH32_P5 + len;
17
+ h += key * XXH32_P3;
18
+ h = rotl(h, 17) * XXH32_P4;
19
+ h ^= h >> 15;
20
+ h *= XXH32_P2;
21
+ h ^= h >> 13;
22
+ h *= XXH32_P3;
23
+ h ^= h >> 16;
24
+ return h;
25
25
  }
26
26
  function rotl(x, r) {
27
- return (x << r) | (x >>> (32 - r));
27
+ return (x << r) | (x >>> (32 - r));
28
28
  }
29
29
  function mix(h, key) {
30
- return rotl(h + key * XXH32_P2, 13) * XXH32_P1;
30
+ return rotl(h + key * XXH32_P2, 13) * XXH32_P1;
31
31
  }
32
32
  export function hashStr(key) {
33
- if (key == null)
34
- return XXH32_SEED;
35
- let h = key.length;
36
- let len = h;
37
- let pos = 0;
38
- if (len >= 16) {
39
- let s1 = XXH32_SEED + XXH32_P1 + XXH32_P2;
40
- let s2 = XXH32_SEED + XXH32_P2;
41
- let s3 = XXH32_SEED;
42
- let s4 = XXH32_SEED - XXH32_P1;
43
- let end = len + pos - 16;
44
- while (pos <= end) {
45
- s1 = mix(s1, key.charCodeAt(pos));
46
- s2 = mix(s2, key.charCodeAt(pos + 1));
47
- s3 = mix(s3, key.charCodeAt(pos + 2));
48
- s4 = mix(s4, load(pos, 12));
49
- pos += 16;
50
- }
51
- h += rotl(s1, 1) + rotl(s2, 7) + rotl(s3, 12) + rotl(s4, 18);
52
- }
53
- else {
54
- h += XXH32_SEED + XXH32_P5;
55
- }
56
- let end = changetype(key) + len - 4;
33
+ if (key == null) return XXH32_SEED;
34
+ let h = key.length;
35
+ let len = h;
36
+ let pos = 0;
37
+ if (len >= 16) {
38
+ let s1 = XXH32_SEED + XXH32_P1 + XXH32_P2;
39
+ let s2 = XXH32_SEED + XXH32_P2;
40
+ let s3 = XXH32_SEED;
41
+ let s4 = XXH32_SEED - XXH32_P1;
42
+ let end = len + pos - 16;
57
43
  while (pos <= end) {
58
- h += load(pos) * XXH32_P3;
59
- h = rotl(h, 17) * XXH32_P4;
60
- pos += 4;
44
+ s1 = mix(s1, key.charCodeAt(pos));
45
+ s2 = mix(s2, key.charCodeAt(pos + 1));
46
+ s3 = mix(s3, key.charCodeAt(pos + 2));
47
+ s4 = mix(s4, load(pos, 12));
48
+ pos += 16;
61
49
  }
62
- end = changetype(key) + len;
63
- while (pos < end) {
64
- h += load(pos) * XXH32_P5;
65
- h = rotl(h, 11) * XXH32_P1;
66
- pos++;
67
- }
68
- h ^= h >> 15;
69
- h *= XXH32_P2;
70
- h ^= h >> 13;
71
- h *= XXH32_P3;
72
- h ^= h >> 16;
73
- return h;
50
+ h += rotl(s1, 1) + rotl(s2, 7) + rotl(s3, 12) + rotl(s4, 18);
51
+ } else {
52
+ h += XXH32_SEED + XXH32_P5;
53
+ }
54
+ let end = changetype(key) + len - 4;
55
+ while (pos <= end) {
56
+ h += load(pos) * XXH32_P3;
57
+ h = rotl(h, 17) * XXH32_P4;
58
+ pos += 4;
59
+ }
60
+ end = changetype(key) + len;
61
+ while (pos < end) {
62
+ h += load(pos) * XXH32_P5;
63
+ h = rotl(h, 11) * XXH32_P1;
64
+ pos++;
65
+ }
66
+ h ^= h >> 15;
67
+ h *= XXH32_P2;
68
+ h ^= h >> 13;
69
+ h *= XXH32_P3;
70
+ h ^= h >> 16;
71
+ return h;
74
72
  }