forked from oven-sh/bun-types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.d.ts
1990 lines (1836 loc) · 59.3 KB
/
globals.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
type BinaryType = "arraybuffer" | "blob";
type Transferable = ArrayBuffer;
type MessageEventSource = undefined;
type Encoding = "utf-8" | "windows-1252" | "utf-16";
type Platform =
| "aix"
| "android"
| "darwin"
| "freebsd"
| "haiku"
| "linux"
| "openbsd"
| "sunos"
| "win32"
| "cygwin"
| "netbsd";
type Architecture =
| "arm"
| "arm64"
| "ia32"
| "mips"
| "mipsel"
| "ppc"
| "ppc64"
| "s390"
| "s390x"
| "x64";
type Signals =
| "SIGABRT"
| "SIGALRM"
| "SIGBUS"
| "SIGCHLD"
| "SIGCONT"
| "SIGFPE"
| "SIGHUP"
| "SIGILL"
| "SIGINT"
| "SIGIO"
| "SIGIOT"
| "SIGKILL"
| "SIGPIPE"
| "SIGPOLL"
| "SIGPROF"
| "SIGPWR"
| "SIGQUIT"
| "SIGSEGV"
| "SIGSTKFLT"
| "SIGSTOP"
| "SIGSYS"
| "SIGTERM"
| "SIGTRAP"
| "SIGTSTP"
| "SIGTTIN"
| "SIGTTOU"
| "SIGUNUSED"
| "SIGURG"
| "SIGUSR1"
| "SIGUSR2"
| "SIGVTALRM"
| "SIGWINCH"
| "SIGXCPU"
| "SIGXFSZ"
| "SIGBREAK"
| "SIGLOST"
| "SIGINFO";
interface console {
assert(condition?: boolean, ...data: any[]): void;
clear(): void;
/**
* Increment a [count](https://www.youtube.com/watch?v=2AoxCkySv34&t=22s)
* @param label label counter
*/
count(label?: string): void;
countReset(label?: string): void;
debug(...data: any[]): void;
dir(item?: any, options?: any): void;
dirxml(...data: any[]): void;
/**
* Log to stderr in your terminal
*
* Appears in red
*
* @param data something to display
*/
error(...data: any[]): void;
/** Does nothing currently */
group(...data: any[]): void;
/** Does nothing currently */
groupCollapsed(...data: any[]): void;
/** Does nothing currently */
groupEnd(): void;
info(...data: any[]): void;
log(...data: any[]): void;
/** Does nothing currently */
table(tabularData?: any, properties?: string[]): void;
/**
* Begin a timer to log with {@link console.timeEnd}
*
* @param label - The label to use for the timer
*
* ```ts
* console.time("how long????");
* for (let i = 0; i < 999999; i++) {
* // do stuff
* let x = i * i;
* }
* console.timeEnd("how long????");
* ```
*/
time(label?: string): void;
/**
* End a timer to log with {@link console.time}
*
* @param label - The label to use for the timer
*
* ```ts
* console.time("how long????");
* for (let i = 0; i < 999999; i++) {
* // do stuff
* let x = i * i;
* }
* console.timeEnd("how long????");
* ```
*/
timeEnd(label?: string): void;
timeLog(label?: string, ...data: any[]): void;
timeStamp(label?: string): void;
trace(...data: any[]): void;
warn(...data: any[]): void;
}
declare var console: console;
interface ImportMeta {
/**
* `file://` url string for the current module.
*
* @example
* ```ts
* console.log(import.meta.url);
* "file:///Users/me/projects/my-app/src/my-app.ts"
* ```
*/
url: string;
/**
* Absolute path to the source file
*/
path: string;
/**
* Absolute path to the directory containing the source file.
*
* Does not have a trailing slash
*/
dir: string;
/**
* Filename of the source file
*/
file: string;
/**
* Resolve a module ID the same as if you imported it
*
* On failure, throws a `ResolveError`
*/
resolve(moduleId: string): Promise<string>;
/**
* Resolve a `moduleId` as though it were imported from `parent`
*
* On failure, throws a `ResolveError`
*/
// tslint:disable-next-line:unified-signatures
resolve(moduleId: string, parent: string): Promise<string>;
}
/** @deprecated Please use `import.meta.path` instead. */
declare var __filename: string;
/** @deprecated Please use `import.meta.dir` instead. */
declare var __dirname: string;
interface StructuredSerializeOptions {
transfer?: Transferable[];
}
interface EncodeIntoResult {
/**
* The read Unicode code units of input.
*/
read: number;
/**
* The written UTF-8 bytes of output.
*/
written: number;
}
interface Process {
/**
* The current version of Bun
*/
version: string;
/**
* Run a function on the next tick of the event loop
*
* This is the same as {@link queueMicrotask}
*
* @param callback - The function to run
*/
nextTick(callback: (...args: any) => any, ...args: any): void;
versions: Record<string, string>;
ppid: number;
pid: number;
arch: Architecture;
platform: Platform;
argv: string[];
// execArgv: string[];
env: Record<string, string> & {
NODE_ENV: string;
};
/** Whether you are using Bun */
isBun: 1; // FIXME: this should actually return a boolean
// execPath: string;
// abort(): void;
chdir(directory: string): void;
cwd(): string;
exit(code?: number): void;
getgid(): number;
setgid(id: number | string): void;
getuid(): number;
setuid(id: number | string): void;
}
declare var process: Process;
declare module "process" {
var process: Process;
export = process;
}
declare module "node:process" {
import process = require("process");
export = process;
}
interface BlobInterface {
text(): Promise<string>;
arrayBuffer(): Promise<ArrayBuffer>;
json<TJSONReturnType = unknown>(): Promise<TJSONReturnType>;
}
type BlobPart = string | Blob | ArrayBufferView | ArrayBuffer;
interface BlobPropertyBag {
/** Set a default "type" */
type?: string;
/** Not implemented in Bun yet. */
endings?: "transparent" | "native";
}
/**
* This Fetch API interface allows you to perform various actions on HTTP
* request and response headers. These actions include retrieving, setting,
* adding to, and removing. A Headers object has an associated header list,
* which is initially empty and consists of zero or more name and value
* pairs.
*
* You can add to this using methods like append()
*
* In all methods of this interface, header names are matched by
* case-insensitive byte sequence.
*/
interface Headers {
append(name: string, value: string): void;
delete(name: string): void;
get(name: string): string | null;
has(name: string): boolean;
set(name: string, value: string): void;
entries(): IterableIterator<[string, string]>;
keys(): IterableIterator<string>;
values(): IterableIterator<string>;
forEach(
callbackfn: (value: string, key: string, parent: Headers) => void,
thisArg?: any
): void;
}
declare var Headers: {
prototype: Headers;
new (init?: HeadersInit): Headers;
};
type HeadersInit = Array<[string, string]> | Record<string, string> | Headers;
type ResponseType =
| "basic"
| "cors"
| "default"
| "error"
| "opaque"
| "opaqueredirect";
declare class Blob implements BlobInterface {
/**
* Create a new [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
*
* @param `parts` - An array of strings, numbers, TypedArray, or [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects
* @param `options` - An object containing properties to be added to the [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
*/
constructor(parts?: BlobPart[] | Blob, options?: BlobPropertyBag);
/**
* Create a new view **without 🚫 copying** the underlying data.
*
* Similar to [`TypedArray.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray)
*
* @param begin The index that sets the beginning of the view.
* @param end The index that sets the end of the view.
*
*/
slice(begin?: number, end?: number): Blob;
/**
* Read the data from the blob as a string. It will be decoded from UTF-8.
*/
text(): Promise<string>;
/**
* Read the data from the blob as a ReadableStream.
*/
stream(): ReadableStream<Uint8Array>;
/**
* Read the data from the blob as an ArrayBuffer.
*
* This copies the data into a new ArrayBuffer.
*/
arrayBuffer(): Promise<ArrayBuffer>;
/**
* Read the data from the blob as a JSON object.
*
* This first decodes the data from UTF-8, then parses it as JSON.
*
*/
json<TJSONReturnType = unknown>(): Promise<TJSONReturnType>;
type: string;
size: number;
}
interface ResponseInit {
headers?: HeadersInit;
/** @default 200 */
status?: number;
/** @default "OK" */
statusText?: string;
}
/**
* Represents an HTTP [Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)
*
* Use it to get the body of the response, the status code, and other information.
*
* @example
* ```ts
* const response: Response = await fetch("https://remix.run");
* await response.text();
* ```
* @example
* ```ts
* const response: Response = await fetch("https://remix.run");
* await Bun.write("remix.html", response);
* ```
*/
declare class Response implements BlobInterface {
constructor(body: BlobPart | BlobPart[], options?: ResponseInit);
/**
* Create a new {@link Response} with a JSON body
*
* @param body - The body of the response
* @param options - options to pass to the response
*
* @example
*
* ```ts
* const response = Response.json({hi: "there"});
* console.assert(
* await response.text(),
* `{"hi":"there"}`
* );
* ```
* -------
*
* This is syntactic sugar for:
* ```js
* new Response(JSON.stringify(body), {headers: { "Content-Type": "application/json" }})
* ```
* @link https://github.com/whatwg/fetch/issues/1389
*/
static json(body?: any, options?: ResponseInit | number): Response;
/**
* Create a new {@link Response} that redirects to url
*
* @param url - the URL to redirect to
* @param status - the HTTP status code to use for the redirect
*/
// tslint:disable-next-line:unified-signatures
static redirect(url: string, status?: number): Response;
/**
* Create a new {@link Response} that redirects to url
*
* @param url - the URL to redirect to
* @param options - options to pass to the response
*/
// tslint:disable-next-line:unified-signatures
static redirect(url: string, options?: ResponseInit): Response;
/**
* Create a new {@link Response} that has a network error
*/
static error(): Response;
/**
* HTTP [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers) sent with the response.
*
* @example
* ```ts
* const {headers} = await fetch("https://remix.run");
* headers.get("Content-Type");
* headers.get("Content-Length");
* headers.get("Set-Cookie");
* ```
*/
readonly headers: Headers;
/**
* Has the body of the response already been consumed?
*/
readonly bodyUsed: boolean;
/**
* Read the data from the Response as a string. It will be decoded from UTF-8.
*
* When the body is valid latin1, this operation is zero copy.
*/
text(): Promise<string>;
/**
* Read the data from the Response as a string. It will be decoded from UTF-8.
*
* When the body is valid latin1, this operation is zero copy.
*/
arrayBuffer(): Promise<ArrayBuffer>;
/**
* Read the data from the Response as a JSON object.
*
* This first decodes the data from UTF-8, then parses it as JSON.
*
*/
json<TJSONReturnType = unknown>(): Promise<TJSONReturnType>;
/**
* Read the data from the Response as a Blob.
*
* This allows you to reuse the underlying data.
*
* @returns Promise<Blob> - The body of the response as a {@link Blob}.
*/
blob(): Promise<Blob>;
readonly ok: boolean;
readonly redirected: boolean;
/**
* HTTP status code
*
* @example
* 200
*
* 0 for network errors
*/
readonly status: number;
readonly statusText: string;
readonly type: ResponseType;
/** HTTP url as a string */
readonly url: string;
/** Copy the Response object into a new Response, including the body */
clone(): Response;
}
type RequestCache =
| "default"
| "force-cache"
| "no-cache"
| "no-store"
| "only-if-cached"
| "reload";
type RequestCredentials = "include" | "omit" | "same-origin";
type RequestDestination =
| ""
| "audio"
| "audioworklet"
| "document"
| "embed"
| "font"
| "frame"
| "iframe"
| "image"
| "manifest"
| "object"
| "paintworklet"
| "report"
| "script"
| "sharedworker"
| "style"
| "track"
| "video"
| "worker"
| "xslt";
type RequestMode = "cors" | "navigate" | "no-cors" | "same-origin";
type RequestRedirect = "error" | "follow" | "manual";
type ReferrerPolicy =
| ""
| "no-referrer"
| "no-referrer-when-downgrade"
| "origin"
| "origin-when-cross-origin"
| "same-origin"
| "strict-origin"
| "strict-origin-when-cross-origin"
| "unsafe-url";
type RequestInfo = Request | string;
type BodyInit = ReadableStream | XMLHttpRequestBodyInit;
type XMLHttpRequestBodyInit = Blob | BufferSource | string;
type ReadableStreamController<T> = ReadableStreamDefaultController<T>;
type ReadableStreamDefaultReadResult<T> =
| ReadableStreamDefaultReadValueResult<T>
| ReadableStreamDefaultReadDoneResult;
type ReadableStreamReader<T> = ReadableStreamDefaultReader<T>;
interface RequestInit {
/**
* A BodyInit object or null to set request's body.
*/
body?: BodyInit | null;
/**
* A string indicating how the request will interact with the browser's cache to set request's cache.
*
* Note: as of Bun v0.0.74, this is not implemented yet.
*/
cache?: RequestCache;
/**
* A string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL. Sets request's credentials.
*/
credentials?: RequestCredentials;
/**
* A Headers object, an object literal, or an array of two-item arrays to set request's headers.
*/
headers?: HeadersInit;
/**
* A cryptographic hash of the resource to be fetched by request. Sets request's integrity.
*
* Note: as of Bun v0.0.74, this is not implemented yet.
*/
integrity?: string;
/**
* A boolean to set request's keepalive.
*
* Note: as of Bun v0.0.74, this is not implemented yet.
*/
keepalive?: boolean;
/**
* A string to set request's method.
*/
method?: string;
/**
* A string to indicate whether the request will use CORS, or will be restricted to same-origin URLs. Sets request's mode.
*/
mode?: RequestMode;
/**
* A string indicating whether request follows redirects, results in an error upon encountering a redirect, or returns the redirect (in an opaque fashion). Sets request's redirect.
*/
redirect?: RequestRedirect;
/**
* A string whose value is a same-origin URL, "about:client", or the empty string, to set request's referrer.
*/
referrer?: string;
/**
* A referrer policy to set request's referrerPolicy.
*/
referrerPolicy?: ReferrerPolicy;
/**
* An AbortSignal to set request's signal.
*
* Note: as of Bun v0.0.74, this is not implemented yet.
*/
signal?: AbortSignal | null;
/**
* Can only be null. Used to disassociate request from any Window.
*
* This does nothing in Bun
*/
window?: any;
}
/**
* [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) represents an HTTP request.
*
* @example
* ```ts
* const request = new Request("https://remix.run/");
* await fetch(request);
* ```
*
* @example
* ```ts
* const request = new Request("https://remix.run/");
* await fetch(request);
* ```
*/
declare class Request implements BlobInterface {
constructor(requestInfo: RequestInfo, requestInit?: RequestInit);
/**
* Read or write the HTTP headers for this request.
*
* @example
* ```ts
* const request = new Request("https://remix.run/");
* request.headers.set("Content-Type", "application/json");
* request.headers.set("Accept", "application/json");
* await fetch(request);
* ```
*/
headers: Headers;
/**
* The URL (as a string) corresponding to the HTTP request
* @example
* ```ts
* const request = new Request("https://remix.run/");
* request.url; // "https://remix.run/"
* ```
*/
readonly url: string;
/**
* Consume the [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) body as a string. It will be decoded from UTF-8.
*
* When the body is valid latin1, this operation is zero copy.
*/
text(): Promise<string>;
/**
* Consume the [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) body as an ArrayBuffer.
*
*/
arrayBuffer(): Promise<ArrayBuffer>;
/**
* Consume the [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) body as a JSON object.
*
* This first decodes the data from UTF-8, then parses it as JSON.
*
*/
json<TJSONReturnType = unknown>(): Promise<TJSONReturnType>;
/**
* Consume the [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) body as a `Blob`.
*
* This allows you to reuse the underlying data.
*
*/
blob(): Promise<Blob>;
/**
* Returns the cache mode associated with request, which is a string indicating how the request will interact with the browser's cache when fetching.
*/
readonly cache: RequestCache;
/**
* Returns the credentials mode associated with request, which is a string indicating whether credentials will be sent with the request always, never, or only when sent to a same-origin URL.
*/
readonly credentials: RequestCredentials;
/**
* Returns the kind of resource requested by request, e.g., "document" or "script".
*
* In Bun, this always returns "navigate".
*/
readonly destination: RequestDestination;
/**
* Returns request's subresource integrity metadata, which is a cryptographic hash of the resource being fetched. Its value consists of multiple hashes separated by whitespace. [SRI]
*
* This does nothing in Bun right now.
*/
readonly integrity: string;
/**
* Returns a boolean indicating whether or not request can outlive the global in which it was created.
*
* In Bun, this always returns false.
*/
readonly keepalive: boolean;
/**
* Returns request's HTTP method, which is "GET" by default.
*/
readonly method: string;
/**
* Returns the mode associated with request, which is a string indicating whether the request will use CORS, or will be restricted to same-origin URLs.
*/
readonly mode: RequestMode;
/**
* Returns the redirect mode associated with request, which is a string indicating how redirects for the request will be handled during fetching. A request will follow redirects by default.
*/
readonly redirect: RequestRedirect;
/**
* Returns the referrer of request. Its value can be a same-origin URL
* if explicitly set in init, the empty string to indicate no referrer,
* and "about:client" when defaulting to the global's default. This is
* used during fetching to determine the value of the `Referer` header
* of the request being made.
*/
readonly referrer: string;
/**
* Returns the referrer policy associated with request. This is used during fetching to compute the value of the request's referrer.
*/
readonly referrerPolicy: ReferrerPolicy;
/**
* Returns the signal associated with request, which is an AbortSignal object indicating whether or not request has been aborted, and its abort event handler.
*
* Note: this is **not implemented yet**. The cake is a lie.
*/
readonly signal: AbortSignal;
/** Copy the Request object into a new Request, including the body */
clone(): Request;
}
interface Crypto {
getRandomValues<T extends TypedArray = TypedArray>(array: T): T;
/**
* Generate a cryptographically secure random UUID.
*
* @example
*
* ```js
* crypto.randomUUID()
* '5e6adf82-f516-4468-b1e1-33d6f664d7dc'
* ```
*/
randomUUID(): string;
}
declare var crypto: Crypto;
/**
* [`atob`](https://developer.mozilla.org/en-US/docs/Web/API/atob) decodes base64 into ascii text.
*
* @param asciiText The base64 string to decode.
*/
declare function atob(encodedData: string): string;
/**
* [`btoa`](https://developer.mozilla.org/en-US/docs/Web/API/btoa) encodes ascii text into base64.
*
* @param stringToEncode The ascii text to encode.
*/
declare function btoa(stringToEncode: string): string;
/**
* An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextEncoder` API. All
* instances of `TextEncoder` only support UTF-8 encoding.
*
* ```js
* const encoder = new TextEncoder();
* const uint8array = encoder.encode('this is some data');
* ```
*
*/
declare class TextEncoder {
/**
* The encoding supported by the `TextEncoder` instance. Always set to `'utf-8'`.
*/
readonly encoding: "utf-8";
constructor(encoding?: "utf-8");
/**
* UTF-8 encodes the `input` string and returns a `Uint8Array` containing the
* encoded bytes.
* @param [input='an empty string'] The text to encode.
*/
encode(input?: string): Uint8Array;
/**
* UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object
* containing the read Unicode code units and written UTF-8 bytes.
*
* ```js
* const encoder = new TextEncoder();
* const src = 'this is some data';
* const dest = new Uint8Array(10);
* const { read, written } = encoder.encodeInto(src, dest);
* ```
* @param src The text to encode.
* @param dest The array to hold the encode result.
*/
encodeInto(src?: string, dest?: TypedArray): EncodeIntoResult;
}
/**
* An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextDecoder` API.
*
* ```js
* const decoder = new TextDecoder();
* const u8arr = new Uint8Array([72, 101, 108, 108, 111]);
* console.log(decoder.decode(u8arr)); // Hello
* ```
*/
declare class TextDecoder {
/**
* The encoding supported by the `TextDecoder` instance.
*/
readonly encoding: string;
/**
* The value will be `true` if decoding errors result in a `TypeError` being
* thrown.
*/
readonly fatal: boolean;
/**
* The value will be `true` if the decoding result will include the byte order
* mark.
*/
readonly ignoreBOM: boolean;
constructor(
encoding?: Encoding,
options?: { fatal?: boolean; ignoreBOM?: boolean }
);
/**
* Decodes the `input` and returns a string. If `options.stream` is `true`, any
* incomplete byte sequences occurring at the end of the `input` are buffered
* internally and emitted after the next call to `textDecoder.decode()`.
*
* If `textDecoder.fatal` is `true`, decoding errors that occur will result in a`TypeError` being thrown.
* @param input An `ArrayBuffer`, `DataView` or `TypedArray` instance containing the encoded data.
*/
decode(input?: TypedArray | ArrayBuffer): string;
}
/**
* ShadowRealms are a distinct global environment, with its own global object
* containing its own intrinsics and built-ins (standard objects that are not
* bound to global variables, like the initial value of Object.prototype).
*
*
* @example
*
* ```js
* const red = new ShadowRealm();
*
* // realms can import modules that will execute within it's own environment.
* // When the module is resolved, it captured the binding value, or creates a new
* // wrapped function that is connected to the callable binding.
* const redAdd = await red.importValue('./inside-code.js', 'add');
*
* // redAdd is a wrapped function exotic object that chains it's call to the
* // respective imported binding.
* let result = redAdd(2, 3);
*
* console.assert(result === 5); // yields true
*
* // The evaluate method can provide quick code evaluation within the constructed
* // shadowRealm without requiring any module loading, while it still requires CSP
* // relaxing.
* globalThis.someValue = 1;
* red.evaluate('globalThis.someValue = 2'); // Affects only the ShadowRealm's global
* console.assert(globalThis.someValue === 1);
*
* // The wrapped functions can also wrap other functions the other way around.
* const setUniqueValue =
* await red.importValue('./inside-code.js', 'setUniqueValue');
*
* // setUniqueValue = (cb) => (cb(globalThis.someValue) * 2);
*
* result = setUniqueValue((x) => x ** 3);
*
* console.assert(result === 16); // yields true
* ```
*/
declare class ShadowRealm {
/**
* Creates a new [ShadowRealm](https://github.com/tc39/proposal-shadowrealm/blob/main/explainer.md#introduction)
*
* @example
*
* ```js
* const red = new ShadowRealm();
*
* // realms can import modules that will execute within it's own environment.
* // When the module is resolved, it captured the binding value, or creates a new
* // wrapped function that is connected to the callable binding.
* const redAdd = await red.importValue('./inside-code.js', 'add');
*
* // redAdd is a wrapped function exotic object that chains it's call to the
* // respective imported binding.
* let result = redAdd(2, 3);
*
* console.assert(result === 5); // yields true
*
* // The evaluate method can provide quick code evaluation within the constructed
* // shadowRealm without requiring any module loading, while it still requires CSP
* // relaxing.
* globalThis.someValue = 1;
* red.evaluate('globalThis.someValue = 2'); // Affects only the ShadowRealm's global
* console.assert(globalThis.someValue === 1);
*
* // The wrapped functions can also wrap other functions the other way around.
* const setUniqueValue =
* await red.importValue('./inside-code.js', 'setUniqueValue');
*
* // setUniqueValue = (cb) => (cb(globalThis.someValue) * 2);
*
* result = setUniqueValue((x) => x ** 3);
*
* console.assert(result === 16); // yields true
* ```
*/
constructor();
importValue(specifier: string, bindingName: string): Promise<any>;
evaluate(sourceText: string): any;
}
interface Blob {
/**
* Read the contents of the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) as a JSON object
* @warn in browsers, this function is only available for `Response` and `Request`
*/
json(): Promise<any>;
/**
* Read the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) as a UTF-8 string
* @link https://developer.mozilla.org/en-US/docs/Web/API/Blob/text
*/
text(): Promise<string>;
/**
* Read the [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) as an ArrayBuffer object
* @link https://developer.mozilla.org/en-US/docs/Web/API/Blob/arrayBuffer
*/
arrayBuffer(): Promise<ArrayBuffer>;
}
declare var performance: {
/**
* Seconds since Bun.js started
*
* Uses a high-precision system timer to measure the time elapsed since the
* Bun.js runtime was initialized. The value is represented as a double
* precision floating point number. The value is monotonically increasing
* during the lifetime of the runtime.
*
*/
now: () => number;
};
/**
* Cancel a repeating timer by its timer ID.
* @param id timer id
*/
declare function clearInterval(id?: number): void;
/**
* Cancel a delayed function call by its timer ID.
* @param id timer id
*/
declare function clearTimeout(id?: number): void;
// declare function createImageBitmap(image: ImageBitmapSource, options?: ImageBitmapOptions): Promise<ImageBitmap>;
// declare function createImageBitmap(image: ImageBitmapSource, sx: number, sy: number, sw: number, sh: number, options?: ImageBitmapOptions): Promise<ImageBitmap>;
/**
* Send a HTTP(s) request
*
* @param url URL string
* @param init A structured value that contains settings for the fetch() request.
*
* @returns A promise that resolves to {@link Response} object.
*
*
*/
declare function fetch(url: string, init?: RequestInit): Promise<Response>;
/**
* Send a HTTP(s) request
*
* @param request Request object
* @param init A structured value that contains settings for the fetch() request.
*
* @returns A promise that resolves to {@link Response} object.
*
*
*/
// tslint:disable-next-line:unified-signatures
declare function fetch(request: Request, init?: RequestInit): Promise<Response>;