bun-types-no-globals 1.3.14 → 1.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/lib/bun.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Bun.js runtime APIs
2
+ * Bun runtime APIs
3
3
  *
4
4
  * @example
5
5
  *
@@ -50,15 +50,10 @@ declare module "bun" {
50
50
  type LibDomIsLoaded = typeof globalThis extends { onabort: any } ? true : false;
51
51
 
52
52
  /**
53
- * Helper type for avoiding conflicts in types.
53
+ * Uses the lib.dom.d.ts definition of a global if it exists, otherwise falls back to `Otherwise`.
54
54
  *
55
- * Uses the lib.dom.d.ts definition if it exists, otherwise defines it locally.
56
- *
57
- * This is to avoid type conflicts between lib.dom.d.ts and \@types/bun.
58
- *
59
- * Unfortunately some symbols cannot be defined when both Bun types and lib.dom.d.ts types are loaded,
60
- * and since we can't redeclare the symbol in a way that satisfies both, we need to fallback
61
- * to the type that lib.dom.d.ts provides.
55
+ * Some symbols can't be declared in a way that satisfies both \@types/bun and lib.dom.d.ts,
56
+ * so when lib.dom.d.ts is loaded, its definition wins.
62
57
  */
63
58
  type UseLibDomIfAvailable<GlobalThisKeyName extends PropertyKey, Otherwise> =
64
59
  // `onabort` is defined in lib.dom.d.ts, so we can check to see if lib dom is loaded by checking if `onabort` is defined
@@ -202,7 +197,7 @@ declare module "bun" {
202
197
  onerror: ((this: EventSource, ev: Event) => any) | null;
203
198
  onmessage: ((this: EventSource, ev: MessageEvent) => any) | null;
204
199
  onopen: ((this: EventSource, ev: Event) => any) | null;
205
- /** Returns the state of this EventSource object's connection. It can have the values described below. */
200
+ /** Returns the state of this EventSource object's connection: `CONNECTING` (0), `OPEN` (1), or `CLOSED` (2). */
206
201
  readonly readyState: number;
207
202
  /** Returns the URL providing the event stream. */
208
203
  readonly url: string;
@@ -248,14 +243,14 @@ declare module "bun" {
248
243
  ): void;
249
244
 
250
245
  /**
251
- * Keep the event loop alive while connection is open or reconnecting
246
+ * Keep the event loop alive while the connection is open or reconnecting
252
247
  *
253
248
  * Not available in browsers
254
249
  */
255
250
  ref(): void;
256
251
 
257
252
  /**
258
- * Do not keep the event loop alive while connection is open or reconnecting
253
+ * Do not keep the event loop alive while the connection is open or reconnecting
259
254
  *
260
255
  * Not available in browsers
261
256
  */
@@ -307,7 +302,7 @@ declare module "bun" {
307
302
  pull?: UnderlyingSourcePullCallback<R>;
308
303
  start?: UnderlyingSourceStartCallback<R>;
309
304
  /**
310
- * Mode "bytes" is not currently supported.
305
+ * Mode "bytes" is not supported.
311
306
  */
312
307
  type?: undefined;
313
308
  }
@@ -374,8 +369,8 @@ declare module "bun" {
374
369
  */
375
370
  interface WorkerOptions {
376
371
  /**
377
- * A string specifying an identifying name for the DedicatedWorkerGlobalScope representing the scope of
378
- * the worker, which is mainly useful for debugging purposes.
372
+ * An identifying name for the worker's `DedicatedWorkerGlobalScope`, mainly
373
+ * useful for debugging.
379
374
  */
380
375
  name?: string;
381
376
 
@@ -388,10 +383,10 @@ declare module "bun" {
388
383
  smol?: boolean;
389
384
 
390
385
  /**
391
- * When `true`, the worker will keep the parent thread alive until the worker is terminated or `unref`'d.
392
- * When `false`, the worker will not keep the parent thread alive.
386
+ * When `true`, the worker keeps the parent thread alive until the worker is terminated or `unref`'d.
387
+ * When `false`, it does not.
393
388
  *
394
- * By default, this is `false`.
389
+ * @default false
395
390
  */
396
391
  ref?: boolean;
397
392
 
@@ -401,10 +396,9 @@ declare module "bun" {
401
396
  type?: Bun.WorkerType | undefined;
402
397
 
403
398
  /**
404
- * List of arguments which would be stringified and appended to
405
- * `Bun.argv` / `process.argv` in the worker. This is mostly similar to the `data`
406
- * but the values will be available on the global `Bun.argv` as if they
407
- * were passed as CLI options to the script.
399
+ * List of arguments to stringify and append to `Bun.argv` / `process.argv`
400
+ * in the worker. The values are available on the global `Bun.argv` as if
401
+ * they were passed as CLI options to the script.
408
402
  */
409
403
  argv?: any[] | undefined;
410
404
 
@@ -412,7 +406,9 @@ declare module "bun" {
412
406
  // eval?: boolean | undefined;
413
407
 
414
408
  /**
415
- * If set, specifies the initial value of process.env inside the Worker thread. As a special value, worker.SHARE_ENV may be used to specify that the parent thread and the child thread should share their environment variables; in that case, changes to one thread's process.env object affect the other thread as well. Default: process.env.
409
+ * If set, the initial value of `process.env` inside the Worker thread. Pass `worker.SHARE_ENV`
410
+ * from `node:worker_threads` to share environment variables between the parent and worker threads;
411
+ * changes to one thread's `process.env` then affect the other thread as well. Default: `process.env`.
416
412
  */
417
413
  env?: Record<string, string> | (typeof import("node:worker_threads"))["SHARE_ENV"] | undefined;
418
414
 
@@ -477,17 +473,16 @@ declare module "bun" {
477
473
  ): void;
478
474
 
479
475
  /**
480
- * Opposite of `unref()`, calling `ref()` on a previously `unref()`ed worker does _not_ let the program exit if it's the only active handle left (the default
481
- * behavior). If the worker is `ref()`ed, calling `ref()` again has
482
- * no effect.
483
- * @since v10.5.0
476
+ * Opposite of `unref()`: calling `ref()` on a previously `unref()`ed worker does _not_ let the
477
+ * program exit if it's the only active handle left (the default behavior).
478
+ * If the worker is already `ref()`ed, calling `ref()` again has no effect.
484
479
  */
485
480
  ref(): void;
486
481
 
487
482
  /**
488
483
  * Calling `unref()` on a worker allows the thread to exit if this is the only
489
- * active handle in the event system. If the worker is already `unref()`ed calling`unref()` again has no effect.
490
- * @since v10.5.0
484
+ * active handle in the event system. If the worker is already `unref()`ed,
485
+ * calling `unref()` again has no effect.
491
486
  */
492
487
  unref(): void;
493
488
 
@@ -495,7 +490,6 @@ declare module "bun" {
495
490
  * An integer identifier for the referenced thread. Inside the worker thread,
496
491
  * it is available as `require('node:worker_threads').threadId`.
497
492
  * This value is unique for each `Worker` instance inside a single process.
498
- * @since v10.5.0
499
493
  */
500
494
  threadId: number;
501
495
  }
@@ -503,7 +497,7 @@ declare module "bun" {
503
497
  interface Env {
504
498
  NODE_ENV?: string;
505
499
  /**
506
- * Can be used to change the default timezone at runtime
500
+ * Set to change the default timezone at runtime
507
501
  */
508
502
  TZ?: string;
509
503
  }
@@ -518,59 +512,71 @@ declare module "bun" {
518
512
  const env: Env & NodeJS.ProcessEnv & ImportMetaEnv;
519
513
 
520
514
  /**
521
- * The raw arguments passed to the process, including flags passed to Bun. If you want to easily read flags passed to your script, consider using `process.argv` instead.
515
+ * The raw arguments passed to the process, including flags passed to Bun.
516
+ * To read the flags passed to your script, use `process.argv` instead.
522
517
  */
523
518
  const argv: string[];
524
519
 
525
520
  interface WhichOptions {
526
521
  /**
527
- * Overrides the PATH environment variable
522
+ * Overrides the `PATH` environment variable
528
523
  */
529
524
  PATH?: string;
530
525
 
531
526
  /**
532
- * When given a relative path, use this path to join it.
527
+ * When `command` is a relative path, resolve it against this directory.
533
528
  */
534
529
  cwd?: string;
535
530
  }
536
531
 
537
532
  /**
538
- * Find the path to an executable, similar to typing which in your terminal. Reads the `PATH` environment variable unless overridden with `options.PATH`.
533
+ * Find the path to an executable, like the `which` command in your terminal.
534
+ * Reads the `PATH` environment variable unless overridden with `options.PATH`.
539
535
  *
540
536
  * @category Utilities
541
537
  *
542
538
  * @param command The name of the executable or script to find
543
539
  * @param options Options for the search
540
+ * @returns The path to the executable, or `null` if it isn't found
544
541
  */
545
542
  function which(command: string, options?: WhichOptions): string | null;
546
543
 
547
544
  interface StringWidthOptions {
548
545
  /**
549
- * If `true`, count ANSI escape codes as part of the string width. If `false`, ANSI escape codes are ignored when calculating the string width.
546
+ * If `true`, count ANSI escape codes as part of the string width. If `false`, ignore them.
550
547
  *
551
548
  * @default false
552
549
  */
553
550
  countAnsiEscapeCodes?: boolean;
554
551
 
555
552
  /**
556
- * When it's ambiugous and `true`, count emoji as 1 characters wide. If `false`, emoji are counted as 2 character wide.
553
+ * If `true`, count ambiguous-width characters as 1 character wide. If `false`, count them as 2 characters wide.
557
554
  *
558
555
  * @default true
559
556
  */
560
557
  ambiguousIsNarrow?: boolean;
558
+
559
+ /**
560
+ * If `true`, measure every Unicode code point individually (East Asian
561
+ * Width plus emoji presentation, the algorithm Node.js uses for
562
+ * `console.table` and `util.inspect` alignment), so each member of an
563
+ * emoji ZWJ sequence is counted: `"👨‍👩‍👧‍👦"` measures 8. If `false`,
564
+ * emoji sequences and other grapheme clusters count once: `"👨‍👩‍👧‍👦"`
565
+ * measures 2.
566
+ *
567
+ * @default false
568
+ */
569
+ perCodePoint?: boolean;
561
570
  }
562
571
 
563
572
  /**
564
573
  * Get the column count of a string as it would be displayed in a terminal.
565
574
  * Supports ANSI escape codes, emoji, and wide characters.
566
575
  *
567
- * This is useful for:
568
- * - Aligning text in a terminal
569
- * - Quickly checking if a string contains ANSI escape codes
570
- * - Measuring the width of a string in a terminal
576
+ * This API is designed to match the `string-width` npm package, so existing
577
+ * code can be ported in either direction.
571
578
  *
572
- * This API is designed to match the popular "string-width" package, so that
573
- * existing code can be easily ported to Bun and vice versa.
579
+ * @category Utilities
574
580
  *
575
581
  * @returns The width of the string in columns
576
582
  *
@@ -651,7 +657,7 @@ declare module "bun" {
651
657
  * @param input The string to slice
652
658
  * @param start Starting column (default 0). Negative counts from end.
653
659
  * @param end Ending column, exclusive (default end of string). Negative counts from end.
654
- * @param options Optional behavior flags (e.g. `ellipsis` for truncation)
660
+ * @param options Optional behavior flags (such as `ellipsis` for truncation)
655
661
  * @returns The sliced string with ANSI codes intact
656
662
  *
657
663
  * @example
@@ -698,7 +704,8 @@ declare module "bun" {
698
704
 
699
705
  /**
700
706
  * If `true`, wrap at word boundaries when possible.
701
- * If `false`, don't perform word wrapping (only wrap at explicit newlines).
707
+ * If `false`, break every line at exactly the column width (characters
708
+ * are split wherever the limit falls, ignoring word boundaries).
702
709
  *
703
710
  * @default true
704
711
  */
@@ -713,7 +720,7 @@ declare module "bun" {
713
720
  trim?: boolean;
714
721
 
715
722
  /**
716
- * When it's ambiguous and `true`, count ambiguous width characters as 1 character wide.
723
+ * If `true`, count ambiguous-width characters as 1 character wide.
717
724
  * If `false`, count them as 2 characters wide.
718
725
  *
719
726
  * @default true
@@ -724,7 +731,7 @@ declare module "bun" {
724
731
  /**
725
732
  * Wrap a string to fit within the specified column width, preserving ANSI escape codes.
726
733
  *
727
- * This function is designed to be compatible with the popular "wrap-ansi" NPM package.
734
+ * Designed to be compatible with the `wrap-ansi` npm package.
728
735
  *
729
736
  * Features:
730
737
  * - Preserves ANSI escape codes (colors, styles) across line breaks
@@ -783,14 +790,293 @@ declare module "bun" {
783
790
  */
784
791
  namespace TOML {
785
792
  /**
786
- * Parse a TOML string into a JavaScript object.
793
+ * Parse a TOML (v1.1.0) document into a JavaScript object.
794
+ *
795
+ * Date/time values parse as Temporal objects: offset date-times as
796
+ * `Temporal.Instant`, local date-times as `Temporal.PlainDateTime`,
797
+ * local dates as `Temporal.PlainDate`, and local times as
798
+ * `Temporal.PlainTime`. Integers outside `Number.MAX_SAFE_INTEGER`
799
+ * throw, since they cannot be represented losslessly as JavaScript
800
+ * numbers.
787
801
  *
788
802
  * @category Utilities
789
803
  *
790
- * @param input The TOML string to parse
804
+ * @param input The TOML document to parse, as a string or UTF-8 bytes
791
805
  * @returns A JavaScript object
806
+ * @throws {SyntaxError} If the input is not valid TOML
792
807
  */
793
- export function parse(input: string): object;
808
+ export function parse(
809
+ input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike | Blob,
810
+ ): object;
811
+
812
+ /**
813
+ * Serialize a JavaScript object to a TOML document.
814
+ *
815
+ * The top-level value must be an object (a TOML document is a table).
816
+ * `Temporal.Instant`, `Temporal.PlainDateTime`, `Temporal.PlainDate`,
817
+ * and `Temporal.PlainTime` values become the corresponding TOML
818
+ * date/time literals, `Temporal.ZonedDateTime` becomes an offset
819
+ * date-time, and `Date` becomes an offset date-time in UTC; time-zone
820
+ * and calendar annotations are dropped, since TOML has no syntax for
821
+ * them. `null`, `BigInt`, circular structures, invalid `Date`s, date
822
+ * values outside years 0000–9999, and Temporal types with no TOML form
823
+ * (`Temporal.PlainYearMonth`, `Temporal.PlainMonthDay`,
824
+ * `Temporal.Duration`) throw, since TOML cannot represent them;
825
+ * `undefined`, function, and symbol properties are skipped (inside
826
+ * arrays they throw, since TOML arrays cannot have holes).
827
+ *
828
+ * @category Utilities
829
+ *
830
+ * @param input The JavaScript object to serialize.
831
+ * @param replacer Not supported; pass `undefined` or `null`.
832
+ * @param space Accepted for signature parity with `YAML.stringify` and
833
+ * `JSON5.stringify`, but ignored: TOML output is line-oriented.
834
+ * @returns A TOML document string, or `undefined` if the input is `undefined`, a function, or a symbol.
835
+ *
836
+ * @example
837
+ * ```js
838
+ * import { TOML } from "bun";
839
+ * TOML.stringify({ name: "app", server: { port: 8080 } });
840
+ * // 'name = "app"\n\n[server]\nport = 8080\n'
841
+ * ```
842
+ */
843
+ export function stringify(input: unknown, replacer?: undefined | null, space?: string | number): string | undefined;
844
+ }
845
+
846
+ /**
847
+ * XML related APIs
848
+ */
849
+ namespace XML {
850
+ // ── compact shape ──────────────────────────────────────────────────────
851
+
852
+ /**
853
+ * An element in the compact shape {@link parse} returns by default: its
854
+ * character data (a string) when it has no attributes and no child
855
+ * elements, otherwise an {@link Element}.
856
+ */
857
+ type Value = string | Element;
858
+
859
+ /**
860
+ * An element that has attributes or child elements, in the compact shape.
861
+ *
862
+ * - `"@name"` — one per attribute, holding its value.
863
+ * - `"#text"` — the element's own character data, exactly, when it has any:
864
+ * its text runs concatenated, leaving out only whitespace-only runs that
865
+ * sit between child elements (layout).
866
+ * - any other key — a child element name, holding that child's
867
+ * {@link Value}, or an array of them when the name occurs more than once
868
+ * in this element.
869
+ *
870
+ * Keys are in document order: attributes first, then child names and
871
+ * `"#text"` in order of first appearance. `@` and `#` cannot begin an XML
872
+ * name, so these keys never collide with element names.
873
+ */
874
+ interface Element {
875
+ [key: string]: Value | Value[];
876
+ }
877
+
878
+ /**
879
+ * A parsed document in the compact shape: exactly one key, the root
880
+ * element's name. This is also what importing an `.xml` file evaluates to.
881
+ */
882
+ interface Document {
883
+ [rootName: string]: Value;
884
+ }
885
+
886
+ // ── tree shape ─────────────────────────────────────────────────────────
887
+
888
+ /** An element in the tree {@link parse} returns with `{ compact: false }`. */
889
+ interface Node {
890
+ /** The element name as written, including any namespace prefix (`"soap:Envelope"`). */
891
+ name: string;
892
+ /**
893
+ * Attribute values by name as written, in document order, after
894
+ * attribute-value normalization and with defaults declared in the
895
+ * internal DTD subset applied. Namespace declarations (`xmlns`,
896
+ * `xmlns:*`) are ordinary attributes.
897
+ */
898
+ attributes: Record<string, string>;
899
+ /**
900
+ * The element's content in document order: character data as strings
901
+ * (exact — CDATA sections, character references and internal entities
902
+ * expanded, whitespace untouched, adjacent text merged into one string),
903
+ * child elements, comments and processing instructions. An object here is
904
+ * an element if it has `name`, a comment if it has `comment`, and a
905
+ * processing instruction if it has `target`.
906
+ */
907
+ children: Array<string | Node | Comment | ProcessingInstruction>;
908
+ }
909
+
910
+ /** `<!--comment-->` among a {@link Node}'s children. */
911
+ interface Comment {
912
+ comment: string;
913
+ }
914
+
915
+ /** `<?target data?>` among a {@link Node}'s children. */
916
+ interface ProcessingInstruction {
917
+ target: string;
918
+ /** The text after the whitespace that follows the target; `""` when there is none. */
919
+ data: string;
920
+ }
921
+
922
+ // ── parse ──────────────────────────────────────────────────────────────
923
+
924
+ interface ParseOptions {
925
+ /**
926
+ * Selects the shape of the result.
927
+ *
928
+ * - `true` (default): the compact {@link Document} — elements keyed by
929
+ * name, leaves as strings. The shape for data. It does not keep the
930
+ * relative order of differently named siblings, where text sat relative
931
+ * to child elements, comments, or processing instructions.
932
+ * - `false`: the root element as a {@link Node} tree, which keeps all of
933
+ * those, in document order. The shape for documents.
934
+ *
935
+ * Neither shape represents the XML declaration, the document type
936
+ * declaration, or anything outside the root element.
937
+ *
938
+ * @default true
939
+ */
940
+ compact?: boolean;
941
+ }
942
+
943
+ /**
944
+ * Parse an XML 1.0 document.
945
+ *
946
+ * `Bun.XML` is a conforming, non-validating XML processor. The document —
947
+ * including any internal DTD subset — must be well-formed or a
948
+ * `SyntaxError` is thrown; there is no lenient mode. Internal entities are
949
+ * expanded (within an expansion limit), attribute values are normalized,
950
+ * and attribute defaults declared in the internal subset are applied.
951
+ * External DTDs and external entities are never read. Nothing is coerced:
952
+ * every value is a string.
953
+ *
954
+ * `compact` selects a structure; it never alters character data. The text
955
+ * of an element is the same in both shapes — as written, whitespace
956
+ * included. The compact shape only does what having a single `"#text"`
957
+ * forces: an element's text runs are concatenated, and a whitespace-only
958
+ * run between child elements (the document's layout) is left out.
959
+ *
960
+ * A reference to an entity that only an unread external DTD could declare
961
+ * is not an error (XML 1.0 §4.1) and is kept in the text as written
962
+ * (`"&name;"` — indistinguishable afterwards from an escaped `&amp;name;`).
963
+ *
964
+ * A string is parsed as already-decoded text. Bytes (`Buffer`,
965
+ * `TypedArray`, `DataView`, `ArrayBuffer`, `Blob`) are decoded per the XML
966
+ * rules: a byte-order mark or the `encoding` declared in `<?xml ...?>`
967
+ * selects UTF-8, UTF-16, or ISO-8859-1; other encodings throw.
968
+ *
969
+ * @category Utilities
970
+ *
971
+ * @param input The XML document
972
+ * @throws {SyntaxError} If the document is not well-formed, uses an
973
+ * unsupported encoding, or exceeds the entity-expansion limits
974
+ * @throws {RangeError} If elements are nested too deeply
975
+ *
976
+ * @example
977
+ * ```ts
978
+ * import { XML } from "bun";
979
+ *
980
+ * XML.parse(`<order id="A1"><item sku="x">Tea</item><item sku="y">Mug</item><paid/></order>`);
981
+ * // {
982
+ * // order: {
983
+ * // "@id": "A1",
984
+ * // item: [ { "@sku": "x", "#text": "Tea" }, { "@sku": "y", "#text": "Mug" } ],
985
+ * // paid: "",
986
+ * // },
987
+ * // }
988
+ *
989
+ * XML.parse(`<p>Hello <b>world</b>!<!-- bye --></p>`, { compact: false });
990
+ * // {
991
+ * // name: "p",
992
+ * // attributes: {},
993
+ * // children: [ "Hello ", { name: "b", attributes: {}, children: ["world"] }, "!", { comment: " bye " } ],
994
+ * // }
995
+ * ```
996
+ */
997
+ function parse(
998
+ input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike | Blob,
999
+ options?: ParseOptions & { compact?: true },
1000
+ ): Document;
1001
+ function parse(
1002
+ input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike | Blob,
1003
+ options: ParseOptions & { compact: false },
1004
+ ): Node;
1005
+ function parse(
1006
+ input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike | Blob,
1007
+ options?: ParseOptions,
1008
+ ): Document | Node;
1009
+
1010
+ // ── stringify ──────────────────────────────────────────────────────────
1011
+
1012
+ /** A value {@link stringify} writes as text: `String(v)`, or the ISO string of a `Date`. */
1013
+ type Scalar = string | number | boolean | bigint | Date;
1014
+
1015
+ /**
1016
+ * A {@link Node} as {@link stringify} accepts it: `attributes` and
1017
+ * `children` may be omitted, scalars may stand where text goes, and
1018
+ * `null`/`undefined` entries are skipped.
1019
+ */
1020
+ interface NodeInput {
1021
+ name: string;
1022
+ attributes?: { [name: string]: Scalar | null | undefined } | null;
1023
+ children?: Array<Scalar | NodeInput | Comment | ProcessingInstruction | null | undefined> | null;
1024
+ }
1025
+
1026
+ /**
1027
+ * Serialize one element to XML: a {@link NodeInput} tree (any object with a
1028
+ * string `name` and a `children` or `attributes` property), or a compact
1029
+ * object with exactly one key naming the root element whose value follows
1030
+ * the {@link Element} conventions.
1031
+ *
1032
+ * The result is that element's markup only — no XML declaration and no
1033
+ * document type declaration; prepend them as text when writing a file
1034
+ * (`'<?xml version="1.0" encoding="UTF-8"?>\n' + XML.stringify(doc)`).
1035
+ * Because of that, results can be concatenated inside an enclosing element.
1036
+ *
1037
+ * The output is well-formed or `stringify` throws. `& < >` are escaped
1038
+ * everywhere; `"`, tabs and newlines in attribute values, and carriage
1039
+ * returns anywhere, are written as character references so they survive
1040
+ * being parsed again. It throws for element, attribute or processing
1041
+ * instruction names that are not XML names; for characters XML cannot
1042
+ * contain (U+0000, other C0 controls except tab/newline/carriage return,
1043
+ * U+FFFE, U+FFFF, unpaired surrogates); for `--` inside a comment or `?>`
1044
+ * inside processing-instruction data; for an array at the root or inside
1045
+ * another array; and for circular structures.
1046
+ *
1047
+ * Strings, numbers, booleans and bigints become text via `String()`, a
1048
+ * `Date` its ISO string; `null` becomes an empty element (or leaves an
1049
+ * attribute out); `undefined`, functions and symbols are skipped, as are
1050
+ * symbol-keyed, non-enumerable and inherited properties. In the compact
1051
+ * shape an array is one element per item and any other object is a child
1052
+ * element.
1053
+ *
1054
+ * `XML.parse(XML.stringify(value))` deep-equals `value` for anything
1055
+ * `XML.parse` returned, in either shape.
1056
+ *
1057
+ * @category Utilities
1058
+ *
1059
+ * @param value The element to serialize
1060
+ * @param replacer Reserved; must be `undefined` or `null`
1061
+ * @param space Indentation for element-only content, as in `JSON.stringify`:
1062
+ * a number of spaces (at most 10) or a string (its first 10 characters).
1063
+ * An element with any text child is written on one line so character data
1064
+ * is unchanged.
1065
+ * @returns The XML, or `undefined` if `value` is `undefined`, a function, or a symbol
1066
+ *
1067
+ * @example
1068
+ * ```ts
1069
+ * import { XML } from "bun";
1070
+ *
1071
+ * XML.stringify({ order: { "@id": "A1", item: ["Tea", "Mug"], paid: null } });
1072
+ * // '<order id="A1"><item>Tea</item><item>Mug</item><paid/></order>'
1073
+ *
1074
+ * XML.stringify({ name: "p", attributes: { class: "x" }, children: ["Hi ", { name: "b", children: ["!"] }] }, null, 2);
1075
+ * // '<p class="x">Hi <b>!</b></p>'
1076
+ * ```
1077
+ */
1078
+ function stringify(value: NodeInput | Document, replacer?: undefined | null, space?: string | number): string;
1079
+ function stringify(value: unknown, replacer?: undefined | null, space?: string | number): string | undefined;
794
1080
  }
795
1081
 
796
1082
  /**
@@ -807,6 +1093,7 @@ declare module "bun" {
807
1093
  *
808
1094
  * @param input The JSONC string to parse
809
1095
  * @returns A JavaScript value
1096
+ * @throws {SyntaxError} If the input is not valid JSONC
810
1097
  *
811
1098
  * @example
812
1099
  * ```js
@@ -823,7 +1110,7 @@ declare module "bun" {
823
1110
  /**
824
1111
  * JSONL (JSON Lines) related APIs.
825
1112
  *
826
- * Each line in the input is expected to be a valid JSON value separated by newlines.
1113
+ * Each line of the input is a JSON value.
827
1114
  */
828
1115
  namespace JSONL {
829
1116
  /**
@@ -832,7 +1119,7 @@ declare module "bun" {
832
1119
  interface ParseChunkResult {
833
1120
  /** The successfully parsed JSON values. */
834
1121
  values: unknown[];
835
- /** 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. */
1122
+ /** How much of 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. */
836
1123
  read: number;
837
1124
  /** `true` if all input was consumed successfully. `false` if the input ends with an incomplete value or a parse error occurred. */
838
1125
  done: boolean;
@@ -847,8 +1134,8 @@ declare module "bun" {
847
1134
  * a `SyntaxError`. If values were parsed before the error, returns the
848
1135
  * successfully parsed values without throwing.
849
1136
  *
850
- * Incomplete trailing values (e.g. from a partial chunk) are silently
851
- * ignored and not included in the result.
1137
+ * Incomplete trailing values (for example, from a partial chunk) are
1138
+ * silently ignored.
852
1139
  *
853
1140
  * When a `TypedArray` is passed, the bytes are parsed directly without
854
1141
  * copying if the content is ASCII.
@@ -875,7 +1162,7 @@ declare module "bun" {
875
1162
  * Bun.JSONL.parse('{bad}\n'); // throws SyntaxError
876
1163
  * ```
877
1164
  */
878
- export function parse(input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike): unknown[];
1165
+ export function parse(input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike): unknown[];
879
1166
 
880
1167
  /**
881
1168
  * Parse a JSONL chunk, designed for streaming use.
@@ -888,9 +1175,9 @@ declare module "bun" {
888
1175
  * When a `TypedArray` is passed, the bytes are parsed directly without
889
1176
  * copying if the content is ASCII. Optional `start` and `end` parameters
890
1177
  * select a window of the input without copying. For typed arrays these
891
- * are byte offsets and `read` will be a byte offset into the original
892
- * typed array. For strings these are character offsets and `read` will
893
- * be a character offset into the original string.
1178
+ * are byte offsets and `read` is a byte offset into the original
1179
+ * typed array. For strings these are character offsets and `read` is
1180
+ * a character offset into the original string.
894
1181
  *
895
1182
  * @param input The JSONL string or typed array to parse
896
1183
  * @param start Offset to start parsing from (bytes for typed arrays, characters for strings, default: 0)
@@ -910,7 +1197,7 @@ declare module "bun" {
910
1197
  * ```
911
1198
  */
912
1199
  export function parseChunk(
913
- input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike,
1200
+ input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike,
914
1201
  start?: number,
915
1202
  end?: number,
916
1203
  ): ParseChunkResult;
@@ -921,12 +1208,13 @@ declare module "bun" {
921
1208
  */
922
1209
  namespace YAML {
923
1210
  /**
924
- * Parse a YAML string into a JavaScript value
1211
+ * Parse a YAML string into a JavaScript value. Every alias (`*name`) of an anchored collection yields the
1212
+ * same object, and an alias may refer to a collection that contains it, so the result can be cyclic.
925
1213
  *
926
1214
  * @category Utilities
927
1215
  *
928
1216
  * @param input The YAML string to parse
929
- * @returns A JavaScript value
1217
+ * @returns A JavaScript value, or an array of them for a multi-document stream
930
1218
  *
931
1219
  * @example
932
1220
  * ```ts
@@ -949,7 +1237,7 @@ declare module "bun" {
949
1237
  * @category Utilities
950
1238
  *
951
1239
  * @param input The JavaScript value to stringify.
952
- * @param replacer Currently not supported.
1240
+ * @param replacer Not supported.
953
1241
  * @param space A number for how many spaces each level of indentation gets, or a string used as indentation.
954
1242
  * Without this parameter, outputs flow-style (single-line) YAML.
955
1243
  * With this parameter, outputs block-style (multi-line) YAML.
@@ -979,6 +1267,7 @@ declare module "bun" {
979
1267
  * console.log(YAML.stringify(cycle, null, 2));
980
1268
  * // &1
981
1269
  * // obj: *1
1270
+ * ```
982
1271
  */
983
1272
  export function stringify(input: unknown, replacer?: undefined | null, space?: string | number): string;
984
1273
  }
@@ -986,8 +1275,9 @@ declare module "bun" {
986
1275
  /**
987
1276
  * Markdown related APIs.
988
1277
  *
989
- * Provides fast markdown parsing and rendering with three output modes:
1278
+ * Parses and renders markdown with four output modes:
990
1279
  * - `html()` — render to an HTML string
1280
+ * - `ansi()` — render to an ANSI-colored string for terminals
991
1281
  * - `render()` — render with custom callbacks for each element
992
1282
  * - `react()` — parse to React-compatible JSX elements
993
1283
  *
@@ -1167,13 +1457,6 @@ declare module "bun" {
1167
1457
  br?: Component<{}>;
1168
1458
  }
1169
1459
 
1170
- /**
1171
- * Callbacks for `render()`. Each callback receives the accumulated children
1172
- * as a string and optional metadata, and returns a string.
1173
- *
1174
- * Return `null` or `undefined` to omit the element from the output.
1175
- * If no callback is registered for an element, its children pass through unchanged.
1176
- */
1177
1460
  /** Meta passed to the `heading` callback. */
1178
1461
  interface HeadingMeta {
1179
1462
  /** Heading level (1–6). */
@@ -1234,6 +1517,13 @@ declare module "bun" {
1234
1517
  title?: string;
1235
1518
  }
1236
1519
 
1520
+ /**
1521
+ * Callbacks for `render()`. Each callback receives the accumulated children
1522
+ * as a string and optional metadata, and returns a string.
1523
+ *
1524
+ * Return `null` or `undefined` to omit the element from the output.
1525
+ * If no callback is registered for an element, its children pass through unchanged.
1526
+ */
1237
1527
  interface RenderCallbacks {
1238
1528
  /** Heading (level 1–6). `id` is set when `headings: { ids: true }` is enabled. */
1239
1529
  heading?: (children: string, meta: HeadingMeta) => string | null | undefined;
@@ -1307,7 +1597,7 @@ declare module "bun" {
1307
1597
  * ```
1308
1598
  */
1309
1599
  export function html(
1310
- input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike,
1600
+ input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike,
1311
1601
  options?: Options,
1312
1602
  ): string;
1313
1603
 
@@ -1383,7 +1673,7 @@ declare module "bun" {
1383
1673
  * ```
1384
1674
  */
1385
1675
  export function ansi(
1386
- input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike,
1676
+ input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike,
1387
1677
  theme?: AnsiTheme,
1388
1678
  ): string;
1389
1679
 
@@ -1425,7 +1715,7 @@ declare module "bun" {
1425
1715
  * ```
1426
1716
  */
1427
1717
  export function render(
1428
- input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike,
1718
+ input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike,
1429
1719
  callbacks?: RenderCallbacks,
1430
1720
  options?: Options,
1431
1721
  ): string;
@@ -1474,7 +1764,7 @@ declare module "bun" {
1474
1764
  * ```
1475
1765
  */
1476
1766
  export function react(
1477
- input: string | NodeJS.TypedArray | DataView<ArrayBuffer> | ArrayBufferLike,
1767
+ input: string | NodeJS.TypedArray | DataView<ArrayBufferLike> | ArrayBufferLike,
1478
1768
  components?: ComponentOverrides,
1479
1769
  options?: ReactOptions,
1480
1770
  ): import("./jsx.d.ts").JSX.Element;
@@ -1489,7 +1779,7 @@ declare module "bun" {
1489
1779
  *
1490
1780
  * JSON5 is a superset of JSON based on ECMAScript 5.1 that supports
1491
1781
  * comments, trailing commas, unquoted keys, single-quoted strings,
1492
- * hex numbers, Infinity, NaN, and more.
1782
+ * hex numbers, `Infinity`, `NaN`, and more.
1493
1783
  *
1494
1784
  * @category Utilities
1495
1785
  *
@@ -1521,7 +1811,7 @@ declare module "bun" {
1521
1811
  * @category Utilities
1522
1812
  *
1523
1813
  * @param input The JavaScript value to stringify.
1524
- * @param replacer Currently not supported.
1814
+ * @param replacer Not supported.
1525
1815
  * @param space A number for how many spaces each level of indentation gets, or a string used as indentation.
1526
1816
  * The number is clamped between 0 and 10, and the first 10 characters of the string are used.
1527
1817
  * @returns A JSON5 string, or `undefined` if the input is `undefined`, a function, or a symbol.
@@ -1555,19 +1845,19 @@ declare module "bun" {
1555
1845
  *
1556
1846
  * On failure, throws a `ResolveMessage`
1557
1847
  *
1558
- * For now, use the sync version. There is zero performance benefit to using this async version. It exists for future-proofing.
1848
+ * Use {@link resolveSync} instead. This async version has no performance benefit; it exists for future-proofing.
1559
1849
  */
1560
1850
  function resolve(moduleId: string, parent: string): Promise<string>;
1561
1851
 
1562
1852
  /**
1563
1853
  * Use the fastest syscalls available to copy from `input` into `destination`.
1564
1854
  *
1565
- * If `destination` exists, it must be a regular file or symlink to a file. If `destination`'s directory does not exist, it will be created by default.
1855
+ * If `destination` exists, it must be a regular file or symlink to a file. If `destination`'s directory does not exist, it is created by default.
1566
1856
  *
1567
1857
  * @category File System
1568
1858
  *
1569
1859
  * @param destination The file or file path to write to
1570
- * @param input The data to copy into `destination`.
1860
+ * @param input The data to copy into `destination`
1571
1861
  * @param options Options for the write
1572
1862
  *
1573
1863
  * @returns A promise that resolves with the number of bytes written.
@@ -1581,9 +1871,9 @@ declare module "bun" {
1581
1871
  */
1582
1872
  mode?: number;
1583
1873
  /**
1584
- * If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
1874
+ * If `true`, create the parent directory if it doesn't exist.
1585
1875
  *
1586
- * If `false`, this will throw an error if the directory doesn't exist.
1876
+ * If `false`, the write throws an error when the directory doesn't exist.
1587
1877
  *
1588
1878
  * @default true
1589
1879
  */
@@ -1594,11 +1884,10 @@ declare module "bun" {
1594
1884
  /**
1595
1885
  * Persist a {@link Response} body to disk.
1596
1886
  *
1597
- * @param destination The file to write to. If the file doesn't exist,
1598
- * it will be created and if the file does exist, it will be
1599
- * overwritten. If `input`'s size is less than `destination`'s size,
1600
- * `destination` will be truncated.
1601
- * @param input - `Response` object
1887
+ * @param destination The file to write to. If the file doesn't exist, it is
1888
+ * created; if it does, it is overwritten. If `input` is smaller than
1889
+ * `destination`, `destination` is truncated.
1890
+ * @param input The `Response` whose body is written
1602
1891
  * @param options Options for the write
1603
1892
  *
1604
1893
  * @returns A promise that resolves with the number of bytes written.
@@ -1608,9 +1897,9 @@ declare module "bun" {
1608
1897
  input: Response,
1609
1898
  options?: {
1610
1899
  /**
1611
- * If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
1900
+ * If `true`, create the parent directory if it doesn't exist.
1612
1901
  *
1613
- * If `false`, this will throw an error if the directory doesn't exist.
1902
+ * If `false`, the write throws an error when the directory doesn't exist.
1614
1903
  *
1615
1904
  * @default true
1616
1905
  */
@@ -1622,10 +1911,9 @@ declare module "bun" {
1622
1911
  * Persist a {@link Response} body to disk.
1623
1912
  *
1624
1913
  * @param destinationPath The file path to write to. If the file doesn't
1625
- * exist, it will be created and if the file does exist, it will be
1626
- * overwritten. If `input`'s size is less than `destination`'s size,
1627
- * `destination` will be truncated.
1628
- * @param input - `Response` object
1914
+ * exist, it is created; if it does, it is overwritten. If `input` is
1915
+ * smaller than the existing file, the file is truncated.
1916
+ * @param input The `Response` whose body is written
1629
1917
  * @returns A promise that resolves with the number of bytes written.
1630
1918
  */
1631
1919
  function write(
@@ -1633,9 +1921,9 @@ declare module "bun" {
1633
1921
  input: Response,
1634
1922
  options?: {
1635
1923
  /**
1636
- * If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
1924
+ * If `true`, create the parent directory if it doesn't exist.
1637
1925
  *
1638
- * If `false`, this will throw an error if the directory doesn't exist.
1926
+ * If `false`, the write throws an error when the directory doesn't exist.
1639
1927
  *
1640
1928
  * @default true
1641
1929
  */
@@ -1652,13 +1940,12 @@ declare module "bun" {
1652
1940
  *
1653
1941
  * On macOS, when the destination doesn't already exist, this uses
1654
1942
  * [`clonefile()`](https://www.manpagez.com/man/2/clonefile/) and falls
1655
- * back to [`fcopyfile()`](https://www.manpagez.com/man/2/fcopyfile/)
1943
+ * back to [`fcopyfile()`](https://www.manpagez.com/man/2/fcopyfile/).
1656
1944
  *
1657
- * @param destination The file to write to. If the file doesn't exist,
1658
- * it will be created and if the file does exist, it will be
1659
- * overwritten. If `input`'s size is less than `destination`'s size,
1660
- * `destination` will be truncated.
1661
- * @param input The file to copy from.
1945
+ * @param destination The file to write to. If the file doesn't exist, it is
1946
+ * created; if it does, it is overwritten. If `input` is smaller than
1947
+ * `destination`, `destination` is truncated.
1948
+ * @param input The file to copy from
1662
1949
  * @returns A promise that resolves with the number of bytes written.
1663
1950
  */
1664
1951
 
@@ -1681,9 +1968,9 @@ declare module "bun" {
1681
1968
  */
1682
1969
  mode?: number;
1683
1970
  /**
1684
- * If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
1971
+ * If `true`, create the parent directory if it doesn't exist.
1685
1972
  *
1686
- * If `false`, this will throw an error if the directory doesn't exist.
1973
+ * If `false`, the write throws an error when the directory doesn't exist.
1687
1974
  *
1688
1975
  * @default true
1689
1976
  */
@@ -1700,13 +1987,12 @@ declare module "bun" {
1700
1987
  *
1701
1988
  * On macOS, when the destination doesn't already exist, this uses
1702
1989
  * [`clonefile()`](https://www.manpagez.com/man/2/clonefile/) and falls
1703
- * back to [`fcopyfile()`](https://www.manpagez.com/man/2/fcopyfile/)
1990
+ * back to [`fcopyfile()`](https://www.manpagez.com/man/2/fcopyfile/).
1704
1991
  *
1705
1992
  * @param destinationPath The file path to write to. If the file doesn't
1706
- * exist, it will be created and if the file does exist, it will be
1707
- * overwritten. If `input`'s size is less than `destination`'s size,
1708
- * `destination` will be truncated.
1709
- * @param input The file to copy from.
1993
+ * exist, it is created; if it does, it is overwritten. If `input` is
1994
+ * smaller than the existing file, the file is truncated.
1995
+ * @param input The file to copy from
1710
1996
  * @returns A promise that resolves with the number of bytes written.
1711
1997
  */
1712
1998
  function write(
@@ -1728,9 +2014,9 @@ declare module "bun" {
1728
2014
  */
1729
2015
  mode?: number;
1730
2016
  /**
1731
- * If `true`, create the parent directory if it doesn't exist. By default, this is `true`.
2017
+ * If `true`, create the parent directory if it doesn't exist.
1732
2018
  *
1733
- * If `false`, this will throw an error if the directory doesn't exist.
2019
+ * If `false`, the write throws an error when the directory doesn't exist.
1734
2020
  *
1735
2021
  * @default true
1736
2022
  */
@@ -1738,6 +2024,10 @@ declare module "bun" {
1738
2024
  },
1739
2025
  ): Promise<number>;
1740
2026
 
2027
+ /**
2028
+ * An `Error` from a failed system call, with optional `errno`, `code`,
2029
+ * `path`, and `syscall` properties.
2030
+ */
1741
2031
  interface SystemError extends Error {
1742
2032
  errno?: number | undefined;
1743
2033
  code?: string | undefined;
@@ -1746,35 +2036,16 @@ declare module "bun" {
1746
2036
  }
1747
2037
 
1748
2038
  /**
1749
- * Concatenate an array of typed arrays into a single `ArrayBuffer`. This is a fast path.
2039
+ * Concatenate an array of typed arrays into a single `ArrayBuffer`.
1750
2040
  *
1751
- * You can do this manually if you'd like, but this function will generally
1752
- * be a little faster.
2041
+ * About 30% faster than allocating an `ArrayBuffer` and copying each chunk
2042
+ * into it yourself: the total length is known up front, so Bun can copy into
2043
+ * uninitialized memory.
1753
2044
  *
1754
2045
  * If you want a `Uint8Array` instead, consider `Buffer.concat`.
1755
2046
  *
1756
2047
  * @param buffers An array of typed arrays to concatenate.
1757
2048
  * @returns An `ArrayBuffer` with the data from all the buffers.
1758
- *
1759
- * Here is similar code to do it manually, except about 30% slower:
1760
- * ```js
1761
- * var chunks = [...];
1762
- * var size = 0;
1763
- * for (const chunk of chunks) {
1764
- * size += chunk.byteLength;
1765
- * }
1766
- * var buffer = new ArrayBuffer(size);
1767
- * var view = new Uint8Array(buffer);
1768
- * var offset = 0;
1769
- * for (const chunk of chunks) {
1770
- * view.set(chunk, offset);
1771
- * offset += chunk.byteLength;
1772
- * }
1773
- * return buffer;
1774
- * ```
1775
- *
1776
- * This function is faster because it uses uninitialized memory when copying. Since the entire
1777
- * length of the buffer is known, it is safe to use uninitialized memory.
1778
2049
  */
1779
2050
  function concatArrayBuffers(buffers: Array<ArrayBufferView | ArrayBufferLike>, maxLength?: number): ArrayBuffer;
1780
2051
  function concatArrayBuffers(
@@ -1789,15 +2060,14 @@ declare module "bun" {
1789
2060
  ): Uint8Array<ArrayBuffer>;
1790
2061
 
1791
2062
  /**
1792
- * Consume all data from a {@link ReadableStream} until it closes or errors.
1793
- *
1794
- * Concatenate the chunks into a single {@link ArrayBuffer}.
2063
+ * Consume all data from a {@link ReadableStream} until it closes or errors,
2064
+ * concatenating the chunks into a single {@link ArrayBuffer}.
1795
2065
  *
1796
2066
  * Each chunk must be a TypedArray or an ArrayBuffer. If you need to support
1797
- * chunks of different types, consider {@link readableStreamToBlob}
2067
+ * chunks of different types, consider {@link readableStreamToBlob}.
1798
2068
  *
1799
2069
  * @param stream The stream to consume.
1800
- * @returns A promise that resolves with the concatenated chunks or the concatenated chunks as an `ArrayBuffer`.
2070
+ * @returns The concatenated chunks as an `ArrayBuffer`, or a promise that resolves with one.
1801
2071
  */
1802
2072
  function readableStreamToArrayBuffer(
1803
2073
  stream: ReadableStream<ArrayBufferView | ArrayBufferLike>,
@@ -1806,10 +2076,10 @@ declare module "bun" {
1806
2076
  /**
1807
2077
  * Consume all data from a {@link ReadableStream} until it closes or errors.
1808
2078
  *
1809
- * Reads the multi-part or URL-encoded form data into a {@link FormData} object
2079
+ * Reads the multipart or URL-encoded form data into a {@link FormData} object.
1810
2080
  *
1811
2081
  * @param stream The stream to consume.
1812
- * @param multipartBoundaryExcludingDashes Optional boundary to use for multipart form data. If none is provided, assumes it is a URLEncoded form.
2082
+ * @param multipartBoundaryExcludingDashes Optional boundary to use for multipart form data. If none is provided, assumes it is a URL-encoded form.
1813
2083
  * @returns A promise that resolves with the data encoded into a {@link FormData} object.
1814
2084
  *
1815
2085
  * @example
@@ -1818,7 +2088,7 @@ declare module "bun" {
1818
2088
  * // without dashes
1819
2089
  * const boundary = "WebKitFormBoundary" + Math.random().toString(16).slice(2);
1820
2090
  *
1821
- * const myStream = getStreamFromSomewhere() // ...
2091
+ * const stream = getStreamFromSomewhere() // ...
1822
2092
  * const formData = await Bun.readableStreamToFormData(stream, boundary);
1823
2093
  * formData.get("foo"); // "bar"
1824
2094
  * ```
@@ -1839,15 +2109,13 @@ declare module "bun" {
1839
2109
  * Consume all data from a {@link ReadableStream} until it closes or errors.
1840
2110
  *
1841
2111
  * @param stream The stream to consume
1842
- * @returns A promise that resolves with the chunks as an array
2112
+ * @returns The chunks as an array, or a promise that resolves with one
1843
2113
  */
1844
2114
  function readableStreamToArray<T>(stream: ReadableStream<T>): Promise<T[]> | T[];
1845
2115
 
1846
2116
  /**
1847
2117
  * Escape the following characters in a string:
1848
2118
  *
1849
- * @category Security
1850
- *
1851
2119
  * - `"` becomes `"&quot;"`
1852
2120
  * - `&` becomes `"&amp;"`
1853
2121
  * - `'` becomes `"&#x27;"`
@@ -1855,10 +2123,12 @@ declare module "bun" {
1855
2123
  * - `>` becomes `"&gt;"`
1856
2124
  *
1857
2125
  * This function is optimized for large input. On an M1X, it processes 480 MB/s -
1858
- * 20 GB/s, depending on how much data is being escaped and whether there is non-ascii
2126
+ * 20 GB/s, depending on how much data is being escaped and whether there is non-ASCII
1859
2127
  * text.
1860
2128
  *
1861
- * Non-string types will be converted to a string before escaping.
2129
+ * Non-string types are converted to a string before escaping.
2130
+ *
2131
+ * @category Security
1862
2132
  */
1863
2133
  function escapeHTML(input: string | object | number | boolean): string;
1864
2134
 
@@ -1886,6 +2156,9 @@ declare module "bun" {
1886
2156
  */
1887
2157
  function peek<T = undefined>(promise: T | Promise<T>): Promise<T> | T;
1888
2158
  namespace peek {
2159
+ /**
2160
+ * Read a promise's state without awaiting it: `"pending"`, `"fulfilled"`, or `"rejected"`.
2161
+ */
1889
2162
  function status<T = undefined>(promise: T | Promise<T>): "pending" | "fulfilled" | "rejected";
1890
2163
  }
1891
2164
 
@@ -1894,7 +2167,7 @@ declare module "bun" {
1894
2167
  *
1895
2168
  * @param url The URL to convert.
1896
2169
  * @returns A filesystem path.
1897
- * @throws If the URL is not a URL.
2170
+ * @throws If `url` is not a valid URL.
1898
2171
  *
1899
2172
  * @category File System
1900
2173
  *
@@ -1913,35 +2186,35 @@ declare module "bun" {
1913
2186
  start(options?: {
1914
2187
  asUint8Array?: boolean;
1915
2188
  /**
1916
- * Preallocate an internal buffer of this size
1917
- * This can significantly improve performance when the chunk size is small
2189
+ * Preallocate an internal buffer of this size.
2190
+ * This can significantly improve performance when the chunk size is small.
1918
2191
  */
1919
2192
  highWaterMark?: number;
1920
2193
  /**
1921
2194
  * On {@link ArrayBufferSink.flush}, return the written data as a `Uint8Array`.
1922
- * Writes will restart from the beginning of the buffer.
2195
+ * Writes restart from the beginning of the buffer.
1923
2196
  */
1924
2197
  stream?: boolean;
1925
2198
  }): void;
1926
2199
 
1927
2200
  write(chunk: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer): number;
1928
2201
  /**
1929
- * Flush the internal buffer
2202
+ * Flush the internal buffer.
1930
2203
  *
1931
- * If {@link ArrayBufferSink.start} was passed a `stream` option, this will return a `ArrayBuffer`
1932
- * If {@link ArrayBufferSink.start} was passed a `stream` option and `asUint8Array`, this will return a `Uint8Array`
1933
- * Otherwise, this will return the number of bytes written since the last flush
2204
+ * - If {@link ArrayBufferSink.start} was passed a `stream` option, this returns an `ArrayBuffer`.
2205
+ * - If it was passed a `stream` option and `asUint8Array`, this returns a `Uint8Array`.
2206
+ * - Otherwise, this returns the number of bytes written since the last flush.
1934
2207
  *
1935
- * This API might change later to separate Uint8ArraySink and ArrayBufferSink
2208
+ * This API might change later to separate Uint8ArraySink and ArrayBufferSink.
1936
2209
  */
1937
2210
  flush(): number | Uint8Array<ArrayBuffer> | ArrayBuffer;
1938
2211
  end(): ArrayBuffer | Uint8Array<ArrayBuffer>;
1939
2212
  }
1940
2213
 
1941
- /** DNS Related APIs */
2214
+ /** DNS-related APIs */
1942
2215
  namespace dns {
1943
2216
  /**
1944
- * Lookup the IP address for a hostname
2217
+ * Look up the IP address for a hostname
1945
2218
  *
1946
2219
  * Uses non-blocking APIs by default
1947
2220
  *
@@ -1973,7 +2246,7 @@ declare module "bun" {
1973
2246
  * Bun supports three DNS resolvers:
1974
2247
  * - `c-ares` - Uses the c-ares library to perform DNS resolution. This is the default on Linux.
1975
2248
  * - `system` - Uses the system's non-blocking DNS resolver API if available, falls back to `getaddrinfo`. This is the default on macOS and the same as `getaddrinfo` on Linux.
1976
- * - `getaddrinfo` - Uses the posix standard `getaddrinfo` function. Will cause performance issues under concurrent loads.
2249
+ * - `getaddrinfo` - Uses the POSIX standard `getaddrinfo` function. Causes performance issues under concurrent loads.
1977
2250
  *
1978
2251
  * To customize the DNS resolver, pass a `backend` option to `dns.lookup`:
1979
2252
  * ```js
@@ -2010,36 +2283,34 @@ declare module "bun" {
2010
2283
  * On Linux, `system` is the same as `getaddrinfo`.
2011
2284
  *
2012
2285
  * `c-ares` is more performant on Linux in some high concurrency
2013
- * situations, but it lacks support support for mDNS (`*.local`,
2286
+ * situations, but it lacks support for mDNS (`*.local`,
2014
2287
  * `*.localhost` domains) along with some other advanced features. If
2015
- * you run into issues using `c-ares`, you should try `system`. If the
2016
- * hostname ends with `.local` or `.localhost`, Bun will automatically
2017
- * use `system` instead of `c-ares`.
2288
+ * you run into issues using `c-ares`, try `system`. If the
2289
+ * hostname ends with `.local` or `.localhost`, Bun automatically
2290
+ * uses `system` instead of `c-ares`.
2018
2291
  *
2019
2292
  * [`getaddrinfo`](https://man7.org/linux/man-pages/man3/getaddrinfo.3.html)
2020
2293
  * is the POSIX standard function for blocking DNS resolution. Bun runs
2021
- * it in Bun's thread pool, which is limited to `cpus / 2`. That means
2022
- * if you run a lot of concurrent DNS lookups, concurrent IO will
2023
- * potentially pause until the DNS lookups are done.
2294
+ * it in Bun's thread pool, which is limited to `cpus / 2`, so many
2295
+ * concurrent DNS lookups can pause other concurrent IO until the
2296
+ * lookups finish.
2024
2297
  *
2025
- * On macOS, it shouldn't be necessary to use "`getaddrinfo`" because
2298
+ * On macOS, `"getaddrinfo"` shouldn't be necessary because
2026
2299
  * `"system"` uses the same API underneath (except non-blocking).
2027
2300
  *
2028
2301
  * On Windows, libuv's non-blocking DNS resolver is used by default, and
2029
2302
  * when specifying backends "system", "libc", or "getaddrinfo". The c-ares
2030
- * backend isn't currently supported on Windows.
2303
+ * backend isn't supported on Windows.
2031
2304
  */
2032
2305
  backend?: "libc" | "c-ares" | "system" | "getaddrinfo";
2033
2306
  },
2034
2307
  ): Promise<DNSLookup[]>;
2035
2308
 
2036
2309
  /**
2037
- *
2038
2310
  * **Experimental API**
2039
2311
  *
2040
- * Prefetch a hostname.
2041
- *
2042
- * This will be used by fetch() and Bun.connect() to avoid DNS lookups.
2312
+ * Prefetch a hostname so that later `fetch()` and `Bun.connect()` calls
2313
+ * can skip the DNS lookup.
2043
2314
  *
2044
2315
  * @param hostname The hostname to prefetch
2045
2316
  * @param port The port to prefetch. Default is 443. Port helps distinguish between IPv6 vs IPv4-only connections.
@@ -2098,9 +2369,9 @@ declare module "bun" {
2098
2369
  /**
2099
2370
  * [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) powered by the fastest system calls available for operating on files.
2100
2371
  *
2101
- * This Blob is lazy. That means it won't do any work until you read from it.
2372
+ * This Blob is lazy: it does no work until you read from it.
2102
2373
  *
2103
- * - `size` will not be valid until the contents of the file are read at least once.
2374
+ * - `size` is not valid until the contents of the file are read at least once.
2104
2375
  * - `type` is auto-set based on the file extension when possible
2105
2376
  *
2106
2377
  * @category File System
@@ -2126,7 +2397,7 @@ declare module "bun" {
2126
2397
  *
2127
2398
  * Similar to [`TypedArray.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray). Does not copy the file, open the file, or modify the file.
2128
2399
  *
2129
- * If `begin` > 0, {@link Bun.write()} will be slower on macOS
2400
+ * If `begin` > 0, {@link Bun.write()} is slower on macOS
2130
2401
  *
2131
2402
  * @param begin - start offset in bytes
2132
2403
  * @param end - absolute offset in bytes (relative to 0)
@@ -2139,7 +2410,7 @@ declare module "bun" {
2139
2410
  *
2140
2411
  * Similar to [`TypedArray.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray). Does not copy the file, open the file, or modify the file.
2141
2412
  *
2142
- * If `begin` > 0, {@link Bun.write}() will be slower on macOS
2413
+ * If `begin` > 0, {@link Bun.write}() is slower on macOS
2143
2414
  *
2144
2415
  * @param begin - start offset in bytes
2145
2416
  * @param contentType - MIME type for the new BunFile
@@ -2175,8 +2446,8 @@ declare module "bun" {
2175
2446
  * Does the file exist?
2176
2447
  *
2177
2448
  * This returns true for regular files and FIFOs. It returns false for
2178
- * directories. Note that a race condition can occur where the file is
2179
- * deleted or renamed after this is called but before you open it.
2449
+ * directories. A race condition can occur where the file is deleted or
2450
+ * renamed after this is called but before you open it.
2180
2451
  *
2181
2452
  * This does a system call to check if the file exists, which can be
2182
2453
  * slow.
@@ -2239,11 +2510,19 @@ declare module "bun" {
2239
2510
  * @default "sha256"
2240
2511
  */
2241
2512
  algorithm?: CSRFAlgorithm;
2513
+
2514
+ /**
2515
+ * Binds the token to the requesting principal (session ID, user ID, or
2516
+ * equivalent). A token generated with a `sessionId` only verifies when the
2517
+ * same `sessionId` is supplied to `verify()`. Without it, any token issued
2518
+ * under the same secret validates for every user.
2519
+ */
2520
+ sessionId?: string;
2242
2521
  }
2243
2522
 
2244
2523
  interface CSRFVerifyOptions {
2245
2524
  /**
2246
- * The secret to use for the token. If not provided, a random default secret will be generated in memory and used.
2525
+ * The secret to use for the token. If not provided, Bun generates a random default secret in memory and uses it.
2247
2526
  */
2248
2527
  secret?: string;
2249
2528
 
@@ -2264,6 +2543,14 @@ declare module "bun" {
2264
2543
  * @default 24 * 60 * 60 * 1000 (24 hours)
2265
2544
  */
2266
2545
  maxAge?: number;
2546
+
2547
+ /**
2548
+ * The principal (session ID, user ID, or equivalent) the token must be
2549
+ * bound to. A token generated with a `sessionId` only verifies when the
2550
+ * same `sessionId` is supplied here; a token generated without one only
2551
+ * verifies when this option is omitted.
2552
+ */
2553
+ sessionId?: string;
2267
2554
  }
2268
2555
 
2269
2556
  /**
@@ -2274,7 +2561,7 @@ declare module "bun" {
2274
2561
  namespace CSRF {
2275
2562
  /**
2276
2563
  * Generate a CSRF token.
2277
- * @param secret The secret to use for the token. If not provided, a random default secret will be generated in memory and used.
2564
+ * @param secret The secret to use for the token. If not provided, Bun generates a random default secret in memory and uses it.
2278
2565
  * @param options The options for the token.
2279
2566
  * @returns The generated token.
2280
2567
  */
@@ -2290,7 +2577,7 @@ declare module "bun" {
2290
2577
  }
2291
2578
 
2292
2579
  /**
2293
- * This lets you use macros as regular imports
2580
+ * Use macros as regular imports.
2294
2581
  * @example
2295
2582
  * ```
2296
2583
  * {
@@ -2399,8 +2686,8 @@ declare module "bun" {
2399
2686
  /**
2400
2687
  * Replace an import statement with a macro.
2401
2688
  *
2402
- * This will remove the import statement from the final output
2403
- * and replace any function calls or template strings with the result returned by the macro
2689
+ * This removes the import statement from the final output
2690
+ * and replaces any function calls or template strings with the result returned by the macro
2404
2691
  *
2405
2692
  * @example
2406
2693
  * ```json
@@ -2411,7 +2698,7 @@ declare module "bun" {
2411
2698
  * }
2412
2699
  * ```
2413
2700
  *
2414
- * Code that calls `graphql` will be replaced with the result of the macro.
2701
+ * Code that calls `graphql` is replaced with the result of the macro.
2415
2702
  *
2416
2703
  * ```js
2417
2704
  * import {graphql} from "react-relay";
@@ -2461,16 +2748,16 @@ declare module "bun" {
2461
2748
  deadCodeElimination?: boolean;
2462
2749
 
2463
2750
  /**
2464
- * This does two things (and possibly more in the future):
2465
- * 1. `const` declarations to primitive types (excluding Object/Array) at the top of a scope before any `let` or `var` declarations will be inlined into their usages.
2751
+ * This does two things:
2752
+ * 1. `const` declarations to primitive types (excluding Object/Array) at the top of a scope before any `let` or `var` declarations are inlined into their usages.
2466
2753
  * 2. `let` and `const` declarations only used once are inlined into their usages.
2467
2754
  *
2468
2755
  * JavaScript engines typically do these optimizations internally, however
2469
2756
  * it might only happen much later in the compilation pipeline, after code
2470
2757
  * has been executed many many times.
2471
2758
  *
2472
- * This will typically shrink the output size of code, but it might increase
2473
- * it in some cases. Do your own benchmarks!
2759
+ * This typically shrinks the output size of code, but it might increase
2760
+ * it in some cases. Do your own benchmarks.
2474
2761
  */
2475
2762
  inline?: boolean;
2476
2763
 
@@ -2717,7 +3004,7 @@ declare module "bun" {
2717
3004
  * references to string literals containing the actual environment variable values
2718
3005
  * - `"disable"`: Disables environment variable injection entirely
2719
3006
  * - A string ending in `*`: Inlines environment variables that match the given prefix.
2720
- * For example, `"MY_PUBLIC_*"` will only include env vars starting with "MY_PUBLIC_"
3007
+ * For example, `"MY_PUBLIC_*"` only includes env vars starting with "MY_PUBLIC_"
2721
3008
  *
2722
3009
  * @example
2723
3010
  * ```ts
@@ -2758,7 +3045,12 @@ declare module "bun" {
2758
3045
  */
2759
3046
  emitDCEAnnotations?: boolean;
2760
3047
 
2761
- // treeshaking?: boolean;
3048
+ /**
3049
+ * Whether to enable tree-shaking (removal of unreferenced top-level
3050
+ * declarations and unused exports). Defaults to `true`. Set to `false` to
3051
+ * keep dead code in the output for debugging or test fixtures.
3052
+ */
3053
+ treeShaking?: boolean;
2762
3054
 
2763
3055
  // jsx?:
2764
3056
  // | "automatic"
@@ -2775,7 +3067,7 @@ declare module "bun" {
2775
3067
 
2776
3068
  /**
2777
3069
  * Generate bytecode for the output. This can dramatically improve cold
2778
- * start times, but will make the final output larger and slightly increase
3070
+ * start times, but makes the final output larger and slightly increases
2779
3071
  * memory usage.
2780
3072
  *
2781
3073
  * - CommonJS: works with or without `compile: true`
@@ -2885,10 +3177,31 @@ declare module "bun" {
2885
3177
  */
2886
3178
  reactFastRefresh?: boolean;
2887
3179
 
3180
+ /**
3181
+ * Run the React Compiler over `.jsx`/`.tsx` source files, automatically
3182
+ * memoizing components and hooks.
3183
+ *
3184
+ * @default false
3185
+ * @experimental
3186
+ */
3187
+ reactCompiler?: boolean;
3188
+
3189
+ /**
3190
+ * Output mode for the React Compiler. `"ssr"` skips memoization (the
3191
+ * `useMemoCache` runtime) for server-rendered output.
3192
+ *
3193
+ * Only applies when {@link reactCompiler} is `true`.
3194
+ *
3195
+ * @default `"client"` when {@link target} is `"browser"`; `"ssr"` when
3196
+ * {@link target} is `"bun"` or `"node"`.
3197
+ * @experimental
3198
+ */
3199
+ reactCompilerOutputMode?: "client" | "ssr";
3200
+
2888
3201
  /**
2889
3202
  * A map of file paths to their contents for in-memory bundling.
2890
3203
  *
2891
- * This allows you to bundle virtual files that don't exist on disk, or override
3204
+ * Use this to bundle virtual files that don't exist on disk, or override
2892
3205
  * the contents of files that do exist on disk. The keys are file paths (which should
2893
3206
  * match how they're imported) and the values are the file contents.
2894
3207
  *
@@ -3025,9 +3338,15 @@ declare module "bun" {
3025
3338
  executablePath?: string;
3026
3339
  outfile?: string;
3027
3340
  /**
3028
- * Whether to autoload .env files when the standalone executable runs
3341
+ * Files or directories to embed into the executable under their original
3342
+ * relative paths. At runtime they are reachable via `node:fs` and
3343
+ * `Bun.file()` relative to `import.meta.dir`.
3029
3344
  *
3030
- * Standalone-only: applies only when building/running the standalone executable.
3345
+ * Equivalent CLI flag: `--asset` (repeatable)
3346
+ */
3347
+ assets?: string[];
3348
+ /**
3349
+ * Whether the standalone executable loads .env files when it runs
3031
3350
  *
3032
3351
  * Equivalent CLI flags: `--compile-autoload-dotenv`, `--no-compile-autoload-dotenv`
3033
3352
  *
@@ -3035,9 +3354,7 @@ declare module "bun" {
3035
3354
  */
3036
3355
  autoloadDotenv?: boolean;
3037
3356
  /**
3038
- * Whether to autoload bunfig.toml when the standalone executable runs
3039
- *
3040
- * Standalone-only: applies only when building/running the standalone executable.
3357
+ * Whether the standalone executable loads bunfig.toml when it runs
3041
3358
  *
3042
3359
  * Equivalent CLI flags: `--compile-autoload-bunfig`, `--no-compile-autoload-bunfig`
3043
3360
  *
@@ -3045,9 +3362,7 @@ declare module "bun" {
3045
3362
  */
3046
3363
  autoloadBunfig?: boolean;
3047
3364
  /**
3048
- * Whether to autoload tsconfig.json when the standalone executable runs
3049
- *
3050
- * Standalone-only: applies only when building/running the standalone executable.
3365
+ * Whether the standalone executable loads tsconfig.json when it runs
3051
3366
  *
3052
3367
  * Equivalent CLI flags: `--compile-autoload-tsconfig`, `--no-compile-autoload-tsconfig`
3053
3368
  *
@@ -3055,9 +3370,7 @@ declare module "bun" {
3055
3370
  */
3056
3371
  autoloadTsconfig?: boolean;
3057
3372
  /**
3058
- * Whether to autoload package.json when the standalone executable runs
3059
- *
3060
- * Standalone-only: applies only when building/running the standalone executable.
3373
+ * Whether the standalone executable loads package.json when it runs
3061
3374
  *
3062
3375
  * Equivalent CLI flags: `--compile-autoload-package-json`, `--no-compile-autoload-package-json`
3063
3376
  *
@@ -3078,7 +3391,7 @@ declare module "bun" {
3078
3391
  /**
3079
3392
  * Hash and verify passwords using argon2 or bcrypt
3080
3393
  *
3081
- * These are fast APIs that can run in a worker thread if used asynchronously.
3394
+ * The asynchronous functions run in a worker thread.
3082
3395
  *
3083
3396
  * @see [Bun.password API docs](https://bun.com/guides/util/hash-a-password)
3084
3397
  *
@@ -3089,12 +3402,12 @@ declare module "bun" {
3089
3402
  algorithm: "argon2id" | "argon2d" | "argon2i";
3090
3403
 
3091
3404
  /**
3092
- * Memory cost, which defines the memory usage, given in kibibytes.
3405
+ * Memory usage, in kibibytes. Minimum 8.
3093
3406
  */
3094
3407
  memoryCost?: number;
3095
3408
  /**
3096
- * Defines the amount of computation realized and therefore the execution
3097
- * time, given in number of iterations.
3409
+ * Number of iterations. More iterations means more computation and a
3410
+ * longer hash time.
3098
3411
  */
3099
3412
  timeCost?: number;
3100
3413
  }
@@ -3103,7 +3416,9 @@ declare module "bun" {
3103
3416
  algorithm: "bcrypt";
3104
3417
 
3105
3418
  /**
3106
- * A number between 4 and 31. The default is 10.
3419
+ * A number between 4 and 31.
3420
+ *
3421
+ * @default 10
3107
3422
  */
3108
3423
  cost?: number;
3109
3424
  }
@@ -3113,14 +3428,13 @@ declare module "bun" {
3113
3428
 
3114
3429
  /**
3115
3430
  * Hash and verify passwords using argon2 or bcrypt. The default is argon2.
3116
- * Password hashing functions are necessarily slow, and this object will
3117
- * automatically run in a worker thread.
3431
+ * Password hashing functions are necessarily slow, so the asynchronous
3432
+ * functions run in a worker thread.
3118
3433
  *
3119
- * @see [Bun.password API docs](https://bun.com/guides/util/hash-a-password)
3434
+ * The underlying implementation of these functions is provided by the
3435
+ * `rust-argon2` and `bcrypt` Rust crates.
3120
3436
  *
3121
- * The underlying implementation of these functions are provided by the Zig
3122
- * Standard Library. Thanks to \@jedisct1 and other Zig contributors for their
3123
- * work on this.
3437
+ * @see [Bun.password API docs](https://bun.com/guides/util/hash-a-password)
3124
3438
  *
3125
3439
  * @example
3126
3440
  * **Example with argon2**
@@ -3160,7 +3474,7 @@ declare module "bun" {
3160
3474
  *
3161
3475
  * @throws If the algorithm is specified and does not match the hash
3162
3476
  * @throws If the algorithm is invalid
3163
- * @throws if the hash is invalid
3477
+ * @throws If the hash is invalid
3164
3478
  */
3165
3479
  verify(
3166
3480
  /**
@@ -3175,7 +3489,7 @@ declare module "bun" {
3175
3489
  */
3176
3490
  hash: Bun.StringOrBuffer,
3177
3491
  /**
3178
- * If not specified, the algorithm will be inferred from the hash.
3492
+ * If not specified, the algorithm is inferred from the hash.
3179
3493
  *
3180
3494
  * If specified and the algorithm does not match the hash, this function
3181
3495
  * throws an error.
@@ -3213,7 +3527,8 @@ declare module "bun" {
3213
3527
  */
3214
3528
  password: Bun.StringOrBuffer,
3215
3529
  /**
3216
- * When using bcrypt, passwords exceeding 72 characters will be SHA512'd before
3530
+ * When using bcrypt, passwords longer than 72 bytes are hashed with
3531
+ * SHA-512 before being passed to bcrypt
3217
3532
  *
3218
3533
  * @default "argon2id"
3219
3534
  */
@@ -3221,13 +3536,14 @@ declare module "bun" {
3221
3536
  ): Promise<string>;
3222
3537
 
3223
3538
  /**
3224
- * Synchronously hash and verify passwords using argon2 or bcrypt. The default is argon2.
3225
- * Warning: password hashing is slow, consider using {@link Bun.password.verify}
3226
- * instead which runs in a worker thread.
3539
+ * Synchronously verify a password against a previously hashed password using
3540
+ * argon2 or bcrypt. The default is argon2.
3227
3541
  *
3228
- * The underlying implementation of these functions are provided by the Zig
3229
- * Standard Library. Thanks to \@jedisct1 and other Zig contributors for their
3230
- * work on this.
3542
+ * Warning: password hashing is slow. Prefer {@link Bun.password.verify},
3543
+ * which runs in a worker thread.
3544
+ *
3545
+ * The underlying implementation of these functions is provided by the
3546
+ * `rust-argon2` and `bcrypt` Rust crates.
3231
3547
  *
3232
3548
  * @example
3233
3549
  * **Example with argon2**
@@ -3260,19 +3576,19 @@ declare module "bun" {
3260
3576
  */
3261
3577
  hash: Bun.StringOrBuffer,
3262
3578
  /**
3263
- * If not specified, the algorithm will be inferred from the hash.
3579
+ * If not specified, the algorithm is inferred from the hash.
3264
3580
  */
3265
3581
  algorithm?: Password.AlgorithmLabel,
3266
3582
  ): boolean;
3267
3583
 
3268
3584
  /**
3269
- * Synchronously hash and verify passwords using argon2 or bcrypt. The default is argon2.
3270
- * Warning: password hashing is slow, consider using {@link Bun.password.hash}
3271
- * instead which runs in a worker thread.
3585
+ * Synchronously hash a password using argon2 or bcrypt. The default is argon2.
3586
+ *
3587
+ * Warning: password hashing is slow. Prefer {@link Bun.password.hash},
3588
+ * which runs in a worker thread.
3272
3589
  *
3273
- * The underlying implementation of these functions are provided by the Zig
3274
- * Standard Library. Thanks to \@jedisct1 and other Zig contributors for their
3275
- * work on this.
3590
+ * The underlying implementation of these functions is provided by the
3591
+ * `rust-argon2` and `bcrypt` Rust crates.
3276
3592
  *
3277
3593
  * @example
3278
3594
  * **Example with argon2**
@@ -3305,7 +3621,8 @@ declare module "bun" {
3305
3621
  password: Bun.StringOrBuffer,
3306
3622
 
3307
3623
  /**
3308
- * When using bcrypt, passwords exceeding 72 characters will be SHA256'd before
3624
+ * When using bcrypt, passwords longer than 72 bytes are hashed with
3625
+ * SHA-512 before being passed to bcrypt
3309
3626
  *
3310
3627
  * @default "argon2id"
3311
3628
  */
@@ -3318,7 +3635,7 @@ declare module "bun" {
3318
3635
  *
3319
3636
  * Uses platform-specific secure storage:
3320
3637
  * - **macOS**: Keychain Services
3321
- * - **Linux**: libsecret (GNOME Keyring, KWallet, etc.)
3638
+ * - **Linux**: libsecret (GNOME Keyring, KWallet, and others)
3322
3639
  * - **Windows**: Windows Credential Manager
3323
3640
  *
3324
3641
  * @category Security
@@ -3384,7 +3701,7 @@ declare module "bun" {
3384
3701
  /**
3385
3702
  * Retrieve a stored credential from the operating system's secure storage.
3386
3703
  *
3387
- * @param options - The service and name identifying the credential
3704
+ * @param options The service and name identifying the credential
3388
3705
  * @returns The stored credential value, or null if not found
3389
3706
  *
3390
3707
  * @example
@@ -3413,15 +3730,14 @@ declare module "bun" {
3413
3730
  * The service or application name.
3414
3731
  *
3415
3732
  * Use a unique identifier for your application to avoid conflicts.
3416
- * Consider using reverse domain notation for production apps (e.g., "com.example.myapp").
3733
+ * Consider reverse domain notation for production apps, for example
3734
+ * "com.example.myapp".
3417
3735
  */
3418
3736
  service: string;
3419
3737
 
3420
3738
  /**
3421
- * The account name, username, or resource identifier.
3422
- *
3423
- * This identifies the specific credential within the service.
3424
- * Common patterns include usernames, email addresses, or resource URLs.
3739
+ * The account name, username, or resource identifier (such as an email
3740
+ * address or URL) that identifies the credential within the service.
3425
3741
  */
3426
3742
  name: string;
3427
3743
  }): Promise<string | null>;
@@ -3429,11 +3745,11 @@ declare module "bun" {
3429
3745
  /**
3430
3746
  * Store or update a credential in the operating system's secure storage.
3431
3747
  *
3432
- * If a credential already exists for the given service/name combination, it will be replaced.
3748
+ * If a credential already exists for the given service/name combination, it is replaced.
3433
3749
  * The credential is encrypted by the operating system and only accessible to the current user.
3434
3750
  *
3435
- * @param options - The service and name identifying the credential
3436
- * @param value - The secret value to store (e.g., password, API key, token)
3751
+ * @param options The service and name identifying the credential, and the value to store
3752
+ * @param value The secret value to store, such as a password, API key, or token
3437
3753
  *
3438
3754
  * @example
3439
3755
  * ```ts
@@ -3495,26 +3811,23 @@ declare module "bun" {
3495
3811
  * The service or application name.
3496
3812
  *
3497
3813
  * Use a unique identifier for your application to avoid conflicts.
3498
- * Consider using reverse domain notation for production apps (e.g., "com.example.myapp").
3814
+ * Consider reverse domain notation for production apps, for example
3815
+ * "com.example.myapp".
3499
3816
  */
3500
3817
  service: string;
3501
3818
 
3502
3819
  /**
3503
- * The account name, username, or resource identifier.
3504
- *
3505
- * This identifies the specific credential within the service.
3506
- * Common patterns include usernames, email addresses, or resource URLs.
3820
+ * The account name, username, or resource identifier (such as an email
3821
+ * address or URL) that identifies the credential within the service.
3507
3822
  */
3508
3823
  name: string;
3509
3824
 
3510
3825
  /**
3511
- * The secret value to store.
3826
+ * The secret value to store, such as a password, API key, or token.
3827
+ * The operating system encrypts the value before storing it.
3512
3828
  *
3513
- * This should be a sensitive credential like a password, API key, or token.
3514
- * The value is encrypted by the operating system before storage.
3515
- *
3516
- * Note: To delete a credential, use the delete() method or pass an empty string.
3517
- * An empty string value will delete the credential if it exists.
3829
+ * An empty string deletes the credential if it exists, the same as
3830
+ * calling `delete()`.
3518
3831
  */
3519
3832
  value: string;
3520
3833
 
@@ -3533,7 +3846,7 @@ declare module "bun" {
3533
3846
  /**
3534
3847
  * Delete a stored credential from the operating system's secure storage.
3535
3848
  *
3536
- * @param options - The service and name identifying the credential
3849
+ * @param options The service and name identifying the credential
3537
3850
  * @returns true if a credential was deleted, false if not found
3538
3851
  *
3539
3852
  * @example
@@ -3580,22 +3893,23 @@ declare module "bun" {
3580
3893
  * The service or application name.
3581
3894
  *
3582
3895
  * Use a unique identifier for your application to avoid conflicts.
3583
- * Consider using reverse domain notation for production apps (e.g., "com.example.myapp").
3896
+ * Consider reverse domain notation for production apps, for example
3897
+ * "com.example.myapp".
3584
3898
  */
3585
3899
  service: string;
3586
3900
 
3587
3901
  /**
3588
- * The account name, username, or resource identifier.
3589
- *
3590
- * This identifies the specific credential within the service.
3591
- * Common patterns include usernames, email addresses, or resource URLs.
3902
+ * The account name, username, or resource identifier (such as an email
3903
+ * address or URL) that identifies the credential within the service.
3592
3904
  */
3593
3905
  name: string;
3594
3906
  }): Promise<boolean>;
3595
3907
  };
3596
3908
 
3597
3909
  /**
3598
- * A build artifact represents a file that was generated by the bundler @see {@link Bun.build}
3910
+ * A file generated by the bundler.
3911
+ *
3912
+ * @see {@link Bun.build}
3599
3913
  *
3600
3914
  * @category Bundler
3601
3915
  */
@@ -3617,19 +3931,15 @@ declare module "bun" {
3617
3931
  success: boolean;
3618
3932
  logs: Array<BuildMessage | ResolveMessage>;
3619
3933
  /**
3620
- * Metadata about the build including inputs, outputs, and their relationships.
3934
+ * Metadata about the build:
3935
+ * - **inputs**: every bundled source file with its byte size, imports, and format
3936
+ * - **outputs**: every generated file with its byte size, the inputs that
3937
+ * contributed to it, imports between chunks, and exports
3621
3938
  *
3622
3939
  * Only present when {@link BuildConfig.metafile} is `true`.
3623
3940
  *
3624
- * The metafile contains detailed information about:
3625
- * - **inputs**: All source files that were bundled, their byte sizes, imports, and format
3626
- * - **outputs**: All generated output files, their byte sizes, which inputs contributed to each output, imports between chunks, and exports
3627
- *
3628
- * This can be used for:
3629
- * - Bundle size analysis and visualization
3630
- * - Detecting unused code or dependencies
3631
- * - Understanding the dependency graph
3632
- * - Integration with bundle analyzer tools
3941
+ * Use it for bundle size analysis, inspecting the dependency graph, or as
3942
+ * input to bundle analyzer tools.
3633
3943
  *
3634
3944
  * @example
3635
3945
  * ```ts
@@ -3662,12 +3972,15 @@ declare module "bun" {
3662
3972
  }
3663
3973
 
3664
3974
  /**
3665
- * Metafile structure containing build metadata for analysis.
3975
+ * Build metadata: every input and output file, its size, and the imports
3976
+ * between them.
3977
+ *
3978
+ * @see {@link BuildOutput.metafile}
3666
3979
  *
3667
3980
  * @category Bundler
3668
3981
  */
3669
3982
  interface BuildMetafile {
3670
- /** Information about all input source files */
3983
+ /** Input source files, keyed by path */
3671
3984
  inputs: {
3672
3985
  [path: string]: {
3673
3986
  /** Size of the input file in bytes */
@@ -3682,14 +3995,14 @@ declare module "bun" {
3682
3995
  original?: string;
3683
3996
  /** Whether this import is external to the bundle */
3684
3997
  external?: boolean;
3685
- /** Import attributes (e.g., `{ type: "json" }`) */
3998
+ /** Import attributes, for example `{ type: "json" }` */
3686
3999
  with?: Record<string, string>;
3687
4000
  }>;
3688
4001
  /** Module format of the input file */
3689
4002
  format?: "esm" | "cjs" | "json" | "css";
3690
4003
  };
3691
4004
  };
3692
- /** Information about all output files */
4005
+ /** Output files, keyed by path */
3693
4006
  outputs: {
3694
4007
  [path: string]: {
3695
4008
  /** Size of the output file in bytes */
@@ -3710,9 +4023,9 @@ declare module "bun" {
3710
4023
  }>;
3711
4024
  /** List of exported names from this output */
3712
4025
  exports: string[];
3713
- /** Entry point path if this output is an entry point */
4026
+ /** Entrypoint path, if this output is an entrypoint */
3714
4027
  entryPoint?: string;
3715
- /** Path to the associated CSS bundle (for JS entry points with CSS) */
4028
+ /** Path to the associated CSS bundle (for JS entrypoints with CSS) */
3716
4029
  cssBundle?: string;
3717
4030
  };
3718
4031
  };
@@ -3721,7 +4034,7 @@ declare module "bun" {
3721
4034
  /**
3722
4035
  * Bundles JavaScript, TypeScript, CSS, HTML and other supported files into optimized outputs.
3723
4036
  *
3724
- * @param config - Build configuration options
4037
+ * @param config Build configuration options
3725
4038
  * @returns Promise that resolves to build output containing generated artifacts and build status
3726
4039
  * @throws {AggregateError} When build fails and config.throw is true (default in Bun 1.2+)
3727
4040
  *
@@ -3831,7 +4144,7 @@ declare module "bun" {
3831
4144
  *```
3832
4145
  *
3833
4146
  * @example
3834
- * Implement comprehensive error handling with position info
4147
+ * Handle build errors with position info
3835
4148
  *```ts
3836
4149
  * try {
3837
4150
  * const result = await Bun.build({
@@ -3982,7 +4295,7 @@ declare module "bun" {
3982
4295
  passphrase?: string;
3983
4296
 
3984
4297
  /**
3985
- * File path to a .pem file custom Diffie Helman parameters
4298
+ * File path to a `.pem` file containing custom Diffie-Hellman parameters
3986
4299
  */
3987
4300
  dhParamsFile?: string;
3988
4301
 
@@ -3992,8 +4305,8 @@ declare module "bun" {
3992
4305
  serverName?: string;
3993
4306
 
3994
4307
  /**
3995
- * This sets `OPENSSL_RELEASE_BUFFERS` to 1.
3996
- * It reduces overall performance but saves some memory.
4308
+ * Sets `OPENSSL_RELEASE_BUFFERS` to 1.
4309
+ * Reduces overall performance but saves some memory.
3997
4310
  * @default false
3998
4311
  */
3999
4312
  lowMemoryMode?: boolean;
@@ -4005,7 +4318,7 @@ declare module "bun" {
4005
4318
  rejectUnauthorized?: boolean;
4006
4319
 
4007
4320
  /**
4008
- * If set to `true`, the server will request a client certificate.
4321
+ * If set to `true`, the server requests a client certificate.
4009
4322
  *
4010
4323
  * Default is `false`.
4011
4324
  */
@@ -4025,25 +4338,25 @@ declare module "bun" {
4025
4338
  * including the root CA (the root CA must be pre-known to the peer,
4026
4339
  * see ca). When providing multiple cert chains, they do not have to
4027
4340
  * be in the same order as their private keys in key. If the
4028
- * intermediate certificates are not provided, the peer will not be
4029
- * able to validate the certificate, and the handshake will fail.
4341
+ * intermediate certificates are not provided, the peer cannot
4342
+ * validate the certificate, and the handshake fails.
4030
4343
  */
4031
4344
  cert?: string | BufferSource | BunFile | Array<string | BufferSource | BunFile> | undefined;
4032
4345
  /**
4033
4346
  * Private keys in PEM format. PEM allows the option of private keys
4034
- * being encrypted. Encrypted keys will be decrypted with
4347
+ * being encrypted. Encrypted keys are decrypted with
4035
4348
  * options.passphrase. Multiple keys using different algorithms can be
4036
4349
  * provided either as an array of unencrypted key strings or buffers,
4037
4350
  * or an array of objects in the form {pem: <string|buffer>[,
4038
4351
  * passphrase: <string>]}. The object form can only occur in an array.
4039
- * object.passphrase is optional. Encrypted keys will be decrypted with
4352
+ * object.passphrase is optional. Encrypted keys are decrypted with
4040
4353
  * object.passphrase if provided, or options.passphrase if it is not.
4041
4354
  */
4042
4355
  key?: string | BufferSource | BunFile | Array<string | BufferSource | BunFile> | undefined;
4043
4356
  /**
4044
4357
  * Optionally affect the OpenSSL protocol behavior, which is not
4045
- * usually necessary. This should be used carefully if at all! Value is
4046
- * a numeric bitmask of the SSL_OP_* options from OpenSSL Options
4358
+ * usually necessary. Use it carefully, if at all. Value is a numeric
4359
+ * bitmask of the SSL_OP_* options from OpenSSL Options
4047
4360
  */
4048
4361
  secureOptions?: number | undefined; // Value is a numeric bitmask of the `SSL_OP_*` options
4049
4362
 
@@ -4076,9 +4389,9 @@ declare module "bun" {
4076
4389
  /**
4077
4390
  * [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) powered by the fastest system calls available for operating on files.
4078
4391
  *
4079
- * This Blob is lazy. That means it won't do any work until you read from it.
4392
+ * This Blob is lazy: it does no work until you read from it.
4080
4393
  *
4081
- * - `size` will not be valid until the contents of the file are read at least once.
4394
+ * - `size` is not valid until the contents of the file are read at least once.
4082
4395
  * - `type` is auto-set based on the file extension when possible
4083
4396
  *
4084
4397
  * @example
@@ -4095,55 +4408,71 @@ declare module "bun" {
4095
4408
  * "Hello, world!"
4096
4409
  * );
4097
4410
  * ```
4098
- * @param path The path to the file (lazily loaded) if the path starts with `s3://` it will behave like {@link S3File}
4411
+ * @param path The path to the file (lazily loaded). If the path starts with `s3://`, the file behaves like {@link S3File}
4099
4412
  */
4100
4413
  function file(path: string | URL, options?: BlobPropertyBag): BunFile;
4101
4414
 
4102
4415
  /**
4103
- * A list of files embedded into the standalone executable. Lexigraphically sorted by name.
4416
+ * A list of files embedded into the standalone executable, lexicographically sorted by name.
4104
4417
  *
4105
- * If the process is not a standalone executable, this returns an empty array.
4418
+ * If the process is not a standalone executable, this array is empty.
4106
4419
  */
4107
4420
  const embeddedFiles: ReadonlyArray<Blob>;
4108
4421
 
4109
4422
  /**
4110
- * `Blob` that leverages the fastest system calls available to operate on files.
4423
+ * `true` when the current process is a standalone executable produced by
4424
+ * `bun build --compile`, `false` otherwise.
4425
+ *
4426
+ * Unlike checking `Bun.embeddedFiles.length > 0`, reading this property does
4427
+ * not materialize embedded files as `Blob` objects.
4428
+ *
4429
+ * @example
4430
+ * ```ts
4431
+ * if (Bun.isStandaloneExecutable) {
4432
+ * console.log("Running from a compiled binary");
4433
+ * }
4434
+ * ```
4435
+ */
4436
+ const isStandaloneExecutable: boolean;
4437
+
4438
+ /**
4439
+ * `Blob` that uses the fastest system calls available to operate on files.
4111
4440
  *
4112
- * This Blob is lazy. It won't do any work until you read from it. Errors propagate as promise rejections.
4441
+ * This Blob is lazy: it does no work until you read from it. Errors propagate as promise rejections.
4113
4442
  *
4114
- * `Blob.size` will not be valid until the contents of the file are read at least once.
4115
- * `Blob.type` will have a default set based on the file extension
4443
+ * `Blob.size` is not valid until the contents of the file are read at least once.
4444
+ * `Blob.type` is set based on the file extension when possible
4116
4445
  *
4117
4446
  * @example
4118
4447
  * ```js
4119
- * const file = Bun.file(new TextEncoder.encode("./hello.json"));
4448
+ * const file = Bun.file(new TextEncoder().encode("./hello.json"));
4120
4449
  * console.log(file.type); // "application/json"
4121
4450
  * ```
4122
4451
  *
4123
- * @param path The path to the file as a byte buffer (the buffer is copied) if the path starts with `s3://` it will behave like {@link S3File}
4452
+ * @param path The path to the file as a byte buffer (the buffer is copied). If the path starts with `s3://`, the file behaves like {@link S3File}
4124
4453
  */
4125
4454
  function file(path: ArrayBufferLike | Uint8Array<ArrayBuffer>, options?: BlobPropertyBag): BunFile;
4126
4455
 
4127
4456
  /**
4128
4457
  * [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) powered by the fastest system calls available for operating on files.
4129
4458
  *
4130
- * This Blob is lazy. That means it won't do any work until you read from it.
4459
+ * This Blob is lazy: it does no work until you read from it.
4131
4460
  *
4132
- * - `size` will not be valid until the contents of the file are read at least once.
4461
+ * - `size` is not valid until the contents of the file are read at least once.
4133
4462
  *
4134
4463
  * @example
4135
4464
  * ```js
4136
4465
  * const file = Bun.file(fd);
4137
4466
  * ```
4138
4467
  *
4139
- * @param fileDescriptor The file descriptor of the file
4468
+ * @param fileDescriptor An open file descriptor
4140
4469
  */
4141
4470
  function file(fileDescriptor: number, options?: BlobPropertyBag): BunFile;
4142
4471
 
4143
4472
  /**
4144
4473
  * Allocate a new [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) without zeroing the bytes.
4145
4474
  *
4146
- * This can be 3.5x faster than `new Uint8Array(size)`, but if you send uninitialized memory to your users (even unintentionally), it can potentially leak anything recently in memory.
4475
+ * This can be 3.5x faster than `new Uint8Array(size)`, but if you send uninitialized memory to your users (even unintentionally), it can leak anything recently in memory.
4147
4476
  */
4148
4477
  function allocUnsafe(size: number): Uint8Array<ArrayBuffer>;
4149
4478
 
@@ -4221,7 +4550,8 @@ declare module "bun" {
4221
4550
  /**
4222
4551
  * HTTP proxy to use for the WebSocket connection.
4223
4552
  *
4224
- * Can be a string URL or an object with `url` and optional `headers`.
4553
+ * Can be a string URL, a URL instance, or an object with `url` and
4554
+ * optional `headers`.
4225
4555
  *
4226
4556
  * @example
4227
4557
  * ```ts
@@ -4248,11 +4578,12 @@ declare module "bun" {
4248
4578
  */
4249
4579
  proxy?:
4250
4580
  | string
4581
+ | URL
4251
4582
  | {
4252
4583
  /**
4253
- * The proxy URL (http:// or https://)
4584
+ * The proxy URL (http:// or https://), as a string or a `URL`.
4254
4585
  */
4255
- url: string;
4586
+ url: string | URL;
4256
4587
  /**
4257
4588
  * Custom headers to send to the proxy server.
4258
4589
  * Supports plain objects or Headers class instances.
@@ -4385,8 +4716,10 @@ declare module "bun" {
4385
4716
 
4386
4717
  /**
4387
4718
  * Closes the WebSocket connection
4388
- * @param code A numeric value indicating the status code
4389
- * @param reason A human-readable string explaining why the connection is closing
4719
+ * @param code A close code an endpoint is allowed to send (RFC 6455): `1000`-`1014` except
4720
+ * the reserved `1004`-`1006`, or `3000`-`4999`. Any other code throws an `InvalidAccessError`.
4721
+ * @param reason A human-readable string explaining why the connection is closing. Throws a
4722
+ * `SyntaxError` if longer than 123 bytes of UTF-8
4390
4723
  */
4391
4724
  close(code?: number, reason?: string): void;
4392
4725
 
@@ -4452,7 +4785,7 @@ declare module "bun" {
4452
4785
  }
4453
4786
 
4454
4787
  /**
4455
- * Pretty-print an object the same as {@link console.log} to a `string`
4788
+ * Pretty-prints an object to a `string`, the same as {@link console.log}
4456
4789
  *
4457
4790
  * Supports JSX
4458
4791
  *
@@ -4462,7 +4795,7 @@ declare module "bun" {
4462
4795
  function inspect(arg: any, options?: BunInspectOptions): string;
4463
4796
  namespace inspect {
4464
4797
  /**
4465
- * That can be used to declare custom inspect functions.
4798
+ * Symbol for declaring a custom inspect function on an object. Same as `util.inspect.custom` in Node.js.
4466
4799
  */
4467
4800
  const custom: typeof import("util").inspect.custom;
4468
4801
 
@@ -4481,29 +4814,39 @@ declare module "bun" {
4481
4814
  */
4482
4815
  sync?: boolean;
4483
4816
  /**
4484
- * Allow other processes to see results instantly?
4485
- * This enables MAP_SHARED. If false, it enables MAP_PRIVATE.
4817
+ * Whether other processes see writes immediately.
4818
+ * `true` maps with MAP_SHARED; `false` maps with MAP_PRIVATE.
4486
4819
  * @default true
4487
4820
  */
4488
4821
  shared?: boolean;
4822
+ /**
4823
+ * Byte offset into the file where the mapping starts.
4824
+ * @default 0
4825
+ */
4826
+ offset?: number;
4827
+ /**
4828
+ * Maximum number of bytes to map. Clamped to the file size
4829
+ * (minus `offset`). Defaults to mapping the rest of the file.
4830
+ */
4831
+ size?: number;
4489
4832
  }
4490
4833
  /**
4491
4834
  * Open a file as a live-updating `Uint8Array` without copying memory
4492
4835
  * - Writing to the array writes to the file.
4493
4836
  * - Reading from the array reads from the file.
4494
4837
  *
4495
- * This uses the [`mmap()`](https://man7.org/linux/man-pages/man2/mmap.2.html) syscall under the hood.
4838
+ * This uses the [`mmap()`](https://man7.org/linux/man-pages/man2/mmap.2.html) syscall.
4496
4839
  *
4497
4840
  * ---
4498
4841
  *
4499
4842
  * This API inherently has some rough edges:
4500
- * - It does not support empty files. It will throw a `SystemError` with `EINVAL`
4501
- * - Usage on shared/networked filesystems is discouraged. It will be very slow.
4502
- * - If you delete or truncate the file, that will crash bun. This is called a segmentation fault.
4843
+ * - It does not support empty files. It throws a `SystemError` with `EINVAL`
4844
+ * - Usage on shared/networked filesystems is discouraged. It is very slow.
4845
+ * - Deleting or truncating the file crashes Bun with a segmentation fault.
4503
4846
  *
4504
4847
  * ---
4505
4848
  *
4506
- * To close the file, set the array to `null` and it will be garbage collected eventually.
4849
+ * To close the file, set the array to `null`; it is garbage collected eventually.
4507
4850
  */
4508
4851
  function mmap(path: PathLike, opts?: MMapOptions): Uint8Array<ArrayBuffer>;
4509
4852
 
@@ -4544,7 +4887,7 @@ declare module "bun" {
4544
4887
  | { toString(): string };
4545
4888
 
4546
4889
  /**
4547
- * Converts formats of colors
4890
+ * Converts a color to a different format
4548
4891
  *
4549
4892
  * @category Utilities
4550
4893
  *
@@ -4581,11 +4924,11 @@ declare module "bun" {
4581
4924
  */
4582
4925
  | "HEX"
4583
4926
  /**
4584
- * @example hsl(35.764706, 1, 0.5)
4927
+ * @example hsl(35.764706, 100%, 50%)
4585
4928
  */
4586
4929
  | "hsl"
4587
4930
  /**
4588
- * @example lab(0.72732764, 33.938198, -25.311619)
4931
+ * @example lab(72.732764% 33.938198 -25.311619)
4589
4932
  */
4590
4933
  | "lab"
4591
4934
  /**
@@ -4607,17 +4950,17 @@ declare module "bun" {
4607
4950
  /**
4608
4951
  * Convert any color input to rgb
4609
4952
  * @param input Any color input
4610
- * @param outputFormat Specify `[rgb]` to output as an array with `r`, `g`, and `b` properties
4953
+ * @param outputFormat Specify `[rgb]` to output as a `[r, g, b]` array
4611
4954
  */
4612
4955
  function color(input: ColorInput, outputFormat: "[rgb]"): [number, number, number] | null;
4613
4956
  /**
4614
4957
  * Convert any color input to rgba
4615
4958
  * @param input Any color input
4616
- * @param outputFormat Specify `[rgba]` to output as an array with `r`, `g`, `b`, and `a` properties
4959
+ * @param outputFormat Specify `[rgba]` to output as a `[r, g, b, a]` array
4617
4960
  */
4618
4961
  function color(input: ColorInput, outputFormat: "[rgba]"): [number, number, number, number] | null;
4619
4962
  /**
4620
- * Convert any color input to a number
4963
+ * Convert any color input to rgb
4621
4964
  * @param input Any color input
4622
4965
  * @param outputFormat Specify `{rgb}` to output as an object with `r`, `g`, and `b` properties
4623
4966
  */
@@ -4625,7 +4968,7 @@ declare module "bun" {
4625
4968
  /**
4626
4969
  * Convert any color input to rgba
4627
4970
  * @param input Any color input
4628
- * @param outputFormat Specify {rgba} to output as an object with `r`, `g`, `b`, and `a` properties
4971
+ * @param outputFormat Specify `{rgba}` to output as an object with `r`, `g`, `b`, and `a` properties
4629
4972
  */
4630
4973
  function color(input: ColorInput, outputFormat: "{rgba}"): { r: number; g: number; b: number; a: number } | null;
4631
4974
  /**
@@ -4636,11 +4979,11 @@ declare module "bun" {
4636
4979
  function color(input: ColorInput, outputFormat: "number"): number | null;
4637
4980
 
4638
4981
  /**
4639
- * Bun.semver provides a fast way to parse and compare version numbers.
4982
+ * Bun.semver parses and compares version numbers.
4640
4983
  */
4641
4984
  namespace semver {
4642
4985
  /**
4643
- * Test if the version satisfies the range. Stringifies both arguments. Returns `true` or `false`.
4986
+ * Tests whether `version` satisfies `range`. Both arguments are stringified first.
4644
4987
  */
4645
4988
  function satisfies(version: StringLike, range: StringLike): boolean;
4646
4989
 
@@ -4655,9 +4998,9 @@ declare module "bun" {
4655
4998
  /**
4656
4999
  * Cast bytes to a `String` without copying. This is the fastest way to get a `String` from a `Uint8Array` or `ArrayBuffer`.
4657
5000
  *
4658
- * **Only use this for ASCII strings**. If there are non-ascii characters, your application may crash and/or very confusing bugs will happen such as `"foo" !== "foo"`.
5001
+ * **Only use this for ASCII strings**. If there are non-ASCII characters, your application may crash or hit confusing bugs such as `"foo" !== "foo"`.
4659
5002
  *
4660
- * **The input buffer must not be garbage collected**. That means you will need to hold on to it for the duration of the string's lifetime.
5003
+ * **The input buffer must not be garbage collected**. Hold a reference to it for the lifetime of the string.
4661
5004
  */
4662
5005
  function arrayBufferToString(buffer: Uint8Array<ArrayBuffer> | ArrayBufferLike): string;
4663
5006
 
@@ -4666,7 +5009,7 @@ declare module "bun" {
4666
5009
  *
4667
5010
  * **The input must be a UTF-16 encoded string**. This API does no validation whatsoever.
4668
5011
  *
4669
- * **The input buffer must not be garbage collected**. That means you will need to hold on to it for the duration of the string's lifetime.
5012
+ * **The input buffer must not be garbage collected**. Hold a reference to it for the lifetime of the string.
4670
5013
  */
4671
5014
 
4672
5015
  function arrayBufferToString(buffer: Uint16Array): string;
@@ -4683,7 +5026,7 @@ declare module "bun" {
4683
5026
  *
4684
5027
  * `BUN_GARBAGE_COLLECTOR_LEVEL` environment variable is also supported.
4685
5028
  *
4686
- * @param level
5029
+ * @param level The level to set: `0`, `1`, or `2`
4687
5030
  * @returns The previous level
4688
5031
  */
4689
5032
  function gcAggressionLevel(level?: 0 | 1 | 2): 0 | 1 | 2;
@@ -4692,21 +5035,33 @@ declare module "bun" {
4692
5035
  * Dump the mimalloc heap to the console
4693
5036
  */
4694
5037
  function mimallocDump(): void;
5038
+
5039
+ /**
5040
+ * Accurate per-process memory footprint in bytes.
5041
+ *
5042
+ * Unlike `process.memoryUsage.rss()`, this excludes pages already
5043
+ * returned to the OS that the kernel keeps mapped lazily (Darwin's
5044
+ * `MADV_FREE_REUSABLE`), so leak tests are platform-comparable.
5045
+ *
5046
+ * Backed by `task_info(TASK_VM_INFO).phys_footprint` on Darwin, `Pss:`
5047
+ * from `/proc/self/smaps_rollup` on Linux, and `PrivateUsage` on Windows.
5048
+ * Returns `undefined` on platforms with no accurate accessor; callers
5049
+ * should fall back: `Bun.unsafe.memoryFootprint() ?? process.memoryUsage.rss()`.
5050
+ */
5051
+ function memoryFootprint(): number | undefined;
4695
5052
  }
4696
5053
 
4697
5054
  type DigestEncoding = "utf8" | "ucs2" | "utf16le" | "latin1" | "ascii" | "base64" | "base64url" | "hex";
4698
5055
 
4699
5056
  /**
4700
- * Are ANSI colors enabled for stdin and stdout?
5057
+ * Whether ANSI colors are enabled for stdin and stdout
4701
5058
  *
4702
5059
  * Used for {@link console.log}
4703
5060
  */
4704
5061
  const enableANSIColors: boolean;
4705
5062
 
4706
5063
  /**
4707
- * What script launched Bun?
4708
- *
4709
- * Absolute file path
5064
+ * Absolute path of the script that launched Bun
4710
5065
  *
4711
5066
  * @example "/never-gonna-give-you-up.js"
4712
5067
  */
@@ -4724,11 +5079,9 @@ declare module "bun" {
4724
5079
  function gc(force?: boolean): void;
4725
5080
 
4726
5081
  /**
4727
- * JavaScriptCore engine's internal heap snapshot
4728
- *
4729
- * I don't know how to make this something Chrome or Safari can read.
5082
+ * JavaScriptCore engine's internal heap snapshot format
4730
5083
  *
4731
- * If you have any ideas, please file an issue https://github.com/oven-sh/bun
5084
+ * For a snapshot Chrome DevTools can read, use {@link generateHeapSnapshot} with the `"v8"` format.
4732
5085
  */
4733
5086
  interface HeapSnapshot {
4734
5087
  /** 2 */
@@ -4746,35 +5099,29 @@ declare module "bun" {
4746
5099
  }
4747
5100
 
4748
5101
  /**
4749
- * Returns the number of nanoseconds since the process was started.
5102
+ * Returns the number of nanoseconds since the process was started, measured with a
5103
+ * high-resolution monotonic system timer.
4750
5104
  *
4751
- * This function uses a high-resolution monotonic system timer to provide precise time measurements.
4752
- * In JavaScript, numbers are represented as double-precision floating-point values (IEEE 754),
4753
- * which can safely represent integers up to 2^53 - 1 (Number.MAX_SAFE_INTEGER).
5105
+ * JavaScript numbers are IEEE 754 doubles, which represent integers exactly only up to
5106
+ * 2^53 - 1 (`Number.MAX_SAFE_INTEGER`). After about 14.8 weeks of uptime the nanosecond
5107
+ * count exceeds that, so the returned value keeps counting but loses precision.
4754
5108
  *
4755
- * Due to this limitation, while the internal counter may continue beyond this point,
4756
- * the precision of the returned value will degrade after 14.8 weeks of uptime (when the nanosecond
4757
- * count exceeds Number.MAX_SAFE_INTEGER). Beyond this point, the function will continue to count but
4758
- * with reduced precision, which might affect time calculations and comparisons in long-running applications.
4759
- *
4760
- * @returns {number} The number of nanoseconds since the process was started, with precise values up to
4761
- * Number.MAX_SAFE_INTEGER.
5109
+ * @returns Nanoseconds since the process started
4762
5110
  */
4763
5111
  function nanoseconds(): number;
4764
5112
 
4765
5113
  /**
4766
- * Show precise statistics about memory usage of your application
4767
- *
4768
- * Generate a heap snapshot in JavaScriptCore's format that can be viewed with `bun --inspect` or Safari's Web Inspector
5114
+ * Generates a heap snapshot in JavaScriptCore's format. View it with `bun --inspect` or
5115
+ * Safari's Web Inspector
4769
5116
  */
4770
5117
  function generateHeapSnapshot(format?: "jsc"): HeapSnapshot;
4771
5118
 
4772
5119
  /**
4773
- * Show precise statistics about memory usage of your application
5120
+ * Generates a V8 heap snapshot for use with Chrome DevTools or Visual Studio Code
4774
5121
  *
4775
- * Generate a V8 Heap Snapshot that can be used with Chrome DevTools & Visual Studio Code
5122
+ * Returns a JSON string you can save to a file.
4776
5123
  *
4777
- * This is a JSON string that can be saved to a file.
5124
+ * @example
4778
5125
  * ```ts
4779
5126
  * const snapshot = Bun.generateHeapSnapshot("v8");
4780
5127
  * await Bun.write("heap.heapsnapshot", snapshot);
@@ -4783,12 +5130,11 @@ declare module "bun" {
4783
5130
  function generateHeapSnapshot(format: "v8"): string;
4784
5131
 
4785
5132
  /**
4786
- * Show precise statistics about memory usage of your application
4787
- *
4788
- * Generate a V8 Heap Snapshot as an ArrayBuffer.
5133
+ * Generates a V8 heap snapshot as an `ArrayBuffer` containing the UTF-8 encoded JSON.
4789
5134
  *
4790
5135
  * This avoids the overhead of creating a JavaScript string for large heap snapshots.
4791
- * The ArrayBuffer contains the UTF-8 encoded JSON.
5136
+ *
5137
+ * @example
4792
5138
  * ```ts
4793
5139
  * const snapshot = Bun.generateHeapSnapshot("v8", "arraybuffer");
4794
5140
  * await Bun.write("heap.heapsnapshot", snapshot);
@@ -4804,9 +5150,10 @@ declare module "bun" {
4804
5150
  function shrink(): void;
4805
5151
 
4806
5152
  /**
4807
- * Open a file in your local editor. Auto-detects via `$VISUAL` || `$EDITOR`
5153
+ * Open a file in your local editor. The editor is detected from `$VISUAL` or `$EDITOR`
4808
5154
  *
4809
- * @param path path to open
5155
+ * @param path Path of the file to open
5156
+ * @param options Editor, line, and column overrides
4810
5157
  */
4811
5158
  function openInEditor(path: string, options?: EditorOptions): void;
4812
5159
 
@@ -4825,14 +5172,14 @@ declare module "bun" {
4825
5172
  /**
4826
5173
  * Update the hash with data
4827
5174
  *
4828
- * @param data
5175
+ * @param data Data to add to the hash
4829
5176
  */
4830
5177
  update(data: Bun.BlobOrStringOrBuffer): T;
4831
5178
 
4832
5179
  /**
4833
5180
  * Finalize the hash
4834
5181
  *
4835
- * @param encoding `DigestEncoding` to return the hash in. If none is provided, it will return a `Uint8Array`.
5182
+ * @param encoding `DigestEncoding` to return the hash in. If none is provided, the hash is returned as a `Uint8Array`
4836
5183
  */
4837
5184
  digest(encoding: DigestEncoding): string;
4838
5185
 
@@ -4903,14 +5250,14 @@ declare module "bun" {
4903
5250
  * Create a new hasher
4904
5251
  *
4905
5252
  * @param algorithm The algorithm to use. See {@link algorithms} for a list of supported algorithms
4906
- * @param hmacKey Optional key for HMAC. Must be a string or `TypedArray`. If not provided, the hasher will be a non-HMAC hasher.
5253
+ * @param hmacKey Optional key for HMAC. If not provided, the hasher is a regular (non-HMAC) hasher.
4907
5254
  */
4908
5255
  constructor(algorithm: SupportedCryptoAlgorithms, hmacKey?: string | NodeJS.TypedArray);
4909
5256
 
4910
5257
  /**
4911
5258
  * Update the hash with data
4912
5259
  *
4913
- * @param input
5260
+ * @param input Data to add to the hash. `Uint8Array` or `ArrayBuffer` is faster than a string
4914
5261
  */
4915
5262
  update(input: Bun.BlobOrStringOrBuffer, inputEncoding?: import("crypto").Encoding): CryptoHasher;
4916
5263
 
@@ -4922,7 +5269,7 @@ declare module "bun" {
4922
5269
  /**
4923
5270
  * Finalize the hash. Resets the CryptoHasher so it can be reused.
4924
5271
  *
4925
- * @param encoding `DigestEncoding` to return the hash in. If none is provided, it will return a `Uint8Array`.
5272
+ * @param encoding `DigestEncoding` to return the hash in
4926
5273
  */
4927
5274
  digest(encoding: DigestEncoding): string;
4928
5275
 
@@ -4980,14 +5327,15 @@ declare module "bun" {
4980
5327
  }
4981
5328
 
4982
5329
  /**
4983
- * Resolve a `Promise` after milliseconds. This is like
4984
- * {@link setTimeout} except it returns a `Promise`.
5330
+ * Returns a `Promise` that resolves after the given number of milliseconds,
5331
+ * or at the given {@link Date}. Like {@link setTimeout}, except it returns a
5332
+ * `Promise`.
4985
5333
  *
4986
5334
  * @category Utilities
4987
5335
  *
4988
- * @param ms milliseconds to delay resolving the promise. This is a minimum
4989
- * number. It may take longer. If a {@link Date} is passed, it will sleep until the
4990
- * {@link Date} is reached.
5336
+ * @param ms milliseconds to wait before resolving the promise. This is a
5337
+ * minimum; it may take longer. Pass a {@link Date} to sleep until that time
5338
+ * is reached.
4991
5339
  *
4992
5340
  * @example
4993
5341
  * ## Sleep for 1 second
@@ -5011,14 +5359,12 @@ declare module "bun" {
5011
5359
  * ```ts
5012
5360
  * await new Promise((resolve) => setTimeout(resolve, ms));
5013
5361
  * ```
5014
- * As always, you can use `Bun.sleep` or the imported `sleep` function interchangeably.
5362
+ * `Bun.sleep` and the imported `sleep` function are interchangeable.
5015
5363
  */
5016
5364
  function sleep(ms: number | Date): Promise<void>;
5017
5365
 
5018
5366
  /**
5019
- * Sleep the thread for a given number of milliseconds
5020
- *
5021
- * This is a blocking function.
5367
+ * Block the thread for a given number of milliseconds.
5022
5368
  *
5023
5369
  * Internally, it calls [nanosleep(2)](https://man7.org/linux/man-pages/man2/nanosleep.2.html)
5024
5370
  */
@@ -5027,12 +5373,7 @@ declare module "bun" {
5027
5373
  /**
5028
5374
  * Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
5029
5375
  *
5030
- * @category Utilities
5031
- *
5032
- * @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
5033
- * @param hashInto optional `Uint8Array` to write the hash to. 32 bytes minimum.
5034
- *
5035
- * This hashing function balances speed with cryptographic strength. This does not encrypt or decrypt data.
5376
+ * This hashing function balances speed with cryptographic strength. It does not encrypt or decrypt data.
5036
5377
  *
5037
5378
  * The implementation uses [BoringSSL](https://boringssl.googlesource.com/boringssl) (used in Chromium & Go)
5038
5379
  *
@@ -5042,18 +5383,18 @@ declare module "bun" {
5042
5383
  * # You will need OpenSSL 3 or later
5043
5384
  * openssl sha512-256 /path/to/file
5044
5385
  * ```
5386
+ *
5387
+ * @category Utilities
5388
+ *
5389
+ * @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` is faster
5390
+ * @param hashInto optional `Uint8Array` to write the hash to. 32 bytes minimum.
5045
5391
  */
5046
5392
  function sha(input: Bun.StringOrBuffer, hashInto?: NodeJS.TypedArray): NodeJS.TypedArray;
5047
5393
 
5048
5394
  /**
5049
5395
  * Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
5050
5396
  *
5051
- * @category Utilities
5052
- *
5053
- * @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
5054
- * @param encoding `DigestEncoding` to return the hash in
5055
- *
5056
- * This hashing function balances speed with cryptographic strength. This does not encrypt or decrypt data.
5397
+ * This hashing function balances speed with cryptographic strength. It does not encrypt or decrypt data.
5057
5398
  *
5058
5399
  * The implementation uses [BoringSSL](https://boringssl.googlesource.com/boringssl) (used in Chromium & Go)
5059
5400
  *
@@ -5063,19 +5404,24 @@ declare module "bun" {
5063
5404
  * # You will need OpenSSL 3 or later
5064
5405
  * openssl sha512-256 /path/to/file
5065
5406
  * ```
5407
+ *
5408
+ * @category Utilities
5409
+ *
5410
+ * @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` is faster
5411
+ * @param encoding `DigestEncoding` to return the hash in
5066
5412
  */
5067
5413
  function sha(input: Bun.StringOrBuffer, encoding: DigestEncoding): string;
5068
5414
 
5069
5415
  /**
5070
5416
  * This is not the default because it's not cryptographically secure and it's slower than {@link SHA512}
5071
5417
  *
5072
- * Consider using the ugly-named {@link SHA512_256} instead
5418
+ * Consider {@link SHA512_256} instead
5073
5419
  */
5074
5420
  class SHA1 extends CryptoHashInterface<SHA1> {
5075
5421
  constructor();
5076
5422
 
5077
5423
  /**
5078
- * The number of bytes the hash will produce
5424
+ * The number of bytes the hash produces
5079
5425
  */
5080
5426
  static readonly byteLength: 20;
5081
5427
  }
@@ -5083,7 +5429,7 @@ declare module "bun" {
5083
5429
  constructor();
5084
5430
 
5085
5431
  /**
5086
- * The number of bytes the hash will produce
5432
+ * The number of bytes the hash produces
5087
5433
  */
5088
5434
  static readonly byteLength: 16;
5089
5435
  }
@@ -5091,7 +5437,7 @@ declare module "bun" {
5091
5437
  constructor();
5092
5438
 
5093
5439
  /**
5094
- * The number of bytes the hash will produce
5440
+ * The number of bytes the hash produces
5095
5441
  */
5096
5442
  static readonly byteLength: 16;
5097
5443
  }
@@ -5099,7 +5445,7 @@ declare module "bun" {
5099
5445
  constructor();
5100
5446
 
5101
5447
  /**
5102
- * The number of bytes the hash will produce
5448
+ * The number of bytes the hash produces
5103
5449
  */
5104
5450
  static readonly byteLength: 28;
5105
5451
  }
@@ -5107,7 +5453,7 @@ declare module "bun" {
5107
5453
  constructor();
5108
5454
 
5109
5455
  /**
5110
- * The number of bytes the hash will produce
5456
+ * The number of bytes the hash produces
5111
5457
  */
5112
5458
  static readonly byteLength: 64;
5113
5459
  }
@@ -5115,7 +5461,7 @@ declare module "bun" {
5115
5461
  constructor();
5116
5462
 
5117
5463
  /**
5118
- * The number of bytes the hash will produce
5464
+ * The number of bytes the hash produces
5119
5465
  */
5120
5466
  static readonly byteLength: 48;
5121
5467
  }
@@ -5123,7 +5469,7 @@ declare module "bun" {
5123
5469
  constructor();
5124
5470
 
5125
5471
  /**
5126
- * The number of bytes the hash will produce
5472
+ * The number of bytes the hash produces
5127
5473
  */
5128
5474
  static readonly byteLength: 32;
5129
5475
  }
@@ -5134,7 +5480,7 @@ declare module "bun" {
5134
5480
  constructor();
5135
5481
 
5136
5482
  /**
5137
- * The number of bytes the hash will produce
5483
+ * The number of bytes the hash produces
5138
5484
  */
5139
5485
  static readonly byteLength: 32;
5140
5486
  }
@@ -5146,14 +5492,14 @@ declare module "bun" {
5146
5492
  interface ZlibCompressionOptions {
5147
5493
  /**
5148
5494
  * The compression level to use. Must be between `-1` and `9`.
5149
- * - A value of `-1` uses the default compression level (Currently `6`)
5150
- * - A value of `0` gives no compression
5151
- * - A value of `1` gives least compression, fastest speed
5152
- * - A value of `9` gives best compression, slowest speed
5495
+ * - `-1` uses the default compression level (`6`)
5496
+ * - `0` gives no compression
5497
+ * - `1` gives least compression, fastest speed
5498
+ * - `9` gives best compression, slowest speed
5153
5499
  */
5154
5500
  level?: -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
5155
5501
  /**
5156
- * How much memory should be allocated for the internal compression state.
5502
+ * How much memory to allocate for the internal compression state.
5157
5503
  *
5158
5504
  * A value of `1` uses minimum memory but is slow and reduces compression ratio.
5159
5505
  *
@@ -5166,11 +5512,11 @@ declare module "bun" {
5166
5512
  * Larger values of this parameter result in better compression at the expense of memory usage.
5167
5513
  *
5168
5514
  * The following value ranges are supported:
5169
- * - `9..15`: The output will have a zlib header and footer (Deflate)
5170
- * - `-9..-15`: The output will **not** have a zlib header or footer (Raw Deflate)
5171
- * - `25..31` (16+`9..15`): The output will have a gzip header and footer (gzip)
5515
+ * - `9..15`: The output has a zlib header and footer (Deflate)
5516
+ * - `-9..-15`: The output does **not** have a zlib header or footer (Raw Deflate)
5517
+ * - `25..31` (16+`9..15`): The output has a gzip header and footer (gzip)
5172
5518
  *
5173
- * The gzip header will have no file name, no extra data, no comment, no modification time (set to zero) and no header CRC.
5519
+ * The gzip header has no file name, no extra data, no comment, no modification time (set to zero) and no header CRC.
5174
5520
  */
5175
5521
  windowBits?:
5176
5522
  | -9
@@ -5205,7 +5551,7 @@ declare module "bun" {
5205
5551
  *
5206
5552
  * `Z_RLE` is designed to be almost as fast as `Z_HUFFMAN_ONLY`, but give better compression for PNG image data.
5207
5553
  *
5208
- * `Z_FILTERED` forces more Huffman coding and less string matching, it is
5554
+ * `Z_FILTERED` forces more Huffman coding and less string matching; it is
5209
5555
  * somewhat intermediate between `Z_DEFAULT_STRATEGY` and `Z_HUFFMAN_ONLY`.
5210
5556
  * Filtered data consists mostly of small values with a somewhat random distribution.
5211
5557
  */
@@ -5220,7 +5566,7 @@ declare module "bun" {
5220
5566
  }
5221
5567
 
5222
5568
  /**
5223
- * Compresses a chunk of data with `zlib` DEFLATE algorithm.
5569
+ * Compresses a chunk of data with the `zlib` DEFLATE algorithm.
5224
5570
  * @param data The buffer of data to compress
5225
5571
  * @param options Compression options to use
5226
5572
  * @returns The output buffer with the compressed data
@@ -5230,7 +5576,7 @@ declare module "bun" {
5230
5576
  options?: ZlibCompressionOptions | LibdeflateCompressionOptions,
5231
5577
  ): Uint8Array<ArrayBuffer>;
5232
5578
  /**
5233
- * Compresses a chunk of data with `zlib` GZIP algorithm.
5579
+ * Compresses a chunk of data with the `zlib` GZIP algorithm.
5234
5580
  * @param data The buffer of data to compress
5235
5581
  * @param options Compression options to use
5236
5582
  * @returns The output buffer with the compressed data
@@ -5240,7 +5586,7 @@ declare module "bun" {
5240
5586
  options?: ZlibCompressionOptions | LibdeflateCompressionOptions,
5241
5587
  ): Uint8Array<ArrayBuffer>;
5242
5588
  /**
5243
- * Decompresses a chunk of data with `zlib` INFLATE algorithm.
5589
+ * Decompresses a chunk of data with the `zlib` INFLATE algorithm.
5244
5590
  * @param data The buffer of data to decompress
5245
5591
  * @returns The output buffer with the decompressed data
5246
5592
  */
@@ -5249,7 +5595,7 @@ declare module "bun" {
5249
5595
  options?: ZlibCompressionOptions | LibdeflateCompressionOptions,
5250
5596
  ): Uint8Array<ArrayBuffer>;
5251
5597
  /**
5252
- * Decompresses a chunk of data with `zlib` GUNZIP algorithm.
5598
+ * Decompresses a chunk of data with the `zlib` GUNZIP algorithm.
5253
5599
  * @param data The buffer of data to decompress
5254
5600
  * @returns The output buffer with the decompressed data
5255
5601
  */
@@ -5296,21 +5642,20 @@ declare module "bun" {
5296
5642
 
5297
5643
  type Target =
5298
5644
  /**
5299
- * For generating bundles that are intended to be run by the Bun runtime. In many cases,
5300
- * it isn't necessary to bundle server-side code; you can directly execute the source code
5301
- * without modification. However, bundling your server code can reduce startup times and
5302
- * improve running performance.
5645
+ * For bundles that run in the Bun runtime. Bundling server-side code is
5646
+ * often unnecessary, since Bun can run the source directly, but it can
5647
+ * reduce startup time and improve performance.
5303
5648
  *
5304
5649
  * All bundles generated with `target: "bun"` are marked with a special `// @bun` pragma, which
5305
- * indicates to the Bun runtime that there's no need to re-transpile the file before execution.
5650
+ * tells the Bun runtime that there's no need to re-transpile the file before execution.
5306
5651
  */
5307
5652
  | "bun"
5308
5653
  /**
5309
- * The plugin will be applied to Node.js builds
5654
+ * The plugin is applied to Node.js builds
5310
5655
  */
5311
5656
  | "node"
5312
5657
  /**
5313
- * The plugin will be applied to browser builds
5658
+ * The plugin is applied to browser builds
5314
5659
  */
5315
5660
  | "browser";
5316
5661
 
@@ -5324,6 +5669,7 @@ declare module "bun" {
5324
5669
  | "jsonc"
5325
5670
  | "toml"
5326
5671
  | "yaml"
5672
+ | "xml"
5327
5673
  | "file"
5328
5674
  | "napi"
5329
5675
  | "wasm"
@@ -5369,8 +5715,6 @@ declare module "bun" {
5369
5715
  contents: string | ArrayBufferView | ArrayBuffer | SharedArrayBuffer;
5370
5716
  /**
5371
5717
  * The loader to use for this file
5372
- *
5373
- * "css" will be added in a future version of Bun.
5374
5718
  */
5375
5719
  loader?: Loader;
5376
5720
  }
@@ -5420,7 +5764,7 @@ declare module "bun" {
5420
5764
  /**
5421
5765
  * Defer the execution of this callback until all other modules have been parsed.
5422
5766
  *
5423
- * @returns Promise which will be resolved when all modules have been parsed
5767
+ * @returns Promise that resolves when all modules have been parsed
5424
5768
  */
5425
5769
  defer: () => Promise<void>;
5426
5770
  }
@@ -5467,7 +5811,7 @@ declare module "bun" {
5467
5811
  path: string;
5468
5812
  /**
5469
5813
  * The namespace of the destination
5470
- * It will be concatenated with `path` to form the final import specifier
5814
+ * It is concatenated with `path` to form the final import specifier
5471
5815
  * @example
5472
5816
  * ```ts
5473
5817
  * "foo" // "foo:bar"
@@ -5493,9 +5837,8 @@ declare module "bun" {
5493
5837
  */
5494
5838
  interface PluginBuilder {
5495
5839
  /**
5496
- * Register a callback which will be invoked when bundling starts. When
5497
- * using hot module reloading, this is called at the start of each
5498
- * incremental rebuild.
5840
+ * Register a callback that runs when bundling starts. With hot module
5841
+ * reloading, it runs at the start of each incremental rebuild.
5499
5842
  *
5500
5843
  * @example
5501
5844
  * ```ts
@@ -5512,8 +5855,8 @@ declare module "bun" {
5512
5855
  */
5513
5856
  onStart(callback: OnStartCallback): this;
5514
5857
  /**
5515
- * Register a callback which will be invoked when bundling ends. This is
5516
- * called after all modules have been bundled and the build is complete.
5858
+ * Register a callback that runs when bundling ends, after all modules
5859
+ * have been bundled and the build is complete.
5517
5860
  *
5518
5861
  * @example
5519
5862
  * ```ts
@@ -5618,25 +5961,25 @@ declare module "bun" {
5618
5961
  /**
5619
5962
  * The target JavaScript environment the plugin should be applied to.
5620
5963
  * - `bun`: The default environment when using `bun run` or `bun` to load a script
5621
- * - `browser`: The plugin will be applied to browser builds
5622
- * - `node`: The plugin will be applied to Node.js builds
5964
+ * - `browser`: The plugin is applied to browser builds
5965
+ * - `node`: The plugin is applied to Node.js builds
5623
5966
  *
5624
- * If unspecified, it is assumed that the plugin is compatible with all targets.
5967
+ * If unspecified, the plugin is assumed to be compatible with all targets.
5625
5968
  *
5626
5969
  * This field is not read by {@link Bun.plugin}, only {@link Bun.build} and `bun build`
5627
5970
  */
5628
5971
  target?: Target;
5629
5972
 
5630
5973
  /**
5631
- * A function that will be called when the plugin is loaded.
5974
+ * Called when the plugin is loaded.
5632
5975
  *
5633
5976
  * This function may be called in the same tick that it is registered, or it
5634
- * may be called later. It could potentially be called multiple times for
5635
- * different targets.
5977
+ * may be called later. It may be called multiple times for different
5978
+ * targets.
5636
5979
  */
5637
5980
  setup(
5638
5981
  /**
5639
- * A builder object that can be used to register plugin hooks
5982
+ * The builder object for registering plugin hooks
5640
5983
  * @example
5641
5984
  * ```ts
5642
5985
  * builder.onLoad({ filter: /\.yaml$/ }, ({ path }) => ({
@@ -5654,18 +5997,18 @@ declare module "bun" {
5654
5997
  *
5655
5998
  * Plugins are applied in the order they are defined.
5656
5999
  *
5657
- * Today, there are two kinds of hooks:
5658
- * - `onLoad` lets you return source code or an object that will become the module's exports
5659
- * - `onResolve` lets you redirect a module specifier to another module specifier. It does not chain.
6000
+ * There are two kinds of hooks:
6001
+ * - `onLoad` returns source code or an object that becomes the module's exports
6002
+ * - `onResolve` redirects a module specifier to another module specifier. It does not chain.
5660
6003
  *
5661
- * Plugin hooks must define a `filter` RegExp and will only be matched if the
6004
+ * Plugin hooks must define a `filter` RegExp and only match when the
5662
6005
  * import specifier contains a "." or a ":".
5663
6006
  *
5664
6007
  * ES Module resolution semantics mean that plugins may be initialized _after_
5665
6008
  * a module is resolved. You might need to load plugins at the very beginning
5666
6009
  * of the application and then use a dynamic import to load the rest of the
5667
6010
  * application. A future version of Bun may also support specifying plugins
5668
- * via `bunfig.toml`.
6011
+ * in `bunfig.toml`.
5669
6012
  *
5670
6013
  * @example
5671
6014
  * A YAML loader plugin
@@ -5677,6 +6020,7 @@ declare module "bun" {
5677
6020
  * loader: "object",
5678
6021
  * exports: require("js-yaml").load(fs.readFileSync(path, "utf8"))
5679
6022
  * }));
6023
+ * }
5680
6024
  * });
5681
6025
  *
5682
6026
  * // You can use require()
@@ -5701,12 +6045,12 @@ declare module "bun" {
5701
6045
  const plugin: BunRegisterPlugin;
5702
6046
 
5703
6047
  /**
5704
- * Is the current global scope the main thread?
6048
+ * Whether the current global scope is the main thread
5705
6049
  */
5706
6050
  const isMainThread: boolean;
5707
6051
 
5708
6052
  /**
5709
- * Used when importing an HTML file at runtime or at build time.
6053
+ * The result of importing an HTML file, at runtime or at build time.
5710
6054
  *
5711
6055
  * @example
5712
6056
  *
@@ -5725,7 +6069,7 @@ declare module "bun" {
5725
6069
  input?: string;
5726
6070
  /** Generated output file path (with content hash, if included in naming) */
5727
6071
  path: string;
5728
- /** File type/loader used (js, css, html, file, etc.) */
6072
+ /** The loader used for this file, such as `js`, `css`, or `html` */
5729
6073
  loader: Loader;
5730
6074
  /** Whether this file is an entry point */
5731
6075
  isEntry: boolean;
@@ -5745,20 +6089,18 @@ declare module "bun" {
5745
6089
  }
5746
6090
 
5747
6091
  /**
5748
- * Represents a TCP or TLS socket connection used for network communication.
5749
- * This interface provides methods for reading, writing, managing the connection state,
5750
- * and handling TLS-specific features if applicable.
6092
+ * A TCP or TLS socket connection.
5751
6093
  *
5752
- * Sockets are created using `Bun.connect()` or accepted by a `Bun.listen()` server.
6094
+ * Sockets are created with `Bun.connect()` or accepted by a `Bun.listen()` server.
5753
6095
  *
5754
6096
  * @category HTTP & Networking
5755
6097
  */
5756
6098
  interface Socket<Data = undefined> extends Disposable {
5757
6099
  /**
5758
- * Writes `data` to the socket. This method is unbuffered and non-blocking. This uses the `sendto(2)` syscall internally.
6100
+ * Writes `data` to the socket. This method is unbuffered and non-blocking. It uses the `sendto(2)` syscall internally.
5759
6101
  *
5760
- * For optimal performance with multiple small writes, consider batching multiple
5761
- * writes together into a single `socket.write()` call.
6102
+ * For best performance with many small writes, batch them into a single
6103
+ * `socket.write()` call.
5762
6104
  *
5763
6105
  * @param data The data to write. Can be a string (encoded as UTF-8), `ArrayBuffer`, `TypedArray`, or `DataView`.
5764
6106
  * @param byteOffset The offset in bytes within the buffer to start writing from. Defaults to 0. Ignored for strings.
@@ -5783,7 +6125,7 @@ declare module "bun" {
5783
6125
 
5784
6126
  /**
5785
6127
  * The user-defined data associated with this socket instance.
5786
- * This can be set when the socket is created via `Bun.connect({ data: ... })`.
6128
+ * Set it when the socket is created with `Bun.connect({ data: ... })`.
5787
6129
  * It can be read or updated at any time.
5788
6130
  *
5789
6131
  * @example
@@ -5856,7 +6198,7 @@ declare module "bun" {
5856
6198
  * This allows the socket to enter a half-closed state where it can still receive data
5857
6199
  * but can no longer send data (`halfClose = true`), or close both read and write
5858
6200
  * (`halfClose = false`, similar to `end()` but potentially more immediate depending on OS).
5859
- * Calls `shutdown(2)` syscall internally.
6201
+ * Calls the `shutdown(2)` syscall internally.
5860
6202
  *
5861
6203
  * @param halfClose If `true`, only shuts down the write side (allows receiving). If `false` or omitted, shuts down both read and write. Defaults to `false`.
5862
6204
  * @example
@@ -5873,7 +6215,7 @@ declare module "bun" {
5873
6215
  /**
5874
6216
  * The ready state of the socket.
5875
6217
  *
5876
- * You can assume that a positive value means the socket is open and usable
6218
+ * A positive value means the socket is open and usable
5877
6219
  *
5878
6220
  * - `-2` = Shutdown
5879
6221
  * - `-1` = Detached
@@ -5892,28 +6234,33 @@ declare module "bun" {
5892
6234
 
5893
6235
  /**
5894
6236
  * Flush any buffered data to the socket
6237
+ *
5895
6238
  * This attempts to send the data immediately, but success depends on the network conditions
5896
6239
  * and the receiving end.
5897
6240
  * It might be necessary after several `write` calls if immediate sending is critical,
5898
- * though often the OS handles flushing efficiently. Note that `write` calls outside
6241
+ * though the OS often handles flushing efficiently. `write` calls outside
5899
6242
  * `open`/`data`/`drain` might benefit from manual `cork`/`flush`.
5900
6243
  */
5901
6244
  flush(): void;
5902
6245
 
5903
6246
  /**
5904
- * Reset the socket's callbacks. This is useful with `bun --hot` to facilitate hot reloading.
6247
+ * Reset the socket's callbacks. This is useful with `bun --hot` for hot reloading.
5905
6248
  *
5906
- * This will apply to all sockets from the same {@link Listener}. it is per socket only for {@link Bun.connect}.
6249
+ * This applies to all sockets from the same {@link Listener}. It is per socket only for {@link Bun.connect}.
5907
6250
  */
5908
6251
  reload(options: Pick<SocketOptions<Data>, "socket">): void;
5909
6252
 
5910
6253
  /**
5911
- * Get the server that created this socket
6254
+ * The server that created this socket
5912
6255
  *
5913
- * This will return undefined if the socket was created by {@link Bun.connect} or if the listener has already closed.
6256
+ * This is `undefined` if the socket was created by {@link Bun.connect} or if the listener has already closed.
5914
6257
  */
5915
6258
  readonly listener?: SocketListener;
5916
6259
 
6260
+ /**
6261
+ * IP protocol family used for the remote endpoint of the socket
6262
+ * @example "IPv4" | "IPv6"
6263
+ */
5917
6264
  readonly remoteFamily: "IPv4" | "IPv6";
5918
6265
 
5919
6266
  /**
@@ -5941,21 +6288,22 @@ declare module "bun" {
5941
6288
  readonly localAddress: string;
5942
6289
 
5943
6290
  /**
5944
- * local port connected to the socket
6291
+ * Local port connected to the socket
5945
6292
  * @example 8080
5946
6293
  */
5947
6294
  readonly localPort: number;
5948
6295
 
5949
6296
  /**
5950
- * This property is `true` if the peer certificate was signed by one of the CAs
5951
- * specified when creating the `Socket` instance, otherwise `false`.
6297
+ * `true` if the peer certificate was signed by one of the CAs
6298
+ * specified when creating the `Socket` instance, otherwise `false`
5952
6299
  */
5953
6300
  readonly authorized: boolean;
5954
6301
 
5955
6302
  /**
5956
- * String containing the selected ALPN protocol.
5957
- * Before a handshake has completed, this value is always null.
5958
- * When a handshake is completed but not ALPN protocol was selected, socket.alpnProtocol equals false.
6303
+ * The selected ALPN protocol.
6304
+ *
6305
+ * Before a handshake has completed, this value is always `null`.
6306
+ * When a handshake has completed but no ALPN protocol was selected, this is `false`.
5959
6307
  */
5960
6308
  readonly alpnProtocol: string | false | null;
5961
6309
 
@@ -5963,27 +6311,24 @@ declare module "bun" {
5963
6311
  * Disables TLS renegotiation for this `Socket` instance. Once called, attempts
5964
6312
  * to renegotiate will trigger an `error` handler on the `Socket`.
5965
6313
  *
5966
- * There is no support for renegotiation as a server. (Attempts by clients will result in a fatal alert so that ClientHello messages cannot be used to flood a server and escape higher-level limits.)
6314
+ * Bun does not support renegotiation as a server. (Attempts by clients result in a fatal alert so that ClientHello messages cannot be used to flood a server and escape higher-level limits.)
5967
6315
  */
5968
6316
  disableRenegotiation(): void;
5969
6317
 
5970
6318
  /**
5971
- * Keying material is used for validations to prevent different kind of attacks in
6319
+ * Keying material is used for validations to prevent different kinds of attacks in
5972
6320
  * network protocols, for example in the specifications of IEEE 802.1X.
5973
6321
  *
5974
- * Example
5975
- *
6322
+ * @example
5976
6323
  * ```js
5977
6324
  * const keyingMaterial = socket.exportKeyingMaterial(
5978
6325
  * 128,
5979
6326
  * 'client finished');
5980
6327
  *
5981
- * /*
5982
- * Example return value of keyingMaterial:
5983
- * <Buffer 76 26 af 99 c5 56 8e 42 09 91 ef 9f 93 cb ad 6c 7b 65 f8 53 f1 d8 d9
5984
- * 12 5a 33 b8 b5 25 df 7b 37 9f e0 e2 4f b8 67 83 a3 2f cd 5d 41 42 4c 91
5985
- * 74 ef 2c ... 78 more bytes>
5986
- *
6328
+ * // Example return value of keyingMaterial:
6329
+ * // <Buffer 76 26 af 99 c5 56 8e 42 09 91 ef 9f 93 cb ad 6c 7b 65 f8 53 f1 d8 d9
6330
+ * // 12 5a 33 b8 b5 25 df 7b 37 9f e0 e2 4f b8 67 83 a3 2f cd 5d 41 42 4c 91
6331
+ * // 74 ef 2c ... 78 more bytes>
5987
6332
  * ```
5988
6333
  *
5989
6334
  * @param length number of bytes to retrieve from keying material
@@ -5995,8 +6340,8 @@ declare module "bun" {
5995
6340
  exportKeyingMaterial(length: number, label: string, context: Buffer): Buffer;
5996
6341
 
5997
6342
  /**
5998
- * Returns the reason why the peer's certificate was not been verified. This
5999
- * property is set only when `socket.authorized === false`.
6343
+ * Returns the reason why the peer's certificate was not verified. This is
6344
+ * only set when `socket.authorized === false`.
6000
6345
  */
6001
6346
  getAuthorizationError(): Error | null;
6002
6347
 
@@ -6004,8 +6349,8 @@ declare module "bun" {
6004
6349
  * Returns an object representing the local certificate. The returned object has
6005
6350
  * some properties corresponding to the fields of the certificate.
6006
6351
  *
6007
- * If there is no local certificate, an empty object will be returned. If the
6008
- * socket has been destroyed, `null` will be returned.
6352
+ * If there is no local certificate, an empty object is returned. If the
6353
+ * socket has been destroyed, `null` is returned.
6009
6354
  */
6010
6355
  getCertificate(): import("tls").PeerCertificate | object | null;
6011
6356
  getX509Certificate(): import("node:crypto").X509Certificate | undefined;
@@ -6030,8 +6375,8 @@ declare module "bun" {
6030
6375
  * Returns an object representing the type, name, and size of parameter of
6031
6376
  * an ephemeral key exchange in `perfect forward secrecy` on a client
6032
6377
  * connection. It returns an empty object when the key exchange is not
6033
- * ephemeral. As this is only supported on a client socket; `null` is returned
6034
- * if called on a server socket. The supported types are `'DH'` and `'ECDH'`. The`name` property is available only when type is `'ECDH'`.
6378
+ * ephemeral. This is only supported on a client socket; `null` is returned
6379
+ * if called on a server socket. The supported types are `'DH'` and `'ECDH'`. The `name` property is available only when type is `'ECDH'`.
6035
6380
  *
6036
6381
  * For example: `{ type: 'ECDH', name: 'prime256v1', size: 256 }`.
6037
6382
  */
@@ -6039,10 +6384,10 @@ declare module "bun" {
6039
6384
 
6040
6385
  /**
6041
6386
  * Returns an object representing the peer's certificate. If the peer does not
6042
- * provide a certificate, an empty object will be returned. If the socket has been
6043
- * destroyed, `null` will be returned.
6387
+ * provide a certificate, an empty object is returned. If the socket has been
6388
+ * destroyed, `null` is returned.
6044
6389
  *
6045
- * If the full certificate chain was requested, each certificate will include an`issuerCertificate` property containing an object representing its issuer's
6390
+ * If the full certificate chain was requested, each certificate includes an `issuerCertificate` property containing an object representing its issuer's
6046
6391
  * certificate.
6047
6392
  * @return A certificate object.
6048
6393
  */
@@ -6051,7 +6396,6 @@ declare module "bun" {
6051
6396
 
6052
6397
  /**
6053
6398
  * See [SSL\_get\_shared\_sigalgs](https://www.openssl.org/docs/man1.1.1/man3/SSL_get_shared_sigalgs.html) for more information.
6054
- * @since v12.11.0
6055
6399
  * @return List of signature algorithms shared between the server and the client in the order of decreasing preference.
6056
6400
  */
6057
6401
  getSharedSigalgs(): string[];
@@ -6078,7 +6422,7 @@ declare module "bun" {
6078
6422
  getTLSPeerFinishedMessage(): Buffer | undefined;
6079
6423
 
6080
6424
  /**
6081
- * For a client, returns the TLS session ticket if one is available, or`undefined`. For a server, always returns `undefined`.
6425
+ * For a client, returns the TLS session ticket if one is available, or `undefined`. For a server, always returns `undefined`.
6082
6426
  *
6083
6427
  * It may be useful for debugging.
6084
6428
  *
@@ -6088,9 +6432,9 @@ declare module "bun" {
6088
6432
 
6089
6433
  /**
6090
6434
  * Returns a string containing the negotiated SSL/TLS protocol version of the
6091
- * current connection. The value `'unknown'` will be returned for connected
6092
- * sockets that have not completed the handshaking process. The value `null` will
6093
- * be returned for server sockets or disconnected client sockets.
6435
+ * current connection. The value `'unknown'` is returned for connected
6436
+ * sockets that have not completed the handshaking process. The value `null` is
6437
+ * returned for server sockets or disconnected client sockets.
6094
6438
  *
6095
6439
  * Protocol versions are:
6096
6440
  *
@@ -6104,15 +6448,15 @@ declare module "bun" {
6104
6448
  getTLSVersion(): string;
6105
6449
 
6106
6450
  /**
6451
+ * **TLS only:** Checks if the current TLS session was resumed from a previous session.
6452
+ *
6107
6453
  * See `Session Resumption` for more information.
6108
- * @return `true` if the session was reused, `false` otherwise.
6109
- * **TLS Only:** Checks if the current TLS session was resumed from a previous session.
6110
- * Returns `true` if the session was resumed, `false` otherwise.
6454
+ * @return `true` if the session was reused, `false` otherwise
6111
6455
  */
6112
6456
  isSessionReused(): boolean;
6113
6457
 
6114
6458
  /**
6115
- * The `socket.setMaxSendFragment()` method sets the maximum TLS fragment size.
6459
+ * Sets the maximum TLS fragment size.
6116
6460
  * Returns `true` if setting the limit succeeded; `false` otherwise.
6117
6461
  *
6118
6462
  * Smaller fragment sizes decrease the buffering latency on the client: larger
@@ -6127,25 +6471,26 @@ declare module "bun" {
6127
6471
 
6128
6472
  /**
6129
6473
  * Enable/disable the use of Nagle's algorithm.
6130
- * Only available for already connected sockets, will return false otherwise
6474
+ * Only available for already connected sockets; returns `false` otherwise
6131
6475
  * @param noDelay Default: `true`
6132
- * @returns true if is able to setNoDelay and false if it fails.
6476
+ * @returns `true` if it succeeds, `false` if it fails
6133
6477
  */
6134
6478
  setNoDelay(noDelay?: boolean): boolean;
6135
6479
 
6136
6480
  /**
6137
6481
  * Enable/disable keep-alive functionality, and optionally set the initial delay before the first keepalive probe is sent on an idle socket.
6138
6482
  * Set `initialDelay` (in milliseconds) to set the delay between the last data packet received and the first keepalive probe.
6139
- * Only available for already connected sockets, will return false otherwise.
6483
+ * Setting `0` for `initialDelay` (the default) will leave the value unchanged from the default (or previous) setting.
6484
+ * Only available for already connected sockets; returns `false` otherwise.
6140
6485
  *
6141
- * Enabling the keep-alive functionality will set the following socket options:
6486
+ * Enabling the keep-alive functionality sets the following socket options:
6142
6487
  * SO_KEEPALIVE=1
6143
- * TCP_KEEPIDLE=initialDelay
6488
+ * TCP_KEEPIDLE=initialDelay/1000
6144
6489
  * TCP_KEEPCNT=10
6145
6490
  * TCP_KEEPINTVL=1
6146
6491
  * @param enable Default: `false`
6147
6492
  * @param initialDelay Default: `0`
6148
- * @returns true if is able to setNoDelay and false if it fails.
6493
+ * @returns `true` if it succeeds, `false` if it fails
6149
6494
  */
6150
6495
  setKeepAlive(enable?: boolean, initialDelay?: number): boolean;
6151
6496
 
@@ -6273,9 +6618,8 @@ declare module "bun" {
6273
6618
 
6274
6619
  interface SocketHandler<Data = unknown, DataBinaryType extends BinaryType = "buffer"> {
6275
6620
  /**
6276
- * Is called when the socket connects, or in case of TLS if no handshake is provided
6277
- * this will be called only after handshake
6278
- * @param socket
6621
+ * Called when the socket connects. For TLS sockets with no `handshake`
6622
+ * handler, this is called only after the handshake completes.
6279
6623
  */
6280
6624
  open?(socket: Socket<Data>): void | Promise<void>;
6281
6625
  close?(socket: Socket<Data>, error?: Error): void | Promise<void>;
@@ -6284,31 +6628,30 @@ declare module "bun" {
6284
6628
  drain?(socket: Socket<Data>): void | Promise<void>;
6285
6629
 
6286
6630
  /**
6287
- * When handshake is completed, this functions is called.
6288
- * @param socket
6289
- * @param success Indicates if the server authorized despite the authorizationError.
6290
- * @param authorizationError Certificate Authorization Error or null.
6631
+ * Called when the TLS handshake completes.
6632
+ * @param success Whether the server authorized the connection despite `authorizationError`
6633
+ * @param authorizationError The certificate authorization error, or `null` if there was none
6291
6634
  */
6292
6635
  handshake?(socket: Socket<Data>, success: boolean, authorizationError: Error | null): void;
6293
6636
 
6294
6637
  /**
6295
- * When the socket has been shutdown from the other end, this function is
6296
- * called. This is a TCP FIN packet.
6638
+ * Called when the other end shuts down its side of the socket by sending
6639
+ * a TCP FIN packet.
6297
6640
  */
6298
6641
  end?(socket: Socket<Data>): void | Promise<void>;
6299
6642
 
6300
6643
  /**
6301
- * When the socket fails to be created, this function is called.
6644
+ * Called when the socket fails to be created.
6302
6645
  *
6303
6646
  * The promise returned by `Bun.connect` rejects **after** this function is
6304
6647
  * called.
6305
6648
  *
6306
- * When `connectError` is specified, the rejected promise will not be
6307
- * added to the promise rejection queue (so it won't be reported as an
6308
- * unhandled promise rejection, since connectError handles it).
6649
+ * When `connectError` is specified, the rejected promise is not added to
6650
+ * the promise rejection queue (so it isn't reported as an unhandled
6651
+ * promise rejection, since `connectError` handles it).
6309
6652
  *
6310
- * When `connectError` is not specified, the rejected promise will be added
6311
- * to the promise rejection queue.
6653
+ * When `connectError` is not specified, the rejected promise is added to
6654
+ * the promise rejection queue.
6312
6655
  */
6313
6656
  connectError?(socket: Socket<Data>, error: Error): void | Promise<void>;
6314
6657
 
@@ -6317,18 +6660,13 @@ declare module "bun" {
6317
6660
  */
6318
6661
  timeout?(socket: Socket<Data>): void | Promise<void>;
6319
6662
  /**
6320
- * Choose what `ArrayBufferView` is returned in the {@link SocketHandler.data} callback.
6663
+ * Choose what `ArrayBufferView` is passed to the {@link SocketHandler.data} callback.
6321
6664
  *
6322
6665
  * @default "buffer"
6323
6666
  *
6324
6667
  * @remarks
6325
- * This lets you select the desired binary type for the `data` callback.
6326
- * It's a small performance optimization to let you avoid creating extra
6327
- * ArrayBufferView objects when possible.
6328
- *
6329
- * Bun originally defaulted to `Uint8Array` but when dealing with network
6330
- * data, it's more useful to be able to directly read from the bytes which
6331
- * `Buffer` allows.
6668
+ * A small performance optimization: picking the type you need avoids
6669
+ * creating extra `ArrayBufferView` objects when possible.
6332
6670
  */
6333
6671
  binaryType?: BinaryType;
6334
6672
  }
@@ -6382,9 +6720,6 @@ declare module "bun" {
6382
6720
  * When `false` (default), other sockets may be able to bind to the same port
6383
6721
  * depending on the operating system's socket sharing capabilities and settings.
6384
6722
  *
6385
- * Exclusive mode is useful in scenarios where you want to ensure only one
6386
- * instance of your server can bind to a specific port at a time.
6387
- *
6388
6723
  * @default false
6389
6724
  */
6390
6725
  exclusive?: boolean;
@@ -6416,7 +6751,7 @@ declare module "bun" {
6416
6751
  */
6417
6752
  port: number;
6418
6753
  /**
6419
- * TLS Configuration with which to create the socket
6754
+ * TLS configuration with which to create the socket
6420
6755
  */
6421
6756
  tls?: TLSOptions | boolean;
6422
6757
  /**
@@ -6428,9 +6763,6 @@ declare module "bun" {
6428
6763
  * When `false` (default), other sockets may be able to bind to the same port
6429
6764
  * depending on the operating system's socket sharing capabilities and settings.
6430
6765
  *
6431
- * Exclusive mode is useful in scenarios where you want to ensure only one
6432
- * instance of your server can bind to a specific port at a time.
6433
- *
6434
6766
  * @default false
6435
6767
  */
6436
6768
  exclusive?: boolean;
@@ -6445,14 +6777,14 @@ declare module "bun" {
6445
6777
  unix: string;
6446
6778
 
6447
6779
  /**
6448
- * TLS Configuration with which to create the socket
6780
+ * TLS configuration with which to create the socket
6449
6781
  */
6450
6782
  tls?: TLSOptions | boolean;
6451
6783
  }
6452
6784
 
6453
6785
  interface FdSocketOptions<Data = undefined> extends SocketOptions<Data> {
6454
6786
  /**
6455
- * TLS Configuration with which to create the socket
6787
+ * TLS configuration with which to create the socket
6456
6788
  */
6457
6789
  tls?: TLSOptions | boolean;
6458
6790
  /**
@@ -6462,13 +6794,13 @@ declare module "bun" {
6462
6794
  }
6463
6795
 
6464
6796
  /**
6465
- * Create a TCP client that connects to a server via a TCP socket
6797
+ * Create a TCP client that connects to a server
6466
6798
  *
6467
6799
  * @category HTTP & Networking
6468
6800
  */
6469
6801
  function connect<Data = undefined>(options: TCPSocketConnectOptions<Data>): Promise<Socket<Data>>;
6470
6802
  /**
6471
- * Create a TCP client that connects to a server via a unix socket
6803
+ * Create a client that connects to a server over a Unix socket
6472
6804
  *
6473
6805
  * @category HTTP & Networking
6474
6806
  */
@@ -6481,7 +6813,7 @@ declare module "bun" {
6481
6813
  */
6482
6814
  function listen<Data = undefined>(options: TCPSocketListenOptions<Data>): TCPSocketListener<Data>;
6483
6815
  /**
6484
- * Create a TCP server that listens on a unix socket
6816
+ * Create a server that listens on a Unix socket
6485
6817
  *
6486
6818
  * @category HTTP & Networking
6487
6819
  */
@@ -6503,6 +6835,12 @@ declare module "bun" {
6503
6835
  * callback contains only the portion that fit in the buffer.
6504
6836
  */
6505
6837
  truncated: boolean;
6838
+ /**
6839
+ * `true` if the datagram's source address was IPv6, `false` for IPv4.
6840
+ * Reflects the packet's own `sockaddr` — a socket adopting an existing
6841
+ * fd may receive packets of the other family than it was created with.
6842
+ */
6843
+ ipv6: boolean;
6506
6844
  }
6507
6845
 
6508
6846
  export interface SocketHandler<DataBinaryType extends BinaryType> {
@@ -6557,7 +6895,7 @@ declare module "bun" {
6557
6895
  unref(): void;
6558
6896
  close(): void;
6559
6897
  /**
6560
- * Enable or disable SO_BROADCAST socket option.
6898
+ * Enable or disable the SO_BROADCAST socket option.
6561
6899
  * @param enabled Whether to enable broadcast
6562
6900
  * @returns The enabled value
6563
6901
  */
@@ -6575,7 +6913,7 @@ declare module "bun" {
6575
6913
  */
6576
6914
  setMulticastTTL(ttl: number): number;
6577
6915
  /**
6578
- * Enable or disable IP_MULTICAST_LOOP socket option.
6916
+ * Enable or disable the IP_MULTICAST_LOOP socket option.
6579
6917
  * @param enabled Whether to enable multicast loopback
6580
6918
  * @returns The enabled value
6581
6919
  */
@@ -6636,7 +6974,7 @@ declare module "bun" {
6636
6974
  /**
6637
6975
  * Create a UDP socket
6638
6976
  *
6639
- * @param options The options to use when creating the server
6977
+ * @param options The options to use when creating the socket
6640
6978
  * @param options.socket The socket handler to use
6641
6979
  * @param options.hostname The hostname to listen on
6642
6980
  * @param options.port The port to listen on
@@ -6717,6 +7055,47 @@ declare module "bun" {
6717
7055
  */
6718
7056
  detached?: boolean;
6719
7057
 
7058
+ /**
7059
+ * Sets the user identity of the child process (see setuid(2)).
7060
+ *
7061
+ * POSIX only. On Windows the spawn fails with `ENOTSUP`.
7062
+ */
7063
+ uid?: number;
7064
+
7065
+ /**
7066
+ * Sets the group identity of the child process (see setgid(2)).
7067
+ *
7068
+ * POSIX only. On Windows the spawn fails with `ENOTSUP`.
7069
+ */
7070
+ gid?: number;
7071
+
7072
+ /**
7073
+ * Start the child process inside this control group.
7074
+ *
7075
+ * Pass the path of an existing cgroup directory (e.g.
7076
+ * `"/sys/fs/cgroup/my-jobs"`), or an open file descriptor for one. The
7077
+ * child joins it before it begins executing, so resource limits
7078
+ * configured on the cgroup (`memory.max`, `pids.max`, …) apply from its
7079
+ * first instruction and to everything it spawns in turn. Works with both
7080
+ * cgroup v1 and v2 hierarchies.
7081
+ *
7082
+ * Bun does not create or configure the cgroup; do that with `node:fs`
7083
+ * beforehand.
7084
+ *
7085
+ * Linux only; ignored on other platforms. On Linux, the spawn fails if
7086
+ * the cgroup cannot be joined (e.g. the directory does not exist).
7087
+ *
7088
+ * @example
7089
+ * ```ts
7090
+ * import { mkdirSync, writeFileSync } from "node:fs";
7091
+ * const dir = "/sys/fs/cgroup/build-jobs";
7092
+ * mkdirSync(dir, { recursive: true });
7093
+ * writeFileSync(dir + "/memory.max", String(2 * 1024 ** 3));
7094
+ * Bun.spawn({ cmd: ["make"], cgroup: dir });
7095
+ * ```
7096
+ */
7097
+ cgroup?: string | number;
7098
+
6720
7099
  /**
6721
7100
  * The environment variables of the process
6722
7101
  *
@@ -6732,33 +7111,40 @@ declare module "bun" {
6732
7111
  *
6733
7112
  * For stdin you may pass:
6734
7113
  *
6735
- * - `"ignore"`, `null`, `undefined`: The process will have no standard input (default)
6736
- * - `"pipe"`: The process will have a new {@link FileSink} for standard input
6737
- * - `"inherit"`: The process will inherit the standard input of the current process
6738
- * - `ArrayBufferView`, `Blob`, `Bun.file()`, `Response`, `Request`: The process will read from buffer/stream.
6739
- * - `number`: The process will read from the file descriptor
7114
+ * - `"ignore"`, `null`, `undefined`: The process has no standard input (default)
7115
+ * - `"pipe"`: The process has a new {@link FileSink} for standard input
7116
+ * - `"inherit"`: The process inherits the standard input of the current process
7117
+ * - `ArrayBufferView`, `Blob`, `Bun.file()`, `Response`, `Request`: The process reads from buffer/stream.
7118
+ * - `number`: The process reads from the file descriptor
6740
7119
  *
6741
- * For stdout and stdin you may pass:
7120
+ * For stdout and stderr you may pass:
6742
7121
  *
6743
- * - `"pipe"`, `undefined`: The process will have a {@link ReadableStream} for standard output/error
6744
- * - `"ignore"`, `null`: The process will have no standard output/error
6745
- * - `"inherit"`: The process will inherit the standard output/error of the current process
6746
- * - `ArrayBufferView`: The process write to the preallocated buffer. Not implemented.
6747
- * - `number`: The process will write to the file descriptor
7122
+ * - `"pipe"`, `undefined`: The process has a {@link ReadableStream} for standard output/error
7123
+ * - `"ignore"`, `null`: The process has no standard output/error
7124
+ * - `"inherit"`: The process inherits the standard output/error of the current process
7125
+ * - `ArrayBufferView`: The process writes to the preallocated buffer. Not implemented.
7126
+ * - `number`: The process writes to the file descriptor
7127
+ *
7128
+ * At indices >= 3, `"socket-fd"` (POSIX only) is also accepted:
7129
+ * creates a socketpair like `"pipe"`, but the parent-end fd exposed
7130
+ * via {@link Subprocess.stdio} is owned by the caller and is never
7131
+ * closed by the subprocess. Use this when you wrap the fd in
7132
+ * something that will close it itself (e.g. `net.connect({fd})`).
7133
+ * On Windows it behaves the same as `"pipe"`.
6748
7134
  *
6749
7135
  * @default ["ignore", "pipe", "inherit"] for `spawn`
6750
7136
  * ["ignore", "pipe", "pipe"] for `spawnSync`
6751
7137
  */
6752
- stdio?: [In, Out, Err, ...Readable[]];
7138
+ stdio?: [In, Out, Err, ...(Readable | "socket-fd")[]];
6753
7139
 
6754
7140
  /**
6755
7141
  * The file descriptor for the standard input. It may be:
6756
7142
  *
6757
- * - `"ignore"`, `null`, `undefined`: The process will have no standard input
6758
- * - `"pipe"`: The process will have a new {@link FileSink} for standard input
6759
- * - `"inherit"`: The process will inherit the standard input of the current process
6760
- * - `ArrayBufferView`, `Blob`: The process will read from the buffer
6761
- * - `number`: The process will read from the file descriptor
7143
+ * - `"ignore"`, `null`, `undefined`: The process has no standard input
7144
+ * - `"pipe"`: The process has a new {@link FileSink} for standard input
7145
+ * - `"inherit"`: The process inherits the standard input of the current process
7146
+ * - `ArrayBufferView`, `Blob`: The process reads from the buffer
7147
+ * - `number`: The process reads from the file descriptor
6762
7148
  *
6763
7149
  * @default "ignore"
6764
7150
  */
@@ -6766,11 +7152,11 @@ declare module "bun" {
6766
7152
  /**
6767
7153
  * The file descriptor for the standard output. It may be:
6768
7154
  *
6769
- * - `"pipe"`, `undefined`: The process will have a {@link ReadableStream} for standard output/error
6770
- * - `"ignore"`, `null`: The process will have no standard output/error
6771
- * - `"inherit"`: The process will inherit the standard output/error of the current process
6772
- * - `ArrayBufferView`: The process write to the preallocated buffer. Not implemented.
6773
- * - `number`: The process will write to the file descriptor
7155
+ * - `"pipe"`, `undefined`: The process has a {@link ReadableStream} for standard output/error
7156
+ * - `"ignore"`, `null`: The process has no standard output/error
7157
+ * - `"inherit"`: The process inherits the standard output/error of the current process
7158
+ * - `ArrayBufferView`: The process writes to the preallocated buffer. Not implemented.
7159
+ * - `number`: The process writes to the file descriptor
6774
7160
  *
6775
7161
  * @default "pipe"
6776
7162
  */
@@ -6778,11 +7164,11 @@ declare module "bun" {
6778
7164
  /**
6779
7165
  * The file descriptor for the standard error. It may be:
6780
7166
  *
6781
- * - `"pipe"`, `undefined`: The process will have a {@link ReadableStream} for standard output/error
6782
- * - `"ignore"`, `null`: The process will have no standard output/error
6783
- * - `"inherit"`: The process will inherit the standard output/error of the current process
6784
- * - `ArrayBufferView`: The process write to the preallocated buffer. Not implemented.
6785
- * - `number`: The process will write to the file descriptor
7167
+ * - `"pipe"`, `undefined`: The process has a {@link ReadableStream} for standard output/error
7168
+ * - `"ignore"`, `null`: The process has no standard output/error
7169
+ * - `"inherit"`: The process inherits the standard output/error of the current process
7170
+ * - `ArrayBufferView`: The process writes to the preallocated buffer. Not implemented.
7171
+ * - `number`: The process writes to the file descriptor
6786
7172
  *
6787
7173
  * @default "inherit" for `spawn`
6788
7174
  * "pipe" for `spawnSync`
@@ -6796,7 +7182,7 @@ declare module "bun" {
6796
7182
  *
6797
7183
  * Warning: this may run before the `Bun.spawn` function returns.
6798
7184
  *
6799
- * A simple alternative is `await subprocess.exited`.
7185
+ * An alternative is `await subprocess.exited`.
6800
7186
  *
6801
7187
  * @example
6802
7188
  *
@@ -6814,7 +7200,7 @@ declare module "bun" {
6814
7200
  exitCode: number | null,
6815
7201
  signalCode: number | null,
6816
7202
  /**
6817
- * If an error occurred in the call to waitpid2, this will be the error.
7203
+ * If an error occurred in the call to waitpid2, this is the error.
6818
7204
  */
6819
7205
  error?: ErrorLike,
6820
7206
  ): void | Promise<void>;
@@ -6862,14 +7248,14 @@ declare module "bun" {
6862
7248
  onDisconnect?(): void | Promise<void>;
6863
7249
 
6864
7250
  /**
6865
- * When specified, Bun will open an IPC channel to the subprocess. The passed callback is called for
7251
+ * When specified, Bun opens an IPC channel to the subprocess. The passed callback is called for
6866
7252
  * incoming messages, and `subprocess.send` can send messages to the subprocess. Messages are serialized
6867
- * using the JSC serialize API, which allows for the same types that `postMessage`/`structuredClone` supports.
7253
+ * using the JSC serialize API, which allows the same types that `postMessage`/`structuredClone` supports.
6868
7254
  *
6869
- * The subprocess can send and receive messages by using `process.send` and `process.on("message")`,
6870
- * respectively. This is the same API as what Node.js exposes when `child_process.fork()` is used.
7255
+ * The subprocess can send and receive messages with `process.send` and `process.on("message")`,
7256
+ * respectively. This is the same API that Node.js exposes when `child_process.fork()` is used.
6871
7257
  *
6872
- * Currently, this is only compatible with processes that are other `bun` instances.
7258
+ * This is only compatible with processes that are other `bun` instances.
6873
7259
  */
6874
7260
  ipc?(
6875
7261
  message: any,
@@ -6890,7 +7276,7 @@ declare module "bun" {
6890
7276
  serialization?: "json" | "advanced";
6891
7277
 
6892
7278
  /**
6893
- * If true, the subprocess will have a hidden window.
7279
+ * If true, the subprocess has a hidden window.
6894
7280
  */
6895
7281
  windowsHide?: boolean;
6896
7282
 
@@ -6900,22 +7286,26 @@ declare module "bun" {
6900
7286
  windowsVerbatimArguments?: boolean;
6901
7287
 
6902
7288
  /**
6903
- * Path to the executable to run in the subprocess. This defaults to `cmds[0]`.
7289
+ * Path to the executable to run in the subprocess.
6904
7290
  *
6905
- * One use-case for this is for applications which wrap other applications or to simulate a symlink.
7291
+ * Use this to wrap another application or to simulate a symlink.
6906
7292
  *
6907
7293
  * @default cmds[0]
6908
7294
  */
6909
7295
  argv0?: string;
6910
7296
 
6911
7297
  /**
6912
- * An {@link AbortSignal} that can be used to abort the subprocess.
7298
+ * An {@link AbortSignal} that kills the subprocess when aborted.
6913
7299
  *
6914
- * This is useful for aborting a subprocess when some other part of the
6915
- * program is aborted, such as a `fetch` response.
7300
+ * Use this to abort the subprocess when another part of the program is
7301
+ * aborted, such as a `fetch`.
6916
7302
  *
6917
- * If the signal is aborted, the process will be killed with the signal
6918
- * specified by `killSignal` (defaults to SIGTERM).
7303
+ * If the signal is already aborted when `spawn` is called, no process is
7304
+ * created and an `AbortError` (with `cause` set to `signal.reason`) is
7305
+ * thrown synchronously.
7306
+ *
7307
+ * If the signal is aborted after the process starts, the process is
7308
+ * killed with the signal specified by `killSignal` (defaults to SIGTERM).
6919
7309
  *
6920
7310
  * @example
6921
7311
  * ```ts
@@ -6938,7 +7328,7 @@ declare module "bun" {
6938
7328
  /**
6939
7329
  * The maximum amount of time the process is allowed to run in milliseconds.
6940
7330
  *
6941
- * If the timeout is reached, the process will be killed with the signal
7331
+ * If the timeout is reached, the process is killed with the signal
6942
7332
  * specified by `killSignal` (defaults to SIGTERM).
6943
7333
  *
6944
7334
  * @example
@@ -6986,8 +7376,8 @@ declare module "bun" {
6986
7376
  interface SpawnOptions<In extends Writable, Out extends Readable, Err extends Readable>
6987
7377
  extends BaseOptions<In, Out, Err> {
6988
7378
  /**
6989
- * If true, stdout and stderr pipes will not automatically start reading
6990
- * data. Reading will only begin when you access the `stdout` or `stderr`
7379
+ * If true, the stdout and stderr pipes don't automatically start reading
7380
+ * data. Reading begins only when you access the `stdout` or `stderr`
6991
7381
  * properties.
6992
7382
  *
6993
7383
  * This can improve performance when you don't need to read output
@@ -7096,7 +7486,7 @@ declare module "bun" {
7096
7486
  total: number;
7097
7487
  };
7098
7488
  /**
7099
- * The maximum amount of resident set size (in bytes) used by the process during its lifetime.
7489
+ * The maximum resident set size (in bytes) used by the process during its lifetime.
7100
7490
  */
7101
7491
  maxRSS: number;
7102
7492
 
@@ -7135,7 +7525,7 @@ declare module "bun" {
7135
7525
  */
7136
7526
  signalCount: number;
7137
7527
  /**
7138
- * The number of times the process was swapped out of main memory.
7528
+ * The number of times the process was swapped out of main memory.
7139
7529
  */
7140
7530
  swapCount: number;
7141
7531
  }
@@ -7143,7 +7533,7 @@ declare module "bun" {
7143
7533
  /**
7144
7534
  * A process created by {@link Bun.spawn}.
7145
7535
  *
7146
- * This type accepts 3 optional type parameters which correspond to the `stdio` array from the options object. Instead of specifying these, you should use one of the following utility types instead:
7536
+ * The 3 optional type parameters correspond to the `stdio` array from the options object. Instead of specifying them, use one of these utility types:
7147
7537
  * - {@link ReadableSubprocess} (any, pipe, pipe)
7148
7538
  * - {@link WritableSubprocess} (pipe, any, any)
7149
7539
  * - {@link PipedSubprocess} (pipe, pipe, pipe)
@@ -7160,7 +7550,7 @@ declare module "bun" {
7160
7550
 
7161
7551
  /**
7162
7552
  * The terminal attached to this subprocess, if spawned with the `terminal` option.
7163
- * Returns `undefined` if no terminal was attached.
7553
+ * `undefined` if no terminal was attached.
7164
7554
  *
7165
7555
  * When a terminal is attached, `stdin`, `stdout`, and `stderr` return `null`.
7166
7556
  * Use `terminal.write()` and the `data` callback instead.
@@ -7177,19 +7567,21 @@ declare module "bun" {
7177
7567
  readonly terminal: Terminal | undefined;
7178
7568
 
7179
7569
  /**
7180
- * Access extra file descriptors passed to the `stdio` option in the options object.
7570
+ * Extra file descriptors passed to the `stdio` option.
7181
7571
  *
7182
- * Entries beyond index 2 are `number` for `"pipe"` slots and, on POSIX, for slots
7183
- * where a raw file descriptor was supplied (the same fd is returned; it remains
7184
- * owned by the caller and is never closed by the subprocess). Other slots —
7185
- * including raw fds on Windows — are `null`.
7572
+ * Entries beyond index 2 are `number` for `"pipe"` and `"socket-fd"` slots and,
7573
+ * on POSIX, for slots where a raw file descriptor was supplied (the same fd is
7574
+ * returned). On POSIX, reading this property transfers ownership of any
7575
+ * `"pipe"` fds to the caller, who is then responsible for closing them; the
7576
+ * subprocess will not close them. `"socket-fd"` and raw-fd slots are likewise
7577
+ * caller-owned. Other slots — including raw fds on Windows — are `null`.
7186
7578
  */
7187
7579
  readonly stdio: [null, null, null, ...(number | null)[]];
7188
7580
 
7189
7581
  /**
7190
- * This returns the same value as {@link Subprocess.stdout}
7582
+ * The same value as {@link Subprocess.stdout}
7191
7583
  *
7192
- * It exists for compatibility with {@link ReadableStream.pipeThrough}
7584
+ * Exists for compatibility with {@link ReadableStream.pipeThrough}
7193
7585
  */
7194
7586
  readonly readable: SpawnOptions.ReadableToIO<Out>;
7195
7587
 
@@ -7206,52 +7598,52 @@ declare module "bun" {
7206
7598
  /**
7207
7599
  * The exit code of the process
7208
7600
  *
7209
- * The promise will resolve when the process exits
7601
+ * The promise resolves when the process exits
7210
7602
  */
7211
7603
  readonly exited: Promise<number>;
7212
7604
 
7213
7605
  /**
7214
7606
  * Synchronously get the exit code of the process
7215
7607
  *
7216
- * If the process hasn't exited yet, this will return `null`
7608
+ * `null` if the process hasn't exited yet
7217
7609
  */
7218
7610
  readonly exitCode: number | null;
7219
7611
 
7220
7612
  /**
7221
7613
  * Synchronously get the signal code of the process
7222
7614
  *
7223
- * If the process never sent a signal code, this will return `null`
7615
+ * `null` if the process never sent a signal code
7224
7616
  *
7225
7617
  * To receive signal code changes, use the `onExit` callback.
7226
7618
  *
7227
- * If the signal code is unknown, it will return the original signal code
7228
- * number, but that case should essentially never happen.
7619
+ * If the signal code is unknown, this is the original signal code
7620
+ * number, but that case should never happen in practice.
7229
7621
  */
7230
7622
  readonly signalCode: NodeJS.Signals | null;
7231
7623
 
7232
7624
  /**
7233
- * Has the process exited?
7625
+ * Whether the process has exited
7234
7626
  */
7235
7627
  readonly killed: boolean;
7236
7628
 
7237
7629
  /**
7238
7630
  * Kill the process
7239
- * @param exitCode The exitCode to send to the process
7631
+ * @param exitCode Exit code or signal to send to the process
7240
7632
  */
7241
7633
  kill(exitCode?: number | NodeJS.Signals): void;
7242
7634
 
7243
7635
  /**
7244
- * This method will tell Bun to wait for this process to exit after you already
7636
+ * Tell Bun to wait for this process to exit after you already
7245
7637
  * called `unref()`.
7246
7638
  *
7247
- * Before shutting down, Bun will wait for all subprocesses to exit by default
7639
+ * By default, Bun waits for all subprocesses to exit before shutting down
7248
7640
  */
7249
7641
  ref(): void;
7250
7642
 
7251
7643
  /**
7252
- * Before shutting down, Bun will wait for all subprocesses to exit by default
7644
+ * Tell Bun not to wait for this process to exit before shutting down.
7253
7645
  *
7254
- * This method will tell Bun to not wait for this process to exit before shutting down.
7646
+ * By default, Bun waits for all subprocesses to exit before shutting down.
7255
7647
  */
7256
7648
  unref(): void;
7257
7649
 
@@ -7270,11 +7662,9 @@ declare module "bun" {
7270
7662
  disconnect(): void;
7271
7663
 
7272
7664
  /**
7273
- * Get the resource usage information of the process (max RSS, CPU time, etc)
7274
- *
7275
- * Only available after the process has exited
7665
+ * Get the resource usage of the process, such as max RSS and CPU time
7276
7666
  *
7277
- * If the process hasn't exited yet, this will return `undefined`
7667
+ * Returns `undefined` until the process has exited
7278
7668
  */
7279
7669
  resourceUsage(): ResourceUsage | undefined;
7280
7670
  }
@@ -7282,7 +7672,7 @@ declare module "bun" {
7282
7672
  /**
7283
7673
  * A process created by {@link Bun.spawnSync}.
7284
7674
  *
7285
- * This type accepts 2 optional type parameters which correspond to the `stdout` and `stderr` options. Instead of specifying these, you should use one of the following utility types instead:
7675
+ * The 2 optional type parameters correspond to the `stdout` and `stderr` options. Instead of specifying them, use one of these utility types:
7286
7676
  * - {@link ReadableSyncSubprocess} (pipe, pipe)
7287
7677
  * - {@link NullSyncSubprocess} (ignore, ignore)
7288
7678
  */
@@ -7295,7 +7685,7 @@ declare module "bun" {
7295
7685
  exitCode: number;
7296
7686
  success: boolean;
7297
7687
  /**
7298
- * Get the resource usage information of the process (max RSS, CPU time, etc)
7688
+ * Resource usage of the process, such as max RSS and CPU time
7299
7689
  */
7300
7690
  resourceUsage: ResourceUsage;
7301
7691
 
@@ -7330,9 +7720,9 @@ declare module "bun" {
7330
7720
  /**
7331
7721
  * The command to run
7332
7722
  *
7333
- * The first argument will be resolved to an absolute executable path. It must be a file, not a directory.
7723
+ * The first argument is resolved to an absolute executable path. It must be a file, not a directory.
7334
7724
  *
7335
- * If you explicitly set `PATH` in `env`, that `PATH` will be used to resolve the executable instead of the default `PATH`.
7725
+ * If you explicitly set `PATH` in `env`, that `PATH` is used to resolve the executable instead of the default `PATH`.
7336
7726
  *
7337
7727
  * To check if the command exists before running it, use `Bun.which(bin)`.
7338
7728
  *
@@ -7364,9 +7754,9 @@ declare module "bun" {
7364
7754
  /**
7365
7755
  * The command to run
7366
7756
  *
7367
- * The first argument will be resolved to an absolute executable path. It must be a file, not a directory.
7757
+ * The first argument is resolved to an absolute executable path. It must be a file, not a directory.
7368
7758
  *
7369
- * If you explicitly set `PATH` in `env`, that `PATH` will be used to resolve the executable instead of the default `PATH`.
7759
+ * If you explicitly set `PATH` in `env`, that `PATH` is used to resolve the executable instead of the default `PATH`.
7370
7760
  *
7371
7761
  * To check if the command exists before running it, use `Bun.which(bin)`.
7372
7762
  *
@@ -7380,7 +7770,7 @@ declare module "bun" {
7380
7770
  ): Subprocess<In, Out, Err>;
7381
7771
 
7382
7772
  /**
7383
- * Spawn a new process
7773
+ * Synchronously spawn a new process
7384
7774
  *
7385
7775
  * @category Process Management
7386
7776
  *
@@ -7402,9 +7792,9 @@ declare module "bun" {
7402
7792
  /**
7403
7793
  * The command to run
7404
7794
  *
7405
- * The first argument will be resolved to an absolute executable path. It must be a file, not a directory.
7795
+ * The first argument is resolved to an absolute executable path. It must be a file, not a directory.
7406
7796
  *
7407
- * If you explicitly set `PATH` in `env`, that `PATH` will be used to resolve the executable instead of the default `PATH`.
7797
+ * If you explicitly set `PATH` in `env`, that `PATH` is used to resolve the executable instead of the default `PATH`.
7408
7798
  *
7409
7799
  * To check if the command exists before running it, use `Bun.which(bin)`.
7410
7800
  *
@@ -7437,9 +7827,9 @@ declare module "bun" {
7437
7827
  /**
7438
7828
  * The command to run
7439
7829
  *
7440
- * The first argument will be resolved to an absolute executable path. It must be a file, not a directory.
7830
+ * The first argument is resolved to an absolute executable path. It must be a file, not a directory.
7441
7831
  *
7442
- * If you explicitly set `PATH` in `env`, that `PATH` will be used to resolve the executable instead of the default `PATH`.
7832
+ * If you explicitly set `PATH` in `env`, that `PATH` is used to resolve the executable instead of the default `PATH`.
7443
7833
  *
7444
7834
  * To check if the command exists before running it, use `Bun.which(bin)`.
7445
7835
  *
@@ -7506,7 +7896,7 @@ declare module "bun" {
7506
7896
  * ```
7507
7897
  */
7508
7898
  interface CronJob extends Disposable {
7509
- /** The cron expression string. */
7899
+ /** The schedule expression this job was created with. */
7510
7900
  readonly cron: string;
7511
7901
  /** Cancel this cron job. The callback will not fire again. */
7512
7902
  stop(): CronJob;
@@ -7516,6 +7906,24 @@ declare module "bun" {
7516
7906
  unref(): CronJob;
7517
7907
  }
7518
7908
 
7909
+ /**
7910
+ * Options for the in-process {@link Bun.cron} callback overload and {@link Bun.cron.parse}.
7911
+ */
7912
+ interface CronOptions {
7913
+ /**
7914
+ * IANA time-zone name to interpret the schedule in (e.g. `"UTC"`,
7915
+ * `"America/New_York"`). Defaults to the system's local time zone.
7916
+ */
7917
+ tz?: string;
7918
+ }
7919
+
7920
+ /**
7921
+ * Schedule cron jobs.
7922
+ *
7923
+ * Call with a callback to run an in-process job, or with a module path and
7924
+ * title to register an OS-level job. {@link Bun.cron.parse} previews the next
7925
+ * fire time; {@link Bun.cron.remove} unregisters an OS-level job.
7926
+ */
7519
7927
  const cron: {
7520
7928
  /**
7521
7929
  * Schedule an **in-process** cron job that calls a function on a schedule.
@@ -7550,8 +7958,7 @@ declare module "bun" {
7550
7958
  *
7551
7959
  * ### Cron expression syntax
7552
7960
  *
7553
- * Five fields: `minute hour day-of-month month day-of-week`. Schedules are
7554
- * interpreted in **UTC** — `0 9 * * *` fires at 9:00 UTC, regardless of `TZ`.
7961
+ * Five fields: `minute hour day-of-month month day-of-week`.
7555
7962
  *
7556
7963
  * | Field | Values | Special chars |
7557
7964
  * |-------|--------|---------------|
@@ -7605,7 +8012,7 @@ declare module "bun" {
7605
8012
  * @see {@link CronJob} for the returned handle.
7606
8013
  * @see {@link Bun.cron.parse} to preview the next fire time.
7607
8014
  */
7608
- (schedule: CronWithAutocomplete, handler: (this: CronJob) => unknown): CronJob;
8015
+ (schedule: CronWithAutocomplete, handler: (this: CronJob) => unknown, options?: CronOptions): CronJob;
7609
8016
  /**
7610
8017
  * Register an **OS-level** cron job that runs a JavaScript/TypeScript module on a schedule.
7611
8018
  *
@@ -7705,7 +8112,10 @@ declare module "bun" {
7705
8112
  */
7706
8113
  remove(title: string): Promise<void>;
7707
8114
  /**
7708
- * Parse a cron expression and return the next matching `Date` in UTC.
8115
+ * Parse a cron expression and return the next matching `Date` in the
8116
+ * system's local time zone — the same way crontab, launchd, and Windows
8117
+ * Task Scheduler interpret schedules. Pass `{ tz: "UTC" }` (or any IANA
8118
+ * time-zone name) to override.
7709
8119
  *
7710
8120
  * Supports the same syntax as {@link Bun.cron} — 5-field expressions, named
7711
8121
  * days/months, and predefined nicknames like `@daily`.
@@ -7714,23 +8124,31 @@ declare module "bun" {
7714
8124
  * matching uses OR logic per [POSIX cron](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/crontab.html):
7715
8125
  * a date matches if **either** field matches.
7716
8126
  *
8127
+ * DST: spring-forward times shift forward by the gap; in the fall-back
8128
+ * duplicated hour, fixed-time schedules fire once (first occurrence) while
8129
+ * schedules with `*` minute or hour fire through both occurrences.
8130
+ *
7717
8131
  * @param expression - A cron expression or nickname (e.g. `"0,15,30,45 * * * *"`, `"0 9 * * MON-FRI"`, `"@hourly"`)
7718
8132
  * @param relativeDate - Starting point for the search (defaults to `Date.now()`). Accepts a `Date` or milliseconds since epoch.
7719
- * @returns The next `Date` matching the expression in UTC, or `null` if no match exists within 8 years (e.g. `"0 0 30 2 *"` — Feb 30 never occurs)
7720
- * @throws If the expression is invalid or `relativeDate` is `NaN`/`Infinity`
8133
+ * @param options - `{ tz?: string }` — IANA time-zone name to interpret the schedule in (defaults to the system's local zone).
8134
+ * @returns The next `Date` matching the expression, or `null` if no match exists within 8 years (e.g. `"0 0 30 2 *"` — Feb 30 never occurs)
8135
+ * @throws If the expression is invalid, `relativeDate` is `NaN`/`Infinity`, or `options.tz` is not a valid IANA name
7721
8136
  *
7722
8137
  * @example
7723
8138
  * ```ts
7724
- * // Next weekday at 09:30 UTC
8139
+ * // Next weekday at 09:30 local time
7725
8140
  * const next = Bun.cron.parse("30 9 * * MON-FRI");
7726
8141
  *
8142
+ * // 09:00 in New York, regardless of the server's TZ
8143
+ * const ny = Bun.cron.parse("0 9 * * *", Date.now(), { tz: "America/New_York" });
8144
+ *
7727
8145
  * // Chain calls to get a sequence
7728
8146
  * const from = new Date();
7729
8147
  * const first = Bun.cron.parse("@hourly", from);
7730
8148
  * const second = first ? Bun.cron.parse("@hourly", first) : null;
7731
8149
  * ```
7732
8150
  */
7733
- parse(expression: CronWithAutocomplete, relativeDate?: Date | number): Date | null;
8151
+ parse(expression: CronWithAutocomplete, relativeDate?: Date | number, options?: CronOptions): Date | null;
7734
8152
  };
7735
8153
 
7736
8154
  /** Utility type for any process from {@link Bun.spawn()} with both stdout and stderr set to `"pipe"` */
@@ -7780,11 +8198,11 @@ declare module "bun" {
7780
8198
  data?: (terminal: Terminal, data: Uint8Array<ArrayBuffer>) => void;
7781
8199
  /**
7782
8200
  * Callback invoked when the PTY stream closes (EOF or read error).
7783
- * Note: exitCode is a PTY lifecycle status (0=clean EOF, 1=error), NOT the subprocess exit code.
7784
- * Use Subprocess.exited or onExit callback for actual process exit information.
8201
+ * `exitCode` is a PTY lifecycle status (0 = clean EOF, 1 = error), NOT the subprocess exit code.
8202
+ * Use {@link Subprocess.exited} or the `onExit` callback for the process exit information.
7785
8203
  * @param terminal The terminal instance
7786
8204
  * @param exitCode PTY lifecycle status (0 for EOF, 1 for error)
7787
- * @param signal Reserved for future signal reporting, currently null
8205
+ * @param signal Always `null`; reserved for future signal reporting
7788
8206
  */
7789
8207
  exit?: (terminal: Terminal, exitCode: number, signal: string | null) => void;
7790
8208
  /**
@@ -7795,7 +8213,7 @@ declare module "bun" {
7795
8213
  }
7796
8214
 
7797
8215
  /**
7798
- * A pseudo-terminal (PTY) that can be used to spawn interactive terminal programs.
8216
+ * A pseudo-terminal (PTY) for spawning interactive terminal programs.
7799
8217
  *
7800
8218
  * @example
7801
8219
  * ```ts
@@ -7829,8 +8247,14 @@ declare module "bun" {
7829
8247
 
7830
8248
  /**
7831
8249
  * Write data to the terminal.
8250
+ *
8251
+ * All bytes are accepted; any portion that cannot be flushed to the PTY
8252
+ * immediately is buffered and delivered later. The `drain` callback fires
8253
+ * once buffered data has been flushed. Do not re-send any part of `data`
8254
+ * based on the return value.
8255
+ *
7832
8256
  * @param data The data to write (string or BufferSource)
7833
- * @returns The number of bytes written
8257
+ * @returns The number of bytes accepted (the byte length of `data`)
7834
8258
  */
7835
8259
  write(data: string | BufferSource): number;
7836
8260
 
@@ -7871,7 +8295,7 @@ declare module "bun" {
7871
8295
  /**
7872
8296
  * Terminal input flags (c_iflag from termios).
7873
8297
  * Controls input processing behavior like ICRNL, IXON, etc.
7874
- * Returns 0 if terminal is closed.
8298
+ * Returns 0 if the terminal is closed.
7875
8299
  * Setting returns true on success, false on failure.
7876
8300
  */
7877
8301
  inputFlags: number;
@@ -7879,7 +8303,7 @@ declare module "bun" {
7879
8303
  /**
7880
8304
  * Terminal output flags (c_oflag from termios).
7881
8305
  * Controls output processing behavior like OPOST, ONLCR, etc.
7882
- * Returns 0 if terminal is closed.
8306
+ * Returns 0 if the terminal is closed.
7883
8307
  * Setting returns true on success, false on failure.
7884
8308
  */
7885
8309
  outputFlags: number;
@@ -7887,7 +8311,7 @@ declare module "bun" {
7887
8311
  /**
7888
8312
  * Terminal local flags (c_lflag from termios).
7889
8313
  * Controls local processing like ICANON, ECHO, ISIG, etc.
7890
- * Returns 0 if terminal is closed.
8314
+ * Returns 0 if the terminal is closed.
7891
8315
  * Setting returns true on success, false on failure.
7892
8316
  */
7893
8317
  localFlags: number;
@@ -7895,7 +8319,7 @@ declare module "bun" {
7895
8319
  /**
7896
8320
  * Terminal control flags (c_cflag from termios).
7897
8321
  * Controls hardware characteristics like CSIZE, PARENB, etc.
7898
- * Returns 0 if terminal is closed.
8322
+ * Returns 0 if the terminal is closed.
7899
8323
  * Setting returns true on success, false on failure.
7900
8324
  */
7901
8325
  controlFlags: number;
@@ -7926,6 +8350,10 @@ declare module "bun" {
7926
8350
  // },
7927
8351
  // ): number;
7928
8352
 
8353
+ /**
8354
+ * Resolve routes against a directory of files using Next.js-style (`pages`
8355
+ * directory) conventions.
8356
+ */
7929
8357
  class FileSystemRouter {
7930
8358
  /**
7931
8359
  * Create a new {@link FileSystemRouter}.
@@ -7942,19 +8370,11 @@ declare module "bun" {
7942
8370
  * ```
7943
8371
  * @param options The options to use when creating the router
7944
8372
  * @param options.dir The root directory containing the files to route
7945
- * @param options.style The style of router to use (only "nextjs" supported
7946
- * for now)
8373
+ * @param options.style The style of router to use (only "nextjs" is supported)
7947
8374
  */
7948
8375
  constructor(options: {
7949
8376
  /**
7950
8377
  * The root directory containing the files to route
7951
- *
7952
- * There is no default value for this option.
7953
- *
7954
- * @example
7955
- * ```ts
7956
- * const router = new FileSystemRouter({
7957
- * dir:
7958
8378
  */
7959
8379
  dir: string;
7960
8380
  style: "nextjs";
@@ -8026,7 +8446,7 @@ declare module "bun" {
8026
8446
  /**
8027
8447
  * Find the index of a newline character in potentially ill-formed UTF-8 text.
8028
8448
  *
8029
- * This is sort of like readline() except without the IO.
8449
+ * Like `readline()`, but without the IO.
8030
8450
  */
8031
8451
  function indexOfLine(buffer: ArrayBufferView | ArrayBufferLike, offset?: number): number;
8032
8452
 
@@ -8051,14 +8471,14 @@ declare module "bun" {
8051
8471
  absolute?: boolean;
8052
8472
 
8053
8473
  /**
8054
- * Indicates whether to traverse descendants of symbolic link directories.
8474
+ * Whether to traverse descendants of symbolic link directories.
8055
8475
  *
8056
8476
  * @default false
8057
8477
  */
8058
8478
  followSymlinks?: boolean;
8059
8479
 
8060
8480
  /**
8061
- * Throw an error when symbolic link is broken
8481
+ * Throw an error when a symbolic link is broken
8062
8482
  *
8063
8483
  * @default false
8064
8484
  */
@@ -8075,7 +8495,7 @@ declare module "bun" {
8075
8495
  /**
8076
8496
  * Match files using [glob patterns](https://en.wikipedia.org/wiki/Glob_(programming)).
8077
8497
  *
8078
- * The supported pattern syntax for is:
8498
+ * The supported pattern syntax is:
8079
8499
  *
8080
8500
  * - `?`
8081
8501
  * Matches any single character.
@@ -8083,22 +8503,22 @@ declare module "bun" {
8083
8503
  * Matches zero or more characters, except for path separators ('/' or '\').
8084
8504
  * - `**`
8085
8505
  * Matches zero or more characters, including path separators.
8086
- * Must match a complete path segment, i.e. followed by a path separator or
8087
- * at the end of the pattern.
8506
+ * Must match a complete path segment (followed by a path separator or
8507
+ * at the end of the pattern).
8088
8508
  * - `[ab]`
8089
8509
  * Matches one of the characters contained in the brackets.
8090
- * Character ranges (e.g. "[a-z]") are also supported.
8510
+ * Character ranges like "[a-z]" are also supported.
8091
8511
  * Use "[!ab]" or "[^ab]" to match any character *except* those contained
8092
8512
  * in the brackets.
8093
8513
  * - `{a,b}`
8094
8514
  * Match one of the patterns contained in the braces.
8095
- * Any of the wildcards listed above can be used in the sub patterns.
8515
+ * The sub-patterns can use any of the other wildcards.
8096
8516
  * Braces may be nested up to 10 levels deep.
8097
8517
  * - `!`
8098
8518
  * Negates the result when at the start of the pattern.
8099
8519
  * Multiple "!" characters negate the pattern multiple times.
8100
8520
  * - `\`
8101
- * Used to escape any of the special characters above.
8521
+ * Escapes any of the special characters listed here.
8102
8522
  *
8103
8523
  * @example
8104
8524
  * ```js
@@ -8404,6 +8824,7 @@ declare module "bun" {
8404
8824
 
8405
8825
  /** Populated after the first awaited terminal; `-1` before. */
8406
8826
  readonly width: number;
8827
+ /** Populated after the first awaited terminal; `-1` before. */
8407
8828
  readonly height: number;
8408
8829
  }
8409
8830
 
@@ -8474,7 +8895,7 @@ declare module "bun" {
8474
8895
  * Auto-detects the binary in standard locations; override with
8475
8896
  * `backend.path` or the `BUN_CHROME_PATH` environment variable.
8476
8897
  *
8477
- * The object form lets you pass extra launch flags. Chrome switches are
8898
+ * The object form accepts extra launch flags. Chrome switches are
8478
8899
  * last-wins for duplicates, so `argv` can override the defaults.
8479
8900
  *
8480
8901
  * **Chrome is spawned once per process** — the first `new Bun.WebView()`
@@ -8602,7 +9023,7 @@ declare module "bun" {
8602
9023
  /**
8603
9024
  * Initial URL to navigate to. The navigation starts before the
8604
9025
  * constructor returns; `await view.navigate(otherUrl)` or any other
8605
- * operation will wait for it to complete first.
9026
+ * operation waits for it to complete first.
8606
9027
  *
8607
9028
  * Equivalent to calling `view.navigate(url)` immediately after
8608
9029
  * construction.
@@ -8666,7 +9087,7 @@ declare module "bun" {
8666
9087
  * Pending promises on all views reject on the next event loop tick.
8667
9088
  *
8668
9089
  * Called automatically at process exit. Call manually to reclaim browser
8669
- * resources early — subsequent `new Bun.WebView()` calls will respawn.
9090
+ * resources early — subsequent `new Bun.WebView()` calls respawn them.
8670
9091
  * Idempotent: calling when no subprocesses are alive is a no-op.
8671
9092
  */
8672
9093
  static closeAll(): void;
@@ -8945,7 +9366,7 @@ declare module "bun" {
8945
9366
 
8946
9367
  /**
8947
9368
  * Compression format for archive output.
8948
- * Currently only `"gzip"` is supported.
9369
+ * Only `"gzip"` is supported.
8949
9370
  */
8950
9371
  type ArchiveCompression = "gzip";
8951
9372
 
@@ -8969,7 +9390,7 @@ declare module "bun" {
8969
9390
  interface ArchiveOptions {
8970
9391
  /**
8971
9392
  * Compression algorithm to use.
8972
- * Currently only "gzip" is supported.
9393
+ * Only `"gzip"` is supported.
8973
9394
  * If not specified, no compression is applied.
8974
9395
  */
8975
9396
  compress?: ArchiveCompression;
@@ -8996,8 +9417,8 @@ declare module "bun" {
8996
9417
  * Patterns are matched against archive entry paths normalized to use forward slashes (`/`),
8997
9418
  * regardless of the host operating system. Always write patterns using `/` as the separator.
8998
9419
  *
8999
- * - Positive patterns: Only entries matching at least one pattern will be extracted.
9000
- * - Negative patterns (prefixed with `!`): Entries matching these patterns will be excluded.
9420
+ * - Positive patterns: Only entries matching at least one pattern are extracted.
9421
+ * - Negative patterns (prefixed with `!`): Entries matching these patterns are excluded.
9001
9422
  * Negative patterns are applied after positive patterns.
9002
9423
  *
9003
9424
  * If not specified, all entries are extracted.
@@ -9021,11 +9442,10 @@ declare module "bun" {
9021
9442
  }
9022
9443
 
9023
9444
  /**
9024
- * A class for creating and extracting tar archives with optional gzip compression.
9445
+ * Create and extract tar archives, with optional gzip compression.
9025
9446
  *
9026
- * `Bun.Archive` provides a fast, native implementation for working with tar archives.
9027
- * It supports creating archives from in-memory data or extracting existing archives
9028
- * to disk or memory.
9447
+ * `Bun.Archive` builds an archive from in-memory data, or wraps an existing
9448
+ * archive so you can extract it to disk or memory.
9029
9449
  *
9030
9450
  * @example
9031
9451
  * **Create an archive from an object:**
@@ -9084,8 +9504,7 @@ declare module "bun" {
9084
9504
  * @param data - The input data for the archive:
9085
9505
  * - **Object**: Creates a new tarball with the object's keys as file paths and values as file contents
9086
9506
  * - **Blob/TypedArray/ArrayBuffer**: Wraps existing archive data (tar or tar.gz)
9087
- * @param options - Optional archive options including compression settings.
9088
- * Defaults to no compression if omitted.
9507
+ * @param options - Archive options, including compression settings
9089
9508
  *
9090
9509
  * @example
9091
9510
  * **From an object (creates uncompressed tarball):**
@@ -9118,10 +9537,10 @@ declare module "bun" {
9118
9537
  constructor(data: ArchiveInput, options?: ArchiveOptions);
9119
9538
 
9120
9539
  /**
9121
- * Create and write an archive directly to disk in one operation.
9540
+ * Create an archive and write it to disk in one operation.
9122
9541
  *
9123
- * This is more efficient than creating an archive and then writing it separately,
9124
- * as it streams the data directly to disk.
9542
+ * The data streams directly to disk, which is more efficient than creating an
9543
+ * archive and then writing it separately.
9125
9544
  *
9126
9545
  * @param path - The file path to write the archive to
9127
9546
  * @param data - The input data for the archive (same as `new Archive()`)
@@ -9150,7 +9569,7 @@ declare module "bun" {
9150
9569
  * Extract the archive contents to a directory on disk.
9151
9570
  *
9152
9571
  * Creates the target directory and any necessary parent directories if they don't exist.
9153
- * Existing files will be overwritten.
9572
+ * Existing files are overwritten.
9154
9573
  *
9155
9574
  * @param path - The directory path to extract to
9156
9575
  * @param options - Optional extraction options
@@ -9286,14 +9705,14 @@ declare module "bun" {
9286
9705
  }
9287
9706
 
9288
9707
  /**
9289
- * Generate a UUIDv7, which is a sequential ID based on the current timestamp with a random component.
9708
+ * Generate a UUIDv7, a sequential ID based on the current timestamp with a random component.
9290
9709
  *
9291
9710
  * When the same timestamp is used multiple times, a monotonically increasing
9292
9711
  * counter is appended to allow sorting. The final 8 bytes are
9293
9712
  * cryptographically random. When the timestamp changes, the counter resets to
9294
- * a psuedo-random integer.
9713
+ * a pseudo-random integer.
9295
9714
  *
9296
- * @param encoding "hex" | "base64" | "base64url"
9715
+ * @param encoding Output encoding for the UUID
9297
9716
  * @param timestamp Unix timestamp in milliseconds, defaults to `Date.now()`
9298
9717
  *
9299
9718
  * @example
@@ -9303,12 +9722,12 @@ declare module "bun" {
9303
9722
  * randomUUIDv7(),
9304
9723
  * randomUUIDv7(),
9305
9724
  * randomUUIDv7(),
9306
- * ]
9307
- * [
9308
- * "0192ce07-8c4f-7d66-afec-2482b5c9b03c",
9309
- * "0192ce07-8c4f-7d67-805f-0f71581b5622",
9310
- * "0192ce07-8c4f-7d68-8170-6816e4451a58"
9311
- * ]
9725
+ * ];
9726
+ * // [
9727
+ * // "0192ce07-8c4f-7d66-afec-2482b5c9b03c",
9728
+ * // "0192ce07-8c4f-7d67-805f-0f71581b5622",
9729
+ * // "0192ce07-8c4f-7d68-8170-6816e4451a58"
9730
+ * // ]
9312
9731
  * ```
9313
9732
  */
9314
9733
  function randomUUIDv7(
@@ -9323,9 +9742,9 @@ declare module "bun" {
9323
9742
  ): string;
9324
9743
 
9325
9744
  /**
9326
- * Generate a UUIDv7 as a Buffer
9745
+ * Generate a UUIDv7 as a `Buffer`.
9327
9746
  *
9328
- * @param encoding "buffer"
9747
+ * @param encoding Pass `"buffer"` to get the UUID as bytes instead of a string
9329
9748
  * @param timestamp Unix timestamp in milliseconds, defaults to `Date.now()`
9330
9749
  */
9331
9750
  function randomUUIDv7(
@@ -9337,24 +9756,23 @@ declare module "bun" {
9337
9756
  ): Buffer;
9338
9757
 
9339
9758
  /**
9340
- * Generate a UUIDv5, which is a name-based UUID based on the SHA-1 hash of a namespace UUID and a name.
9341
- *
9342
- * @param name The name to use for the UUID
9343
- * @param namespace The namespace to use for the UUID
9344
- * @param encoding The encoding to use for the UUID
9759
+ * Generate a UUIDv5, a name-based UUID derived from the SHA-1 hash of a namespace UUID and a name.
9345
9760
  *
9761
+ * @param name The name to hash
9762
+ * @param namespace A namespace UUID, or one of the predefined namespaces `"dns"`, `"url"`, `"oid"`, or `"x500"`
9763
+ * @param encoding Output encoding for the UUID
9346
9764
  *
9347
9765
  * @example
9348
9766
  * ```js
9349
9767
  * import { randomUUIDv5 } from "bun";
9350
9768
  * const uuid = randomUUIDv5("www.example.com", "dns");
9351
- * console.log(uuid); // "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
9769
+ * console.log(uuid); // "2ed6657d-e927-568b-95e1-2665a8aea6a2"
9352
9770
  * ```
9353
9771
  *
9354
9772
  * ```js
9355
9773
  * import { randomUUIDv5 } from "bun";
9356
9774
  * const uuid = randomUUIDv5("www.example.com", "url");
9357
- * console.log(uuid); // "6ba7b811-9dad-11d1-80b4-00c04fd430c8"
9775
+ * console.log(uuid); // "b63cdfa4-3df9-568e-97ae-006c5b8fd652"
9358
9776
  * ```
9359
9777
  */
9360
9778
  function randomUUIDv5(
@@ -9367,17 +9785,17 @@ declare module "bun" {
9367
9785
  ): string;
9368
9786
 
9369
9787
  /**
9370
- * Generate a UUIDv5 as a Buffer
9788
+ * Generate a UUIDv5 as a `Buffer`.
9371
9789
  *
9372
- * @param name The name to use for the UUID
9373
- * @param namespace The namespace to use for the UUID
9374
- * @param encoding The encoding to use for the UUID
9790
+ * @param name The name to hash
9791
+ * @param namespace A namespace UUID, or one of the predefined namespaces `"dns"`, `"url"`, `"oid"`, or `"x500"`
9792
+ * @param encoding Pass `"buffer"` to get the UUID as bytes instead of a string
9375
9793
  *
9376
9794
  * @example
9377
9795
  * ```js
9378
9796
  * import { randomUUIDv5 } from "bun";
9379
9797
  * const uuid = randomUUIDv5("www.example.com", "url", "buffer");
9380
- * console.log(uuid); // <Buffer 6b a7 b8 11 9d ad 11 d1 80 b4 00 c0 4f d4 30 c8>
9798
+ * console.log(uuid); // <Buffer b6 3c df a4 3d f9 56 8e 97 ae 00 6c 5b 8f d6 52>
9381
9799
  * ```
9382
9800
  */
9383
9801
  function randomUUIDv5(
@@ -9387,10 +9805,10 @@ declare module "bun" {
9387
9805
  ): Buffer;
9388
9806
 
9389
9807
  /**
9390
- * Types for `bun.lock`
9808
+ * The structure of Bun's lockfile, `bun.lock`
9391
9809
  */
9392
9810
  type BunLockFile = {
9393
- lockfileVersion: 0 | 1;
9811
+ lockfileVersion: 0 | 1 | 2;
9394
9812
  workspaces: {
9395
9813
  [workspace: string]: BunLockFileWorkspacePackage;
9396
9814
  };
@@ -9409,7 +9827,7 @@ declare module "bun" {
9409
9827
  * `0` / `undefined` for projects created before v1.3.2, `1` for projects created after.
9410
9828
  *
9411
9829
  * ---
9412
- * Right now this only changes the default [install linker strategy](https://bun.com/docs/pm/cli/install#isolated-installs):
9830
+ * This only affects the default [install linker strategy](https://bun.com/docs/pm/cli/install#isolated-installs):
9413
9831
  * - With `0`, the linker is hoisted.
9414
9832
  * - With `1`, the linker is isolated for workspaces and hoisted for single-package projects.
9415
9833
  */
@@ -9429,7 +9847,7 @@ declare module "bun" {
9429
9847
  * git -> [ "name@git+repo", INFO, .bun-tag string (TODO: remove this) ]
9430
9848
  * github -> [ "name@github:user/repo", INFO, .bun-tag string (TODO: remove this) ]
9431
9849
  * ```
9432
- * */
9850
+ */
9433
9851
  packages: {
9434
9852
  [pkg: string]: BunLockFilePackageArray;
9435
9853
  };
@@ -9456,7 +9874,7 @@ declare module "bun" {
9456
9874
  bundled?: true;
9457
9875
  };
9458
9876
 
9459
- /** @see {@link BunLockFile.packages} for more info */
9877
+ /** @see {@link BunLockFile.packages} */
9460
9878
  type BunLockFilePackageArray =
9461
9879
  /** npm */
9462
9880
  | [pkg: string, registry: string, info: BunLockFilePackageInfo, integrity: string]
@@ -9498,7 +9916,7 @@ declare module "bun" {
9498
9916
  type CookieSameSite = "strict" | "lax" | "none";
9499
9917
 
9500
9918
  /**
9501
- * A class for working with a single cookie
9919
+ * A single HTTP cookie: its name, value, and attributes.
9502
9920
  *
9503
9921
  * @example
9504
9922
  * ```js
@@ -9508,7 +9926,7 @@ declare module "bun" {
9508
9926
  */
9509
9927
  class Cookie {
9510
9928
  /**
9511
- * Create a new cookie
9929
+ * Creates a cookie from a name, value, and optional attributes
9512
9930
  * @param name - The name of the cookie
9513
9931
  * @param value - The value of the cookie
9514
9932
  * @param options - Optional cookie attributes
@@ -9516,14 +9934,14 @@ declare module "bun" {
9516
9934
  constructor(name: string, value: string, options?: CookieInit);
9517
9935
 
9518
9936
  /**
9519
- * Create a new cookie from a cookie string
9520
- * @param cookieString - The cookie string
9937
+ * Creates a cookie by parsing a serialized cookie string
9938
+ * @param cookieString - A serialized cookie string, like `"name=value; Path=/"`
9521
9939
  */
9522
9940
  constructor(cookieString: string);
9523
9941
 
9524
9942
  /**
9525
- * Create a new cookie from a cookie object
9526
- * @param cookieObject - The cookie object
9943
+ * Creates a cookie from an attributes object
9944
+ * @param cookieObject - The cookie's name, value, and attributes
9527
9945
  */
9528
9946
  constructor(cookieObject?: CookieInit);
9529
9947
 
@@ -9538,52 +9956,52 @@ declare module "bun" {
9538
9956
  value: string;
9539
9957
 
9540
9958
  /**
9541
- * The domain of the cookie
9959
+ * The cookie's `Domain` attribute, or `undefined` if not set
9542
9960
  */
9543
9961
  domain?: string;
9544
9962
 
9545
9963
  /**
9546
- * The path of the cookie
9964
+ * The cookie's `Path` attribute. Defaults to `/`.
9547
9965
  */
9548
9966
  path: string;
9549
9967
 
9550
9968
  /**
9551
- * The expiration date of the cookie
9969
+ * The cookie's expiration date, or `undefined` if not set
9552
9970
  */
9553
9971
  expires?: Date;
9554
9972
 
9555
9973
  /**
9556
- * Whether the cookie is secure
9974
+ * Whether the cookie has the `Secure` attribute
9557
9975
  */
9558
9976
  secure: boolean;
9559
9977
 
9560
9978
  /**
9561
- * The same-site attribute of the cookie
9979
+ * The cookie's `SameSite` attribute. Defaults to `lax`.
9562
9980
  */
9563
9981
  sameSite: CookieSameSite;
9564
9982
 
9565
9983
  /**
9566
- * Whether the cookie is partitioned
9984
+ * Whether the cookie has the `Partitioned` attribute
9567
9985
  */
9568
9986
  partitioned: boolean;
9569
9987
 
9570
9988
  /**
9571
- * The maximum age of the cookie in seconds
9989
+ * The cookie's maximum age in seconds, or `undefined` if not set
9572
9990
  */
9573
9991
  maxAge?: number;
9574
9992
 
9575
9993
  /**
9576
- * Whether the cookie is HTTP-only
9994
+ * Whether the cookie has the `HttpOnly` attribute
9577
9995
  */
9578
9996
  httpOnly: boolean;
9579
9997
 
9580
9998
  /**
9581
- * Whether the cookie is expired
9999
+ * Returns `true` if the cookie has expired
9582
10000
  */
9583
10001
  isExpired(): boolean;
9584
10002
 
9585
10003
  /**
9586
- * Serialize the cookie to a string
10004
+ * Serializes the cookie to a string
9587
10005
  *
9588
10006
  * @example
9589
10007
  * ```ts
@@ -9598,33 +10016,31 @@ declare module "bun" {
9598
10016
  serialize(): string;
9599
10017
 
9600
10018
  /**
9601
- * Serialize the cookie to a string
9602
- *
9603
- * Alias of {@link Cookie.serialize}
10019
+ * Serializes the cookie to a string. Alias of {@link Cookie.serialize}.
9604
10020
  */
9605
10021
  toString(): string;
9606
10022
 
9607
10023
  /**
9608
- * Serialize the cookie to a JSON object
10024
+ * Returns the cookie's name, value, and attributes as a plain object
9609
10025
  */
9610
10026
  toJSON(): CookieInit;
9611
10027
 
9612
10028
  /**
9613
- * Parse a cookie string into a Cookie object
9614
- * @param cookieString - The cookie string
10029
+ * Parses a serialized cookie string into a `Cookie`
10030
+ * @param cookieString - A serialized cookie string, like `"name=value; Path=/"`
9615
10031
  */
9616
10032
  static parse(cookieString: string): Cookie;
9617
10033
 
9618
10034
  /**
9619
- * Create a new cookie from a name and value and optional options
10035
+ * Creates a cookie from a name, value, and optional attributes
9620
10036
  */
9621
10037
  static from(name: string, value: string, options?: CookieInit): Cookie;
9622
10038
  }
9623
10039
 
9624
10040
  /**
9625
- * A Map-like interface for working with collections of cookies.
10041
+ * A Map-like collection of cookies.
9626
10042
  *
9627
- * Implements the `Iterable` interface, allowing use with `for...of` loops.
10043
+ * Iterable, so it works with `for...of` loops.
9628
10044
  */
9629
10045
  class CookieMap implements Iterable<[string, string]> {
9630
10046
  /**
@@ -9646,9 +10062,9 @@ declare module "bun" {
9646
10062
  get(name: string): string | null;
9647
10063
 
9648
10064
  /**
9649
- * Gets an array of values for Set-Cookie headers in order to apply all changes to cookies.
10065
+ * Returns the `Set-Cookie` header values that apply the changes made to this map.
9650
10066
  *
9651
- * @returns An array of values for Set-Cookie headers
10067
+ * @returns An array of `Set-Cookie` header values
9652
10068
  */
9653
10069
  toSetCookieHeaders(): string[];
9654
10070
 
@@ -9701,7 +10117,7 @@ declare module "bun" {
9701
10117
  /**
9702
10118
  * Converts the cookie map to a serializable format.
9703
10119
  *
9704
- * @returns An array of name/value pairs
10120
+ * @returns An object mapping cookie names to values
9705
10121
  */
9706
10122
  toJSON(): Record<string, string>;
9707
10123