microcbor 1.0.0 → 1.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/README.md CHANGED
@@ -166,14 +166,16 @@ export class CBOREncoderStream extends TransformStream<CBORValue, Uint8Array> {
166
166
 
167
167
  ```ts
168
168
  /** Decode a single CBOR value. */
169
- export function decode(data: Uint8Array): CBORValue
169
+ export function decode<T extends CBORValue = CBORValue>(data: Uint8Array): T
170
170
  ```
171
171
 
172
172
  #### `decodeIterable`
173
173
 
174
174
  ```ts
175
175
  /** Decode an iterable of Uint8Array chunks into an iterable of CBOR values */
176
- export function* decodeIterable(source: Iterable<Uint8Array>): IterableIterator<CBORValue>
176
+ export function* decodeIterable<T extends CBORValue = CBORValue>(
177
+ source: Iterable<Uint8Array>,
178
+ ): IterableIterator<T>
177
179
 
178
180
  ```
179
181
 
@@ -181,14 +183,16 @@ export function* decodeIterable(source: Iterable<Uint8Array>): IterableIterator<
181
183
 
182
184
  ```ts
183
185
  /** Decode an async iterable of Uint8Array chunks into an async iterable of CBOR values */
184
- export async function* decodeAsyncIterable(source: AsyncIterable<Uint8Array>): AsyncIterable<CBORValue>
186
+ export async function* decodeAsyncIterable<T extends CBORValue = CBORValue>(
187
+ source: AsyncIterable<Uint8Array>,
188
+ ): AsyncIterable<CBORValue>
185
189
  ```
186
190
 
187
191
  #### `CBORDecoderStream`
188
192
 
189
193
  ```ts
190
194
  /** Decode a Web Streams API ReadableStream. */
191
- export class CBORDecoderStream extends TransformStream<Uint8Array, CBORValue> {
195
+ export class CBORDecoderStream<T extends CBORValue = CBORValue> extends TransformStream<Uint8Array, T> {
192
196
  public constructor()
193
197
  }
194
198
  ```
@@ -1,5 +1,5 @@
1
1
  import { CBORValue } from "./types.js";
2
2
  /** Decode a Web Streams API ReadableStream */
3
- export declare class CBORDecoderStream extends TransformStream<Uint8Array, CBORValue> {
3
+ export declare class CBORDecoderStream<T extends CBORValue = CBORValue> extends TransformStream<Uint8Array, T> {
4
4
  constructor();
5
5
  }
package/lib/Decoder.d.ts CHANGED
@@ -18,4 +18,4 @@ export declare class Decoder {
18
18
  decodeValue(): CBORValue;
19
19
  }
20
20
  /** Decode a single CBOR value */
21
- export declare function decode(data: Uint8Array): CBORValue;
21
+ export declare function decode<T extends CBORValue = CBORValue>(data: Uint8Array): T;
@@ -1,5 +1,5 @@
1
1
  import type { CBORValue } from "./types.js";
2
- export declare class Decoder implements AsyncIterableIterator<CBORValue> {
2
+ export declare class Decoder<T extends CBORValue = CBORValue> implements AsyncIterableIterator<T> {
3
3
  private offset;
4
4
  private byteLength;
5
5
  private readonly chunks;
@@ -29,7 +29,7 @@ export declare class Decoder implements AsyncIterableIterator<CBORValue> {
29
29
  value: undefined;
30
30
  } | {
31
31
  done: false;
32
- value: CBORValue;
32
+ value: T;
33
33
  }>;
34
34
  private decodeValue;
35
35
  }
@@ -121,7 +121,7 @@ export class Decoder {
121
121
  }
122
122
  }
123
123
  const value = await this.decodeValue();
124
- return { done: false, value };
124
+ return { done: false, value: value };
125
125
  }
126
126
  async decodeValue() {
127
127
  const initialByte = await this.uint8();
@@ -115,7 +115,7 @@ class Decoder {
115
115
  }
116
116
  }
117
117
  const value = this.decodeValue();
118
- return { done: false, value };
118
+ return { done: false, value: value };
119
119
  }
120
120
  decodeValue() {
121
121
  const initialByte = this.uint8();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "microcbor",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "lib"