bun-types-no-globals 1.3.7-canary.20260122T141344 → 1.3.7-canary.20260124T140613
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/lib/bun.d.ts +95 -0
- package/package.json +1 -1
package/lib/bun.d.ts
CHANGED
|
@@ -743,6 +743,101 @@ declare module "bun" {
|
|
|
743
743
|
export function parse(input: string): unknown;
|
|
744
744
|
}
|
|
745
745
|
|
|
746
|
+
/**
|
|
747
|
+
* JSONL (JSON Lines) related APIs.
|
|
748
|
+
*
|
|
749
|
+
* Each line in the input is expected to be a valid JSON value separated by newlines.
|
|
750
|
+
*/
|
|
751
|
+
namespace JSONL {
|
|
752
|
+
/**
|
|
753
|
+
* The result of `Bun.JSONL.parseChunk`.
|
|
754
|
+
*/
|
|
755
|
+
interface ParseChunkResult {
|
|
756
|
+
/** The successfully parsed JSON values. */
|
|
757
|
+
values: unknown[];
|
|
758
|
+
/** How far into the input was consumed. When the input is a string, this is a character offset. When the input is a `TypedArray`, this is a byte offset. Use `input.slice(read)` or `input.subarray(read)` to get the unconsumed remainder. */
|
|
759
|
+
read: number;
|
|
760
|
+
/** `true` if all input was consumed successfully. `false` if the input ends with an incomplete value or a parse error occurred. */
|
|
761
|
+
done: boolean;
|
|
762
|
+
/** A `SyntaxError` if a parse error occurred, otherwise `null`. Values parsed before the error are still available in `values`. */
|
|
763
|
+
error: SyntaxError | null;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
/**
|
|
767
|
+
* Parse a JSONL (JSON Lines) string into an array of JavaScript values.
|
|
768
|
+
*
|
|
769
|
+
* If a parse error occurs and no values were successfully parsed, throws
|
|
770
|
+
* a `SyntaxError`. If values were parsed before the error, returns the
|
|
771
|
+
* successfully parsed values without throwing.
|
|
772
|
+
*
|
|
773
|
+
* Incomplete trailing values (e.g. from a partial chunk) are silently
|
|
774
|
+
* ignored and not included in the result.
|
|
775
|
+
*
|
|
776
|
+
* When a `TypedArray` is passed, the bytes are parsed directly without
|
|
777
|
+
* copying if the content is ASCII.
|
|
778
|
+
*
|
|
779
|
+
* @param input The JSONL string or typed array to parse
|
|
780
|
+
* @returns An array of parsed values
|
|
781
|
+
* @throws {SyntaxError} If the input starts with invalid JSON and no values could be parsed
|
|
782
|
+
*
|
|
783
|
+
* @example
|
|
784
|
+
* ```js
|
|
785
|
+
* const items = Bun.JSONL.parse('{"a":1}\n{"b":2}\n');
|
|
786
|
+
* // [{ a: 1 }, { b: 2 }]
|
|
787
|
+
*
|
|
788
|
+
* // From a Uint8Array (zero-copy for ASCII):
|
|
789
|
+
* const buf = new TextEncoder().encode('{"a":1}\n{"b":2}\n');
|
|
790
|
+
* const items = Bun.JSONL.parse(buf);
|
|
791
|
+
* // [{ a: 1 }, { b: 2 }]
|
|
792
|
+
*
|
|
793
|
+
* // Partial results on error after valid values:
|
|
794
|
+
* const partial = Bun.JSONL.parse('{"a":1}\n{bad}\n');
|
|
795
|
+
* // [{ a: 1 }]
|
|
796
|
+
*
|
|
797
|
+
* // Throws when no valid values precede the error:
|
|
798
|
+
* Bun.JSONL.parse('{bad}\n'); // throws SyntaxError
|
|
799
|
+
* ```
|
|
800
|
+
*/
|
|
801
|
+
export function parse(input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike): unknown[];
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Parse a JSONL chunk, designed for streaming use.
|
|
805
|
+
*
|
|
806
|
+
* Never throws on parse errors. Instead, returns whatever values were
|
|
807
|
+
* successfully parsed along with an `error` property containing the
|
|
808
|
+
* `SyntaxError` (or `null` on success). Use `read` to determine how
|
|
809
|
+
* much input was consumed and `done` to check if all input was parsed.
|
|
810
|
+
*
|
|
811
|
+
* When a `TypedArray` is passed, the bytes are parsed directly without
|
|
812
|
+
* copying if the content is ASCII. Optional `start` and `end` parameters
|
|
813
|
+
* allow slicing without copying, and `read` will be a byte offset into
|
|
814
|
+
* the original typed array.
|
|
815
|
+
*
|
|
816
|
+
* @param input The JSONL string or typed array to parse
|
|
817
|
+
* @param start Byte offset to start parsing from (typed array only, default: 0)
|
|
818
|
+
* @param end Byte offset to stop parsing at (typed array only, default: input.byteLength)
|
|
819
|
+
* @returns An object with `values`, `read`, `done`, and `error` properties
|
|
820
|
+
*
|
|
821
|
+
* @example
|
|
822
|
+
* ```js
|
|
823
|
+
* let buffer = new Uint8Array(0);
|
|
824
|
+
* for await (const chunk of stream) {
|
|
825
|
+
* buffer = Buffer.concat([buffer, chunk]);
|
|
826
|
+
* const { values, read, error } = Bun.JSONL.parseChunk(buffer);
|
|
827
|
+
* if (error) throw error;
|
|
828
|
+
* for (const value of values) handle(value);
|
|
829
|
+
* buffer = buffer.subarray(read);
|
|
830
|
+
* }
|
|
831
|
+
* ```
|
|
832
|
+
*/
|
|
833
|
+
export function parseChunk(input: string): ParseChunkResult;
|
|
834
|
+
export function parseChunk(
|
|
835
|
+
input: NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike,
|
|
836
|
+
start?: number,
|
|
837
|
+
end?: number,
|
|
838
|
+
): ParseChunkResult;
|
|
839
|
+
}
|
|
840
|
+
|
|
746
841
|
/**
|
|
747
842
|
* YAML related APIs
|
|
748
843
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bun-types-no-globals",
|
|
3
|
-
"version": "1.3.7-canary.
|
|
3
|
+
"version": "1.3.7-canary.20260124T140613",
|
|
4
4
|
"main": "./generator/index.ts",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"description": "TypeScript type definitions for Bun without global types pollution",
|