@thi.ng/leb128 3.0.88 → 3.1.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.
- package/CHANGELOG.md +11 -1
- package/README.md +16 -9
- package/index.d.ts +13 -13
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
- **Last updated**: 2024-04-
|
|
3
|
+
- **Last updated**: 2024-04-20T14:42:45Z
|
|
4
4
|
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
|
|
5
5
|
|
|
6
6
|
All notable changes to this project will be documented in this file.
|
|
@@ -9,6 +9,16 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
|
|
|
9
9
|
**Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
|
|
10
10
|
and/or version bumps of transitive dependencies.
|
|
11
11
|
|
|
12
|
+
## [3.1.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/leb128@3.1.0) (2024-04-20)
|
|
13
|
+
|
|
14
|
+
#### 🚀 Features
|
|
15
|
+
|
|
16
|
+
- update docs, add encode[SU]LEB128Into() fns ([44f927b](https://github.com/thi-ng/umbrella/commit/44f927b))
|
|
17
|
+
- update/fix doc strings
|
|
18
|
+
- retroactively document new functions by @jtenner's PR ([#460](https://github.com/thi-ng/umbrella/issues/460))
|
|
19
|
+
- add encodeSLEB128Into()
|
|
20
|
+
- add encodeULEB128Into()
|
|
21
|
+
|
|
12
22
|
### [3.0.47](https://github.com/thi-ng/umbrella/tree/@thi.ng/leb128@3.0.47) (2023-11-09)
|
|
13
23
|
|
|
14
24
|
#### ♻️ Refactoring
|
package/README.md
CHANGED
|
@@ -39,8 +39,9 @@ environments. The source code of the actual implementation (written in
|
|
|
39
39
|
All public functions throw an error if the WASM module could not be
|
|
40
40
|
initialized.
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
The `encodeSLEB128Into()` and `encodeULEB128Into()` functions will check the
|
|
43
|
+
bounds of the target array to ensure all bytes can be written and will
|
|
44
|
+
throw an error if the result would go out of bounds.
|
|
44
45
|
|
|
45
46
|
References:
|
|
46
47
|
|
|
@@ -77,10 +78,10 @@ import * as leb from "@thi.ng/leb128";
|
|
|
77
78
|
Browser ESM import:
|
|
78
79
|
|
|
79
80
|
```html
|
|
80
|
-
<script type="module" src="https://
|
|
81
|
+
<script type="module" src="https://esm.run/@thi.ng/leb128"></script>
|
|
81
82
|
```
|
|
82
83
|
|
|
83
|
-
[
|
|
84
|
+
[JSDelivr documentation](https://www.jsdelivr.com/)
|
|
84
85
|
|
|
85
86
|
For Node.js REPL:
|
|
86
87
|
|
|
@@ -100,29 +101,35 @@ Package sizes (brotli'd, pre-treeshake): ESM: 968 bytes
|
|
|
100
101
|
|
|
101
102
|
[Generated API docs](https://docs.thi.ng/umbrella/leb128/)
|
|
102
103
|
|
|
103
|
-
```ts
|
|
104
|
+
```ts tangle:export/readme1.ts
|
|
104
105
|
import * as leb from "@thi.ng/leb128";
|
|
105
106
|
|
|
106
107
|
// if WASM is unavailable, the encode/decode functions will throw an error
|
|
107
|
-
|
|
108
|
+
let encoded = leb.encodeULEB128(Number.MAX_SAFE_INTEGER);
|
|
109
|
+
|
|
110
|
+
console.log(encoded);
|
|
108
111
|
// Uint8Array [ 255, 255, 255, 255, 255, 255, 255, 15 ]
|
|
109
112
|
|
|
110
113
|
// decoding returns tuple of [value (bigint), bytes consumed]
|
|
111
|
-
leb.decodeULEB128(
|
|
114
|
+
console.log(leb.decodeULEB128(encoded));
|
|
112
115
|
// [ 9007199254740991n, 8 ]
|
|
113
116
|
|
|
114
117
|
// encode signed int
|
|
115
|
-
|
|
118
|
+
encoded = leb.encodeSLEB128(Number.MIN_SAFE_INTEGER);
|
|
119
|
+
|
|
120
|
+
console.log(encoded)
|
|
116
121
|
// Uint8Array [ 129, 128, 128, 128, 128, 128, 128, 112 ]
|
|
117
122
|
|
|
118
|
-
leb.decodeSLEB128(
|
|
123
|
+
console.log(leb.decodeSLEB128(encoded));
|
|
119
124
|
// [ -9007199254740991n, 8 ]
|
|
120
125
|
|
|
121
126
|
// when writing into an existing buffer, there needs to be enough bytes to write the value
|
|
122
127
|
const target = new Uint8Array(10);
|
|
123
128
|
const count = leb.encodeULEB128Into(target, Number.MAX_SAFE_INTEGER);
|
|
129
|
+
|
|
124
130
|
console.log(target);
|
|
125
131
|
// Uint8Array [ 255, 255, 255, 255, 255, 255, 255, 15, 0, 0 ]
|
|
132
|
+
|
|
126
133
|
console.log(count);
|
|
127
134
|
// 8
|
|
128
135
|
```
|
package/index.d.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Encodes signed integer `x` into LEB128 varint format and returns
|
|
3
|
-
*
|
|
2
|
+
* Encodes signed integer `x` into LEB128 varint format and returns encoded
|
|
3
|
+
* bytes. Values will be coerced to i64 range prior to encoding.
|
|
4
4
|
*
|
|
5
5
|
* @param x -
|
|
6
6
|
*/
|
|
7
7
|
export declare const encodeSLEB128: (x: bigint | number) => Uint8Array;
|
|
8
8
|
/**
|
|
9
|
-
* Takes Uint8Array with LEB128 encoded signed varint and an optional
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Takes an `Uint8Array` with LEB128 encoded signed varint and an optional start
|
|
10
|
+
* index to decode from. Returns 2-tuple of decoded value and number of bytes
|
|
11
|
+
* consumed. Consumes up to 10 bytes from `src`.
|
|
12
12
|
*
|
|
13
13
|
* @param src -
|
|
14
14
|
* @param idx -
|
|
15
15
|
*/
|
|
16
16
|
export declare const decodeSLEB128: (src: Uint8Array, idx?: number) => [bigint, number];
|
|
17
17
|
/**
|
|
18
|
-
* Takes a destination Uint8Array
|
|
19
|
-
* position to encode an LEB128 formatted byte sequence into the
|
|
20
|
-
* Returns the number of bytes written.
|
|
18
|
+
* Takes a destination `Uint8Array`, a signed integer `x`, and an optional
|
|
19
|
+
* index/position to encode an LEB128 formatted byte sequence into the
|
|
20
|
+
* destination. Returns the number of bytes written.
|
|
21
21
|
*
|
|
22
22
|
* @remarks
|
|
23
23
|
* Also see {@link encodeSLEB128}.
|
|
@@ -28,16 +28,16 @@ export declare const decodeSLEB128: (src: Uint8Array, idx?: number) => [bigint,
|
|
|
28
28
|
*/
|
|
29
29
|
export declare const encodeSLEB128Into: (dst: Uint8Array, x: bigint | number, pos?: number) => number;
|
|
30
30
|
/**
|
|
31
|
-
* Encodes unsigned integer `x` into LEB128 varint format and returns
|
|
32
|
-
*
|
|
31
|
+
* Encodes unsigned integer `x` into LEB128 varint format and returns encoded
|
|
32
|
+
* bytes. Values will be coerced to u64 range prior to encoding.
|
|
33
33
|
*
|
|
34
34
|
* @param x -
|
|
35
35
|
*/
|
|
36
36
|
export declare const encodeULEB128: (x: bigint | number) => Uint8Array;
|
|
37
37
|
/**
|
|
38
|
-
* Takes Uint8Array with LEB128 encoded unsigned varint and an optional
|
|
39
|
-
* start index to decode from. Returns 2-tuple of decoded value and
|
|
40
|
-
*
|
|
38
|
+
* Takes an `Uint8Array` with LEB128 encoded unsigned varint and an optional
|
|
39
|
+
* start index to decode from. Returns 2-tuple of decoded value and number of
|
|
40
|
+
* bytes consumed. Consumes up to 10 bytes from `src`.
|
|
41
41
|
*
|
|
42
42
|
* @param src -
|
|
43
43
|
* @param idx -
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/leb128",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "WASM based LEB128 encoder / decoder (signed & unsigned)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@thi.ng/checks": "^3.6.
|
|
44
|
-
"@thi.ng/errors": "^2.5.
|
|
45
|
-
"@thi.ng/transducers-binary": "^2.1.
|
|
43
|
+
"@thi.ng/checks": "^3.6.2",
|
|
44
|
+
"@thi.ng/errors": "^2.5.5",
|
|
45
|
+
"@thi.ng/transducers-binary": "^2.1.117"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@microsoft/api-extractor": "^7.43.0",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"alias": "leb",
|
|
86
86
|
"year": 2019
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "8339d05ecc857e529c7325a9839c0063b89e728d\n"
|
|
89
89
|
}
|