harmony-erlpack 0.0.1

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/src/test.ts ADDED
@@ -0,0 +1,57 @@
1
+ import {pack, unpack} from "./index.js";
2
+ import {ready} from "./ready.js";
3
+
4
+ const bad = await import("@yukikaze-bot/erlpack");
5
+ const assert = await import("assert");
6
+
7
+ const testPack = (m: unknown, testWithErl = true) => {
8
+ const arr = new Uint8Array(pack(m));
9
+ if (testWithErl) {
10
+ try {
11
+ const after = bad.unpack(arr);
12
+ assert.deepEqual(after, m);
13
+ } catch {}
14
+ }
15
+ {
16
+ const after = unpack(arr.buffer);
17
+ assert.deepEqual(after, m);
18
+ }
19
+ };
20
+ testPack(1);
21
+ testPack(4);
22
+ testPack(4000);
23
+ testPack(-4000);
24
+ testPack(2 ** 32 - 1);
25
+ testPack(1.1);
26
+ testPack(undefined);
27
+ testPack(true);
28
+ testPack(false);
29
+ testPack("short string");
30
+ testPack([1, 2, 3, [], 2]);
31
+ testPack({a: 1});
32
+ testPack(2n ** 200n, false);
33
+ testPack(-1n, false);
34
+ testPack(1n, false);
35
+ const obj = ready;
36
+ console.time("new packer");
37
+ for (let i = 0; i < 100; i++) {
38
+ pack(obj);
39
+ }
40
+ console.timeEnd("new packer");
41
+ console.time("old packer");
42
+ for (let i = 0; i < 100; i++) {
43
+ bad.pack(obj);
44
+ }
45
+ console.timeEnd("old packer");
46
+ console.time("new unpacker");
47
+ const u = pack(obj);
48
+ for (let i = 0; i < 100; i++) {
49
+ unpack(u);
50
+ }
51
+ console.timeEnd("new unpacker");
52
+ const b = new Uint8Array(u);
53
+ console.time("old unpacker");
54
+ for (let i = 0; i < 100; i++) {
55
+ bad.unpack(b);
56
+ }
57
+ console.timeEnd("old unpacker");
package/tsconfig.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "nodenext",
4
+ "target": "esnext",
5
+ "sourceMap": true,
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "noUncheckedIndexedAccess": true,
9
+ "exactOptionalPropertyTypes": true,
10
+ "strict": true,
11
+ "isolatedModules": false,
12
+ "noUncheckedSideEffectImports": true,
13
+ "moduleDetection": "force",
14
+ "skipLibCheck": true,
15
+ "rootDir":"./src",
16
+ "outDir": "./dist",
17
+ "types":["node"]
18
+ },
19
+ "include": ["src/**/*.ts"],
20
+ "exclude": ["node_modules"]
21
+ }