@thi.ng/leb128 3.0.88 → 3.1.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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2024-04-13T16:05:36Z
3
+ - **Last updated**: 2024-04-23T07:02:18Z
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
- All encodeInto functions will check the bounds of the target array to
43
- make sure all the bytes can be written.
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://cdn.skypack.dev/@thi.ng/leb128"></script>
81
+ <script type="module" src="https://esm.run/@thi.ng/leb128"></script>
81
82
  ```
82
83
 
83
- [Skypack documentation](https://docs.skypack.dev/)
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
- enc = leb.encodeULEB128(Number.MAX_SAFE_INTEGER);
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(enc);
114
+ console.log(leb.decodeULEB128(encoded));
112
115
  // [ 9007199254740991n, 8 ]
113
116
 
114
117
  // encode signed int
115
- enc = leb.encodeSLEB128(Number.MIN_SAFE_INTEGER);
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(enc);
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
- * encoded bytes.
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
- * start index to decode from. Returns 2-tuple of decoded value and
11
- * number of bytes consumed. Consumes up to 10 bytes from `src`.
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, a signed integer `x`, and an optional
19
- * position to encode an LEB128 formatted byte sequence into the destination.
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
- * encoded bytes. Values < 0 will be encoded as zero.
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
- * number of bytes consumed. Consumes up to 10 bytes from `src`.
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.88",
3
+ "version": "3.1.1",
4
4
  "description": "WASM based LEB128 encoder / decoder (signed & unsigned)",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -31,7 +31,7 @@
31
31
  "build:binary": "tools/build-binary.sh",
32
32
  "build:decl": "tsc --declaration --emitDeclarationOnly",
33
33
  "build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
34
- "clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
34
+ "clean": "bun ../../tools/src/clean-package.ts",
35
35
  "doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
36
36
  "doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
37
37
  "doc:readme": "bun ../../tools/src/module-stats.ts && bun ../../tools/src/readme.ts",
@@ -40,14 +40,13 @@
40
40
  "tool:tangle": "../../node_modules/.bin/tangle src/**/*.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@thi.ng/checks": "^3.6.1",
44
- "@thi.ng/errors": "^2.5.4",
45
- "@thi.ng/transducers-binary": "^2.1.116"
43
+ "@thi.ng/checks": "^3.6.3",
44
+ "@thi.ng/errors": "^2.5.6",
45
+ "@thi.ng/transducers-binary": "^2.1.118"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@microsoft/api-extractor": "^7.43.0",
49
49
  "esbuild": "^0.20.2",
50
- "rimraf": "^5.0.5",
51
50
  "typedoc": "^0.25.12",
52
51
  "typescript": "^5.4.3"
53
52
  },
@@ -85,5 +84,5 @@
85
84
  "alias": "leb",
86
85
  "year": 2019
87
86
  },
88
- "gitHead": "fd7ab12d565809a2300783881c62b883dbd25c23\n"
87
+ "gitHead": "5dd66c18a3862a3af69a5b2f49563f7cbdd960c2\n"
89
88
  }