json-stream-lite 1.1.3 → 1.1.4

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
@@ -32,7 +32,7 @@ yarn add json-stream-lite
32
32
 
33
33
  ### Parsing JSON
34
34
 
35
- #### Parse a complete JSON object incrementally
35
+ #### Parse a complete JSON object
36
36
 
37
37
  ```typescript
38
38
  import { JsonObject } from 'json-stream-lite'
@@ -48,7 +48,7 @@ const result = parser.read()
48
48
  console.log(result) // { name: 'Alice', age: 30, active: true }
49
49
  ```
50
50
 
51
- #### Stream through object members
51
+ #### Stream through object members incrementally
52
52
 
53
53
  ```typescript
54
54
  import { JsonObject } from 'json-stream-lite'
@@ -1,4 +1,4 @@
1
- import type { ByteStream, JsonStreamInput } from './types.js';
1
+ import type { ByteStream, StreamInput } from './types.js';
2
2
  /**
3
3
  * A buffer for managing byte-level input with support for async streams.
4
4
  * Provides lookahead, consumption tracking, and buffer compaction capabilities.
@@ -49,7 +49,7 @@ export declare class ByteBuffer {
49
49
  *
50
50
  * @param input - Input items to add to the buffer
51
51
  */
52
- feed(...input: JsonStreamInput[]): void;
52
+ feed(...input: StreamInput[]): void;
53
53
  push(byte: number): void;
54
54
  /**
55
55
  * Checks if end of file has been reached and buffer is exhausted.
@@ -185,13 +185,11 @@ export class ByteBuffer {
185
185
  */
186
186
  next() {
187
187
  if (this.bufferIndex >= this.buffer.length) {
188
+ if (this.readStream()) {
189
+ return this.next();
190
+ }
188
191
  if (!this.eof) {
189
- if (!this.readStream()) {
190
- throw new NoMoreTokensError('No more items available');
191
- }
192
- else {
193
- return this.next();
194
- }
192
+ throw new NoMoreTokensError('No more items available');
195
193
  }
196
194
  throw new EofReachedError('End of file reached');
197
195
  }
package/dist/parser.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ByteBuffer } from './byte-buffer.js';
2
- import { ByteStream, JsonKeyValuePair, JsonStreamInput } from './types.js';
2
+ import { ByteStream, JsonKeyValuePair, StreamInput } from './types.js';
3
3
  /**
4
4
  * Abstract base class for all JSON entities.
5
5
  * Provides common functionality for parsing, reading, and consuming JSON values.
@@ -46,7 +46,7 @@ export declare abstract class JsonEntity<T> {
46
46
  *
47
47
  * @param input - One or more strings, numbers, arrays of numbers, or Uint8Arrays to add to the buffer
48
48
  */
49
- feed(...input: JsonStreamInput[]): void;
49
+ feed(...input: StreamInput[]): void;
50
50
  /**
51
51
  * Abstract method that subclasses must implement to parse their specific type.
52
52
  *
@@ -188,7 +188,7 @@ export declare class JsonNull extends JsonEntity<null> {
188
188
  */
189
189
  export type JsonPrimitiveType = JsonString | JsonNumber | JsonBoolean | JsonNull;
190
190
  /**
191
- * Union type representing any JSON value entity type (primitive, object, or array).
191
+ * Converts a standard JS primitive type into a json-stream-lite parser type
192
192
  *
193
193
  * @typeParam T - The expected type of the value
194
194
  */
package/dist/types.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  /**
2
- * Union type representing valid JSON stream input formats.
2
+ * Union type representing valid stream input formats.
3
3
  */
4
- export type JsonStreamInput = string | number | number[] | Uint8Array;
4
+ export type StreamInput = string | number | number[] | Uint8Array;
5
5
  /**
6
6
  * An async iterable stream of JSON input that can be consumed incrementally.
7
7
  * Supports strings, numbers, arrays of numbers, or Uint8Arrays as stream items.
8
8
  */
9
- export type ByteStream = AsyncIterable<JsonStreamInput> | Iterable<JsonStreamInput> | ReadableStream<JsonStreamInput>;
9
+ export type ByteStream = AsyncIterable<StreamInput> | Iterable<StreamInput> | ReadableStream<StreamInput>;
10
10
  /**
11
11
  * Union type representing all JSON primitive value types.
12
12
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-stream-lite",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "A lightweight, memory-efficient, zero-dependency streaming JSON parser and stringifier for JavaScript and TypeScript. It works in both Node.js and browser environments.",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",