vectorjson 0.3.2 → 0.4.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
@@ -454,6 +454,24 @@ result.status; // "complete" | "complete_early" | "incomplete" | "invalid"
454
454
  result.value.users; // lazy Proxy — materializes on access
455
455
  ```
456
456
 
457
+ ### JSONL & JSON5
458
+
459
+ Both `createParser` and `createEventParser` accept `format: "jsonl" | "json5"`:
460
+
461
+ ```js
462
+ // JSONL — yields each value separately
463
+ for await (const value of createParser({ format: "jsonl", source: stream })) {
464
+ console.log(value); // { user: "Alice" }, { user: "Bob" }, ...
465
+ }
466
+
467
+ // JSON5 — comments, trailing commas, unquoted keys, single-quoted strings, hex, Infinity/NaN
468
+ const p = createParser({ format: "json5" });
469
+ p.feed(`{ name: 'Alice', tags: ['admin',], color: 0xFF0000, timeout: Infinity, }`);
470
+ p.getValue(); // { name: "Alice", tags: ["admin"], color: 16711680, timeout: Infinity }
471
+ ```
472
+
473
+ JSONL push-based: call `resetForNext()` after each value. JSON5 comments are stripped at the byte level during streaming.
474
+
457
475
  ## API Reference
458
476
 
459
477
  ### Direct exports (recommended)
@@ -503,6 +521,7 @@ createParser({ schema, source }); // options object
503
521
  interface CreateParserOptions<T = unknown> {
504
522
  schema?: ZodLike<T>; // only parse schema fields, validate on complete
505
523
  source?: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array | string>;
524
+ format?: "json" | "jsonl" | "json5"; // default: "json"
506
525
  }
507
526
  ```
508
527
 
@@ -526,6 +545,7 @@ interface StreamingParser<T = unknown> {
526
545
  getRemaining(): Uint8Array | null;
527
546
  getRawBuffer(): ArrayBuffer | null; // transferable buffer for Worker postMessage
528
547
  getStatus(): FeedStatus;
548
+ resetForNext(): number; // JSONL: reset for next value, returns remaining byte count
529
549
  destroy(): void;
530
550
  [Symbol.asyncIterator](): AsyncIterableIterator<T | undefined>; // requires source
531
551
  }
@@ -581,7 +601,7 @@ createEventParser({ schema, source }); // schema + for-await
581
601
  {
582
602
  source?: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array | string>;
583
603
  schema?: ZodLike<T>; // only parse schema fields (same as createParser)
584
- // format?: "json" | "jsonl"; // planned — JSONL support for both parsers
604
+ format?: "json" | "jsonl" | "json5"; // default: "json"
585
605
  }
586
606
  ```
587
607
 
@@ -654,7 +674,7 @@ interface DeltaEvent {
654
674
  | **Schema** | Pass Zod/Valibot, only schema fields are parsed | Same |
655
675
  | **Skip non-JSON** (think tags, code fences, prose) | — | Always |
656
676
  | **Field subscriptions** | — | `on()`, `onDelta()` |
657
- | **JSONL** | `format: "jsonl"` (planned) | `format: "jsonl"` (planned) |
677
+ | **JSONL** | `format: "jsonl"` | `format: "jsonl"` |
658
678
  | **Text callbacks** | — | `onText()` |
659
679
 
660
680
  **`createParser` parses one JSON value** and reports status — you check it and react: