@hazae41/webpack 1.0.0 → 1.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/README.md +1 -6
- package/out/mods/packed/mod.d.ts +7 -10
- package/out/mods/packed/mod.js +68 -67
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,11 +8,6 @@ npm install @hazae41/webpack
|
|
|
8
8
|
|
|
9
9
|
[**📦 NPM**](https://www.npmjs.com/package/@hazae41/webpack)
|
|
10
10
|
|
|
11
|
-
## Features
|
|
12
|
-
|
|
13
|
-
- WebAssembly-compatible
|
|
14
|
-
- Fails on self-reference
|
|
15
|
-
|
|
16
11
|
## Usage
|
|
17
12
|
|
|
18
13
|
```tsx
|
|
@@ -23,7 +18,7 @@ type Packable =
|
|
|
23
18
|
| string
|
|
24
19
|
| bigint
|
|
25
20
|
| Array<Packable>
|
|
26
|
-
|
|
|
21
|
+
| Record<string, Packable>
|
|
27
22
|
```
|
|
28
23
|
|
|
29
24
|
```tsx
|
package/out/mods/packed/mod.d.ts
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type { Cursor } from "@hazae41/cursor";
|
|
2
|
-
export type Packable = null | number | Uint8Array | string | bigint | Array<Packable> | {
|
|
3
|
-
[k: string]: Packable;
|
|
4
|
-
};
|
|
5
2
|
export declare class Packed {
|
|
6
|
-
readonly
|
|
7
|
-
constructor(
|
|
3
|
+
readonly data: unknown;
|
|
4
|
+
constructor(data: unknown);
|
|
8
5
|
size(): number;
|
|
9
6
|
write(cursor: Cursor): void;
|
|
10
7
|
encode(): Uint8Array<ArrayBuffer>;
|
|
11
8
|
}
|
|
12
9
|
export declare namespace Packed {
|
|
13
|
-
function encode(
|
|
14
|
-
function decode(
|
|
15
|
-
function read(cursor: Cursor):
|
|
16
|
-
function size(
|
|
17
|
-
function write(
|
|
10
|
+
function encode(data: unknown): Uint8Array<ArrayBuffer>;
|
|
11
|
+
function decode(blob: Uint8Array): unknown;
|
|
12
|
+
function read(cursor: Cursor): unknown;
|
|
13
|
+
function size(data: unknown): number;
|
|
14
|
+
function write(data: unknown, cursor: Cursor): void;
|
|
18
15
|
}
|
package/out/mods/packed/mod.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
// deno-lint-ignore-file no-namespace
|
|
2
2
|
import { Readable, Writable } from "@hazae41/binary";
|
|
3
3
|
export class Packed {
|
|
4
|
-
|
|
5
|
-
constructor(
|
|
6
|
-
this.
|
|
4
|
+
data;
|
|
5
|
+
constructor(data) {
|
|
6
|
+
this.data = data;
|
|
7
7
|
}
|
|
8
8
|
size() {
|
|
9
|
-
return Packed.size(this.
|
|
9
|
+
return Packed.size(this.data);
|
|
10
10
|
}
|
|
11
11
|
write(cursor) {
|
|
12
|
-
return Packed.write(this.
|
|
12
|
+
return Packed.write(this.data, cursor);
|
|
13
13
|
}
|
|
14
14
|
encode() {
|
|
15
|
-
return Packed.encode(this.
|
|
15
|
+
return Packed.encode(this.data);
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
18
|
(function (Packed) {
|
|
19
|
-
function encode(
|
|
20
|
-
return Writable.writeToBytes(new Packed(
|
|
19
|
+
function encode(data) {
|
|
20
|
+
return Writable.writeToBytes(new Packed(data));
|
|
21
21
|
}
|
|
22
22
|
Packed.encode = encode;
|
|
23
|
-
function decode(
|
|
24
|
-
return Readable.readFromBytes(Packed,
|
|
23
|
+
function decode(blob) {
|
|
24
|
+
return Readable.readFromBytes(Packed, blob);
|
|
25
25
|
}
|
|
26
26
|
Packed.decode = decode;
|
|
27
27
|
function read(cursor) {
|
|
@@ -32,20 +32,20 @@ export class Packed {
|
|
|
32
32
|
return cursor.readFloat64();
|
|
33
33
|
if (type === 2) {
|
|
34
34
|
const size = cursor.readUint32();
|
|
35
|
-
const
|
|
36
|
-
return
|
|
35
|
+
const blob = cursor.read(size);
|
|
36
|
+
return blob;
|
|
37
37
|
}
|
|
38
38
|
if (type === 3) {
|
|
39
39
|
const size = cursor.readUint32();
|
|
40
|
-
const
|
|
41
|
-
const text = new TextDecoder().decode(
|
|
40
|
+
const blob = cursor.read(size);
|
|
41
|
+
const text = new TextDecoder().decode(blob);
|
|
42
42
|
return text;
|
|
43
43
|
}
|
|
44
44
|
if (type === 4) {
|
|
45
45
|
const sign = cursor.readUint8();
|
|
46
46
|
const size = cursor.readUint32();
|
|
47
|
-
const
|
|
48
|
-
const absolute = BigInt("0x" +
|
|
47
|
+
const blob = cursor.read(size);
|
|
48
|
+
const absolute = BigInt("0x" + blob.toHex());
|
|
49
49
|
const relative = sign ? -absolute : absolute;
|
|
50
50
|
return relative;
|
|
51
51
|
}
|
|
@@ -61,8 +61,8 @@ export class Packed {
|
|
|
61
61
|
const record = {};
|
|
62
62
|
for (let i = 0; i < length; i++) {
|
|
63
63
|
const subsize = cursor.readUint32();
|
|
64
|
-
const
|
|
65
|
-
const subtext = new TextDecoder().decode(
|
|
64
|
+
const subblob = cursor.read(subsize);
|
|
65
|
+
const subtext = new TextDecoder().decode(subblob);
|
|
66
66
|
record[subtext] = read(cursor);
|
|
67
67
|
}
|
|
68
68
|
return record;
|
|
@@ -70,97 +70,98 @@ export class Packed {
|
|
|
70
70
|
throw new Error("Non-decodable type");
|
|
71
71
|
}
|
|
72
72
|
Packed.read = read;
|
|
73
|
-
function size(
|
|
74
|
-
if (
|
|
73
|
+
function size(data) {
|
|
74
|
+
if (data == null)
|
|
75
75
|
return 1;
|
|
76
|
-
if (typeof
|
|
76
|
+
if (typeof data === "number")
|
|
77
77
|
return 1 + 8;
|
|
78
|
-
if (
|
|
79
|
-
return 1 + 4 +
|
|
80
|
-
if (typeof
|
|
81
|
-
return 1 + 4 + new TextEncoder().encode(
|
|
82
|
-
if (typeof
|
|
83
|
-
const absolute =
|
|
78
|
+
if (data instanceof Uint8Array)
|
|
79
|
+
return 1 + 4 + data.length;
|
|
80
|
+
if (typeof data === "string")
|
|
81
|
+
return 1 + 4 + new TextEncoder().encode(data).length;
|
|
82
|
+
if (typeof data === "bigint") {
|
|
83
|
+
const absolute = data < 0n ? -data : data;
|
|
84
84
|
const text = absolute.toString(16);
|
|
85
|
-
const
|
|
86
|
-
return 1 + 1 + 4 +
|
|
85
|
+
const blob = Uint8Array.fromHex(text.length % 2 === 1 ? "0" + text : text);
|
|
86
|
+
return 1 + 1 + 4 + blob.length;
|
|
87
87
|
}
|
|
88
|
-
if (Array.isArray(
|
|
88
|
+
if (Array.isArray(data)) {
|
|
89
89
|
let total = 0;
|
|
90
90
|
total += 1;
|
|
91
91
|
total += 4;
|
|
92
|
-
for (const
|
|
93
|
-
total += size(
|
|
92
|
+
for (const subdata of data)
|
|
93
|
+
total += size(subdata);
|
|
94
94
|
return total;
|
|
95
95
|
}
|
|
96
|
-
if (typeof
|
|
96
|
+
if (typeof data === "object") {
|
|
97
|
+
const entries = Object.entries(data);
|
|
97
98
|
let total = 0;
|
|
98
99
|
total += 1;
|
|
99
100
|
total += 4;
|
|
100
|
-
for (const subtext
|
|
101
|
-
const
|
|
101
|
+
for (const [subtext, subdata] of entries) {
|
|
102
|
+
const subblob = new TextEncoder().encode(subtext);
|
|
102
103
|
total += 4;
|
|
103
|
-
total +=
|
|
104
|
-
total += size(
|
|
104
|
+
total += subblob.length;
|
|
105
|
+
total += size(subdata);
|
|
105
106
|
}
|
|
106
107
|
return total;
|
|
107
108
|
}
|
|
108
|
-
throw new Error("Non-encodable
|
|
109
|
+
throw new Error("Non-encodable data");
|
|
109
110
|
}
|
|
110
111
|
Packed.size = size;
|
|
111
|
-
function write(
|
|
112
|
-
if (
|
|
112
|
+
function write(data, cursor) {
|
|
113
|
+
if (data == null) {
|
|
113
114
|
cursor.writeUint8(0);
|
|
114
115
|
return;
|
|
115
116
|
}
|
|
116
|
-
if (typeof
|
|
117
|
+
if (typeof data === "number") {
|
|
117
118
|
cursor.writeUint8(1);
|
|
118
|
-
cursor.writeFloat64(
|
|
119
|
+
cursor.writeFloat64(data);
|
|
119
120
|
return;
|
|
120
121
|
}
|
|
121
|
-
if (
|
|
122
|
+
if (data instanceof Uint8Array) {
|
|
122
123
|
cursor.writeUint8(2);
|
|
123
|
-
cursor.writeUint32(
|
|
124
|
-
cursor.write(
|
|
124
|
+
cursor.writeUint32(data.length);
|
|
125
|
+
cursor.write(data);
|
|
125
126
|
return;
|
|
126
127
|
}
|
|
127
|
-
if (typeof
|
|
128
|
+
if (typeof data === "string") {
|
|
128
129
|
cursor.writeUint8(3);
|
|
129
|
-
const
|
|
130
|
-
cursor.writeUint32(
|
|
131
|
-
cursor.write(
|
|
130
|
+
const blob = new TextEncoder().encode(data);
|
|
131
|
+
cursor.writeUint32(blob.length);
|
|
132
|
+
cursor.write(blob);
|
|
132
133
|
return;
|
|
133
134
|
}
|
|
134
|
-
if (typeof
|
|
135
|
+
if (typeof data === "bigint") {
|
|
135
136
|
cursor.writeUint8(4);
|
|
136
|
-
const [negative, absolute] =
|
|
137
|
+
const [negative, absolute] = data < 0n ? [1, -data] : [0, data];
|
|
137
138
|
const text = absolute.toString(16);
|
|
138
|
-
const
|
|
139
|
+
const blob = Uint8Array.fromHex(text.length % 2 === 1 ? "0" + text : text);
|
|
139
140
|
cursor.writeUint8(negative);
|
|
140
|
-
cursor.writeUint32(
|
|
141
|
-
cursor.write(
|
|
141
|
+
cursor.writeUint32(blob.length);
|
|
142
|
+
cursor.write(blob);
|
|
142
143
|
return;
|
|
143
144
|
}
|
|
144
|
-
if (Array.isArray(
|
|
145
|
+
if (Array.isArray(data)) {
|
|
145
146
|
cursor.writeUint8(5);
|
|
146
|
-
cursor.writeUint32(
|
|
147
|
-
for (const
|
|
148
|
-
write(
|
|
147
|
+
cursor.writeUint32(data.length);
|
|
148
|
+
for (const subdata of data)
|
|
149
|
+
write(subdata, cursor);
|
|
149
150
|
return;
|
|
150
151
|
}
|
|
151
|
-
if (typeof
|
|
152
|
-
const
|
|
152
|
+
if (typeof data === "object") {
|
|
153
|
+
const entries = Object.entries(data);
|
|
153
154
|
cursor.writeUint8(6);
|
|
154
|
-
cursor.writeUint32(
|
|
155
|
-
for (const subtext of
|
|
156
|
-
const
|
|
157
|
-
cursor.writeUint32(
|
|
158
|
-
cursor.write(
|
|
159
|
-
write(
|
|
155
|
+
cursor.writeUint32(entries.length);
|
|
156
|
+
for (const [subtext, subdata] of entries) {
|
|
157
|
+
const subblob = new TextEncoder().encode(subtext);
|
|
158
|
+
cursor.writeUint32(subblob.length);
|
|
159
|
+
cursor.write(subblob);
|
|
160
|
+
write(subdata, cursor);
|
|
160
161
|
}
|
|
161
162
|
return;
|
|
162
163
|
}
|
|
163
|
-
throw new Error("Non-encodable
|
|
164
|
+
throw new Error("Non-encodable data");
|
|
164
165
|
}
|
|
165
166
|
Packed.write = write;
|
|
166
167
|
})(Packed || (Packed = {}));
|
package/package.json
CHANGED