@litert/base32 1.0.0

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.
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025 Angus.Fenying <fenying@litert.org>
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.PADDING = void 0;
19
+ exports.bufferToBase32 = bufferToBase32;
20
+ exports.bufferFromBase32 = bufferFromBase32;
21
+ exports.stringToBase32 = stringToBase32;
22
+ exports.stringFromBase32 = stringFromBase32;
23
+ const BASE32_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
24
+ const BITS_TO_CHARS = Buffer.from(BASE32_CHARS);
25
+ const CHARS_TO_BITS = {};
26
+ for (let i = 0; i < BASE32_CHARS.length; i++) {
27
+ CHARS_TO_BITS[BASE32_CHARS[i]] = i;
28
+ }
29
+ exports.PADDING = '='.charCodeAt(0);
30
+ /**
31
+ * Encode a `Buffer` to a BASE32-encoded string.
32
+ *
33
+ * @param data The `Buffer` to be encoded.
34
+ *
35
+ * @returns The BASE32 encoded string.
36
+ *
37
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
38
+ */
39
+ function bufferToBase32(data) {
40
+ const ret = Buffer.alloc(Math.ceil(data.length / 5) * 8);
41
+ for (let i = 0, j = 0; i < data.length; i += 5) {
42
+ switch (data.length - i) {
43
+ case 1:
44
+ /**
45
+ * 11111 111|00 00000 0|0000 0000|0 00000 00|000 00000
46
+ */
47
+ ret[j++] = BITS_TO_CHARS[data[i] >> 3];
48
+ ret[j++] = BITS_TO_CHARS[(data[i] & 0x07) << 2];
49
+ ret[j++] = exports.PADDING;
50
+ ret[j++] = exports.PADDING;
51
+ ret[j++] = exports.PADDING;
52
+ ret[j++] = exports.PADDING;
53
+ ret[j++] = exports.PADDING;
54
+ ret[j++] = exports.PADDING;
55
+ break;
56
+ case 2:
57
+ /**
58
+ * 11111 111|11 11111 1|0000 0000|0 00000 00|000 00000
59
+ */
60
+ ret[j++] = BITS_TO_CHARS[data[i] >> 3];
61
+ ret[j++] = BITS_TO_CHARS[((data[i] & 0x07) << 2) | (data[i + 1] >> 6)];
62
+ ret[j++] = BITS_TO_CHARS[(data[i + 1] >> 1) & 0x1F];
63
+ ret[j++] = BITS_TO_CHARS[(data[i + 1] & 0x01) << 4];
64
+ ret[j++] = exports.PADDING;
65
+ ret[j++] = exports.PADDING;
66
+ ret[j++] = exports.PADDING;
67
+ ret[j++] = exports.PADDING;
68
+ break;
69
+ case 3:
70
+ /**
71
+ * 11111 111|11 11111 1|1111 1111|0 00000 00|000 00000
72
+ */
73
+ ret[j++] = BITS_TO_CHARS[data[i] >> 3];
74
+ ret[j++] = BITS_TO_CHARS[((data[i] & 0x07) << 2) | (data[i + 1] >> 6)];
75
+ ret[j++] = BITS_TO_CHARS[(data[i + 1] >> 1) & 0x1F];
76
+ ret[j++] = BITS_TO_CHARS[((data[i + 1] & 0x01) << 4) | (data[i + 2] >> 4)];
77
+ ret[j++] = BITS_TO_CHARS[(data[i + 2] & 0x0F) << 1];
78
+ ret[j++] = exports.PADDING;
79
+ ret[j++] = exports.PADDING;
80
+ ret[j++] = exports.PADDING;
81
+ break;
82
+ case 4:
83
+ /**
84
+ * 11111 111|11 11111 1|1111 1111|1 11111 11|000 00000
85
+ */
86
+ ret[j++] = BITS_TO_CHARS[data[i] >> 3];
87
+ ret[j++] = BITS_TO_CHARS[((data[i] & 0x07) << 2) | (data[i + 1] >> 6)];
88
+ ret[j++] = BITS_TO_CHARS[(data[i + 1] >> 1) & 0x1F];
89
+ ret[j++] = BITS_TO_CHARS[((data[i + 1] & 0x01) << 4) | (data[i + 2] >> 4)];
90
+ ret[j++] = BITS_TO_CHARS[((data[i + 2] & 0x0F) << 1) | (data[i + 3] >> 7)];
91
+ ret[j++] = BITS_TO_CHARS[(data[i + 3] >> 2) & 0x1F];
92
+ ret[j++] = BITS_TO_CHARS[(data[i + 3] & 0x03) << 3];
93
+ ret[j++] = exports.PADDING;
94
+ break;
95
+ default: // >= 5
96
+ /**
97
+ * 11111 111|11 11111 1|1111 1111|1 11111 11|111 11111
98
+ */
99
+ ret[j++] = BITS_TO_CHARS[data[i] >> 3];
100
+ ret[j++] = BITS_TO_CHARS[((data[i] & 0x07) << 2) | (data[i + 1] >> 6)];
101
+ ret[j++] = BITS_TO_CHARS[(data[i + 1] >> 1) & 0x1F];
102
+ ret[j++] = BITS_TO_CHARS[((data[i + 1] & 0x01) << 4) | (data[i + 2] >> 4)];
103
+ ret[j++] = BITS_TO_CHARS[((data[i + 2] & 0x0F) << 1) | (data[i + 3] >> 7)];
104
+ ret[j++] = BITS_TO_CHARS[(data[i + 3] >> 2) & 0x1F];
105
+ ret[j++] = BITS_TO_CHARS[((data[i + 3] & 0x03) << 3) | (data[i + 4] >> 5)];
106
+ ret[j++] = BITS_TO_CHARS[data[i + 4] & 0x1F];
107
+ break;
108
+ }
109
+ }
110
+ return ret.toString();
111
+ }
112
+ /**
113
+ * Decode a BASE32-encoded string into a `Buffer`.
114
+ *
115
+ * @param input The BASE32-encoded string to be decoded.
116
+ *
117
+ * @returns The decoded `Buffer`.
118
+ *
119
+ * @throws `RangeError` if the input is not a valid BASE32-encoded string.
120
+ *
121
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
122
+ */
123
+ function bufferFromBase32(input) {
124
+ if (input.length & 0x7) {
125
+ throw new RangeError('Unrecognizable base32 input.');
126
+ }
127
+ const ret = Buffer.allocUnsafe(input.length / 8 * 5);
128
+ for (let i = 0, j = 0; i < input.length; i += 8) {
129
+ let padFrom = 0;
130
+ if (input[i + 7] === '=') {
131
+ if (input[i + 8] !== undefined) {
132
+ throw new RangeError('Unrecognizable base32 input.');
133
+ }
134
+ padFrom = input.indexOf('=', i) - i;
135
+ }
136
+ switch (padFrom) {
137
+ case 0: // no padding
138
+ /**
139
+ * 11111 111|11 11111 1|1111 1111|1 11111 11|111 11111
140
+ */
141
+ ret[j++] = (CHARS_TO_BITS[input[i]] << 3) | (CHARS_TO_BITS[input[i + 1]] >> 2);
142
+ ret[j++] = ((CHARS_TO_BITS[input[i + 1]] & 0x03) << 6)
143
+ | (CHARS_TO_BITS[input[i + 2]] << 1)
144
+ | (CHARS_TO_BITS[input[i + 3]] >> 4);
145
+ ret[j++] = ((CHARS_TO_BITS[input[i + 3]] & 0x0F) << 4)
146
+ | (CHARS_TO_BITS[input[i + 4]] >> 1);
147
+ ret[j++] = ((CHARS_TO_BITS[input[i + 4]] & 0x01) << 7)
148
+ | (CHARS_TO_BITS[input[i + 5]] << 2)
149
+ | (CHARS_TO_BITS[input[i + 6]] >> 3);
150
+ ret[j++] = ((CHARS_TO_BITS[input[i + 6]] & 0x07) << 5)
151
+ | CHARS_TO_BITS[input[i + 7]];
152
+ break;
153
+ case 7: // 1 padding
154
+ /**
155
+ * 11111 111|11 11111 1|1111 1111|1 11111 11|000 00000
156
+ */
157
+ ret[j++] = (CHARS_TO_BITS[input[i]] << 3) | (CHARS_TO_BITS[input[i + 1]] >> 2);
158
+ ret[j++] = ((CHARS_TO_BITS[input[i + 1]] & 0x03) << 6)
159
+ | (CHARS_TO_BITS[input[i + 2]] << 1)
160
+ | (CHARS_TO_BITS[input[i + 3]] >> 4);
161
+ ret[j++] = ((CHARS_TO_BITS[input[i + 3]] & 0x0F) << 4)
162
+ | (CHARS_TO_BITS[input[i + 4]] >> 1);
163
+ ret[j++] = ((CHARS_TO_BITS[input[i + 4]] & 0x01) << 7)
164
+ | (CHARS_TO_BITS[input[i + 5]] << 2)
165
+ | (CHARS_TO_BITS[input[i + 6]] >> 3);
166
+ return ret.subarray(0, -1);
167
+ case 5: // 3 padding
168
+ /**
169
+ * 11111 111|11 11111 1|1111 1111|0 00000 00|000 00000
170
+ */
171
+ ret[j++] = (CHARS_TO_BITS[input[i]] << 3) | (CHARS_TO_BITS[input[i + 1]] >> 2);
172
+ ret[j++] = ((CHARS_TO_BITS[input[i + 1]] & 0x03) << 6)
173
+ | (CHARS_TO_BITS[input[i + 2]] << 1)
174
+ | (CHARS_TO_BITS[input[i + 3]] >> 4);
175
+ ret[j++] = ((CHARS_TO_BITS[input[i + 3]] & 0x0F) << 4)
176
+ | (CHARS_TO_BITS[input[i + 4]] >> 1);
177
+ return ret.subarray(0, -2);
178
+ case 4: // 4 padding
179
+ /**
180
+ * 11111 111|11 11111 1|0000 0000|0 00000 00|000 00000
181
+ */
182
+ ret[j++] = (CHARS_TO_BITS[input[i]] << 3) | (CHARS_TO_BITS[input[i + 1]] >> 2);
183
+ ret[j++] = ((CHARS_TO_BITS[input[i + 1]] & 0x03) << 6)
184
+ | (CHARS_TO_BITS[input[i + 2]] << 1)
185
+ | (CHARS_TO_BITS[input[i + 3]] >> 4);
186
+ return ret.subarray(0, -3);
187
+ case 2: // 6 padding
188
+ /**
189
+ * 11111 111|00 00000 0|0000 0000|0 00000 00|000 00000
190
+ */
191
+ ret[j++] = (CHARS_TO_BITS[input[i]] << 3) | (CHARS_TO_BITS[input[i + 1]] >> 2);
192
+ return ret.subarray(0, -4);
193
+ default:
194
+ throw new RangeError('Unrecognizable base32 input.');
195
+ }
196
+ }
197
+ return ret;
198
+ }
199
+ /**
200
+ * Encode a UTF-8 string into a BASE32-encoded string.
201
+ *
202
+ * > This method transform the input string into a `Buffer`, and then calls `bufferToBase32`.
203
+ *
204
+ * @param data The string to be encoded.
205
+ *
206
+ * @returns The BASE32-encoded string.
207
+ *
208
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
209
+ */
210
+ function stringToBase32(data) {
211
+ return bufferToBase32(Buffer.from(data));
212
+ }
213
+ /**
214
+ * Decode a BASE32-encoded string into a UTF-8 string.
215
+ *
216
+ * > This method calls `bufferFromBase32` to decode the input string into a `Buffer`, and then
217
+ * > converts it to a UTF-8 string.
218
+ *
219
+ * @param data The BASE32-encoded string to be decoded.
220
+ *
221
+ * @returns The decoded UTF-8 string.
222
+ *
223
+ * @throws `RangeError` if the input is not a valid BASE32-encoded string.
224
+ *
225
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
226
+ */
227
+ function stringFromBase32(data) {
228
+ return bufferFromBase32(data).toString();
229
+ }
230
+ //# sourceMappingURL=base32-js.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base32-js.js","sourceRoot":"","sources":["../src/lib/base32-js.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAwBH,wCAgFC;AAaD,4CAqGC;AAaD,wCAGC;AAgBD,4CAGC;AA3PD,MAAM,YAAY,GAAG,kCAAkC,CAAC;AAExD,MAAM,aAAa,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAEhD,MAAM,aAAa,GAA2B,EAAE,CAAC;AAEjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;IAE3C,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC;AAEY,QAAA,OAAO,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;AAEzC;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAAC,IAAY;IAEvC,MAAM,GAAG,GAAW,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IAEjE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,C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32`.
5
+ *
6
+ * @param data The string to be encoded.
7
+ *
8
+ * @returns The BASE32-encoded string.
9
+ *
10
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
11
+ */
12
+ export declare const stringToBase32: (data: string) => string;
13
+ /**
14
+ * Decode a BASE32-encoded string into a UTF-8 string.
15
+ *
16
+ * > This method calls `bufferFromBase32` to decode the input string into a `Buffer`, and then
17
+ * > converts it to a UTF-8 string.
18
+ *
19
+ * @param data The BASE32-encoded string to be decoded.
20
+ *
21
+ * @returns The decoded UTF-8 string.
22
+ *
23
+ * @throws `RangeError` if the input is not a valid BASE32-encoded string.
24
+ *
25
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
26
+ */
27
+ export declare const stringFromBase32: (data: string) => string;
28
+ /**
29
+ * Encode a `Buffer` to a BASE32-encoded string.
30
+ *
31
+ * @param data The `Buffer` to be encoded.
32
+ *
33
+ * @returns The BASE32 encoded string.
34
+ *
35
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
36
+ */
37
+ export declare const bufferToBase32: (data: Buffer) => string;
38
+ /**
39
+ * Decode a BASE32-encoded string into a `Buffer`.
40
+ *
41
+ * @param input The BASE32-encoded string to be decoded.
42
+ *
43
+ * @returns The decoded `Buffer`.
44
+ *
45
+ * @throws `RangeError` if the input is not a valid BASE32-encoded string.
46
+ *
47
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
48
+ */
49
+ export declare const bufferFromBase32: (input: string) => Buffer;
50
+ //# sourceMappingURL=base32-wasm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base32-wasm.d.ts","sourceRoot":"","sources":["../src/lib/base32-wasm.ts"],"names":[],"mappings":"AA+HA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,SAxBK,MAAM,KAAG,MAwBiB,CAAC;AAE3D;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,SAnCK,MAAM,KAAG,MAmCmB,CAAC;AAE/D;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,SAtGK,MAAM,KAAG,MAsGiB,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,UA9FM,MAAM,KAAG,MA8FkB,CAAC"}
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.bufferFromBase32 = exports.bufferToBase32 = exports.stringFromBase32 = exports.stringToBase32 = void 0;
37
+ /**
38
+ * Copyright 2025 Angus.Fenying <fenying@litert.org>
39
+ *
40
+ * Licensed under the Apache License, Version 2.0 (the "License");
41
+ * you may not use this file except in compliance with the License.
42
+ * You may obtain a copy of the License at
43
+ *
44
+ * https://www.apache.org/licenses/LICENSE-2.0
45
+ *
46
+ * Unless required by applicable law or agreed to in writing, software
47
+ * distributed under the License is distributed on an "AS IS" BASIS,
48
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
49
+ * See the License for the specific language governing permissions and
50
+ * limitations under the License.
51
+ */
52
+ const NodeFS = __importStar(require("node:fs"));
53
+ let wasmModule;
54
+ /**
55
+ * The encoder (and also the decoder) for base32 encoding,
56
+ * written in WebAssembly.
57
+ */
58
+ class WasmBase32Encoder {
59
+ /**
60
+ * Allocated pages for the WebAssembly memory.
61
+ * The initial value is 1, which means 64K memory is allocated.
62
+ *
63
+ * > A page in WebAssembly is 64 KiB (65536 bytes).
64
+ */
65
+ _allocPages = 1;
66
+ _wasmInst;
67
+ _apis;
68
+ constructor() {
69
+ wasmModule ??= new WebAssembly.Module(NodeFS.readFileSync(`${__dirname}/../wasm/base32.wasm`));
70
+ this._wasmInst = new WebAssembly.Instance(wasmModule, {});
71
+ this._apis = this._wasmInst.exports;
72
+ this._apis.memory.grow(1); // Allocate 64K memory for the first time.
73
+ this._apis.initTable();
74
+ }
75
+ bufferToBase32(data) {
76
+ const RMS = this._apis.getReserverMemorySize();
77
+ // Prepare memory for decoding: RMS + input length + expected output length.
78
+ // The expected output length is 8/5 of the input length.
79
+ // Then the most safe way is just using the 2x (10/5, 200%) as the expected output length,
80
+ // So, the final memory size will be: RMS + input length * 2 + input length.
81
+ const minMemPages = Math.ceil((RMS + data.byteLength * 3) / 65536);
82
+ if (minMemPages > this._allocPages) {
83
+ this._apis.memory.grow(minMemPages - this._allocPages);
84
+ this._allocPages = minMemPages;
85
+ }
86
+ data.copy(Buffer.from(this._apis.memory.buffer, RMS, data.byteLength));
87
+ const outLength = this._apis.encode(data.byteLength);
88
+ return Buffer.from(this._apis.memory.buffer, RMS + data.byteLength, outLength).toString('utf8');
89
+ }
90
+ bufferFromBase32(input) {
91
+ const RMS = this._apis.getReserverMemorySize();
92
+ const inLength = Buffer.byteLength(input);
93
+ // Prepare memory for decoding: RMS + input length + expected output length.
94
+ // The expected output length is 5/8 of the input length.
95
+ // So, to simplify the calculation, just use the same as the expected output length,
96
+ // So, the final memory size will be: RMS + input length * 2.
97
+ const minMemPages = Math.ceil((inLength * 2 + RMS) / 65536);
98
+ if (minMemPages > this._allocPages) {
99
+ this._apis.memory.grow(minMemPages - this._allocPages);
100
+ this._allocPages = minMemPages;
101
+ }
102
+ // copy the input string to the wasm memory (starting from RMS, ending at RMS + inLength).
103
+ Buffer.from(this._apis.memory.buffer, RMS, inLength).write(input);
104
+ const outLength = this._apis.decode(inLength);
105
+ if (outLength < 0) {
106
+ throw new TypeError('Invalid input data for base32 encoding.');
107
+ }
108
+ // read the result from the wasm memory (starting from RMS + inLength, ending at RMS + inLength + outLength).
109
+ return Buffer.from(this._apis.memory.buffer, RMS + inLength, outLength);
110
+ }
111
+ stringToBase32(data) {
112
+ return this.bufferToBase32(Buffer.from(data));
113
+ }
114
+ stringFromBase32(data) {
115
+ return this.bufferFromBase32(data).toString();
116
+ }
117
+ }
118
+ const enc = new WasmBase32Encoder();
119
+ /**
120
+ * Encode a UTF-8 string into a BASE32-encoded string.
121
+ *
122
+ * > This method transform the input string into a `Buffer`, and then calls `bufferToBase32`.
123
+ *
124
+ * @param data The string to be encoded.
125
+ *
126
+ * @returns The BASE32-encoded string.
127
+ *
128
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
129
+ */
130
+ exports.stringToBase32 = enc.stringToBase32.bind(enc);
131
+ /**
132
+ * Decode a BASE32-encoded string into a UTF-8 string.
133
+ *
134
+ * > This method calls `bufferFromBase32` to decode the input string into a `Buffer`, and then
135
+ * > converts it to a UTF-8 string.
136
+ *
137
+ * @param data The BASE32-encoded string to be decoded.
138
+ *
139
+ * @returns The decoded UTF-8 string.
140
+ *
141
+ * @throws `RangeError` if the input is not a valid BASE32-encoded string.
142
+ *
143
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
144
+ */
145
+ exports.stringFromBase32 = enc.stringFromBase32.bind(enc);
146
+ /**
147
+ * Encode a `Buffer` to a BASE32-encoded string.
148
+ *
149
+ * @param data The `Buffer` to be encoded.
150
+ *
151
+ * @returns The BASE32 encoded string.
152
+ *
153
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
154
+ */
155
+ exports.bufferToBase32 = enc.bufferToBase32.bind(enc);
156
+ /**
157
+ * Decode a BASE32-encoded string into a `Buffer`.
158
+ *
159
+ * @param input The BASE32-encoded string to be decoded.
160
+ *
161
+ * @returns The decoded `Buffer`.
162
+ *
163
+ * @throws `RangeError` if the input is not a valid BASE32-encoded string.
164
+ *
165
+ * @see https://datatracker.ietf.org/doc/html/rfc4648#section-6
166
+ */
167
+ exports.bufferFromBase32 = enc.bufferFromBase32.bind(enc);
168
+ //# sourceMappingURL=base32-wasm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base32-wasm.js","sourceRoot":"","sources":["../src/lib/base32-wasm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,gDAAkC;AAElC,IAAI,UAA8B,CAAC;AAenC;;;GAGG;AACH,MAAM,iBAAiB;IAEnB;;;;;OAKG;IACK,WAAW,GAAW,CAAC,CAAC;IAEf,SAAS,CAAuB;IAEhC,KAAK,CAAY;IAElC;QAEI,UAAU,KAAK,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,SAAS,sBAAsB,CAAC,CAAC,CAAC;QAE/F,IAAI,CAAC,SAAS,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QAE1D,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAA+B,CAAC;QAE5D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,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BAAgB,GAAG,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/D;;;;;;;;GAQG;AACU,QAAA,cAAc,GAAG,GAAG,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE3D;;;;;;;;;;GAUG;AACU,QAAA,gBAAgB,GAAG,GAAG,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Copyright 2025 Angus.Fenying <fenying@litert.org>
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * https://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export * from './base32-wasm';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,cAAc,eAAe,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright 2025 Angus.Fenying <fenying@litert.org>
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
29
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./base32-wasm"), exports);
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/lib/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;AAEH,gDAA8B"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@litert/base32",
3
+ "version": "1.0.0",
4
+ "description": "The encoding and decoding library for BASE32, in JavaScript/TypeScript/WebAssembly.",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "types": "lib/index.d.ts",
8
+ "scripts": {
9
+ "prepublishOnly": "npm run build-md-doc && npm run build-wasm && npm run rebuild && npm run test",
10
+ "build": "echo Using TypeScript && tsc -v && tsc -p .",
11
+ "build-watch": "echo Using TypeScript && tsc -v && tsc -w -p .",
12
+ "build-wasm": "./utils/build-wasm.sh",
13
+ "build-md-doc": "./utils/generate-api-docs-md.sh",
14
+ "rebuild": "npm run clean && npm run lint && npm run build",
15
+ "test": "node --enable-source-maps --test --experimental-test-coverage lib/*.test.js",
16
+ "clean": "rm -rf lib examples",
17
+ "typecheck": "tsc -p tsconfig.json --noEmit",
18
+ "lint": "./utils/eslint.sh",
19
+ "prepare": "husky"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/litert/base32.js.git"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/litert/base32.js/issues"
27
+ },
28
+ "homepage": "https://github.com/litert/base32.js#readme",
29
+ "keywords": [
30
+ "litert",
31
+ "lrt",
32
+ "encodings",
33
+ "webassembly",
34
+ "wasm",
35
+ "base32"
36
+ ],
37
+ "author": "Angus.Fenying <fenying@litert.org> (https://fenying.net)",
38
+ "license": "Apache-2.0",
39
+ "devDependencies": {
40
+ "@commitlint/cli": "^19.6.1",
41
+ "@commitlint/config-conventional": "^19.6.0",
42
+ "@litert/eslint-plugin-rules": "^0.3.1",
43
+ "@types/node": "^22.10.2",
44
+ "assemblyscript": "^0.28.2",
45
+ "husky": "^9.1.7",
46
+ "typedoc": "^0.28.5",
47
+ "typedoc-plugin-markdown": "^4.6.4",
48
+ "typedoc-vitepress-theme": "^1.1.2",
49
+ "typescript": "^5.7.2"
50
+ },
51
+ "engines": {
52
+ "node": ">=18.0.0"
53
+ }
54
+ }