aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Colin McDonnell <colinmcd94@gmail.com> 2023-02-06 12:57:19 -0800
committerGravatar GitHub <noreply@github.com> 2023-02-06 12:57:19 -0800
commite7f9ce47f47bee562165bbf8a31c75d00306b0ad (patch)
tree490d33ea4f8cf35b046049577320beeadd9e4eee
parent98022bec1ef9d6365c49d21f2c775d5b07ac9c32 (diff)
downloadbun-e7f9ce47f47bee562165bbf8a31c75d00306b0ad.tar.gz
bun-e7f9ce47f47bee562165bbf8a31c75d00306b0ad.tar.zst
bun-e7f9ce47f47bee562165bbf8a31c75d00306b0ad.zip
Add types for node:console and node:perf_hooks (#1982)
* Add types for node:console and node:perf_hooks * Add types for util/types --------- Co-authored-by: Colin McDonnell <colinmcd@alum.mit.edu>
-rw-r--r--packages/bun-types/console.d.ts148
-rw-r--r--packages/bun-types/index.d.ts2
-rw-r--r--packages/bun-types/perf_hooks.d.ts625
-rw-r--r--packages/bun-types/tests/console.test-d.ts14
-rw-r--r--packages/bun-types/tests/perf_hooks.test-d.ts4
-rw-r--r--packages/bun-types/tests/util.test-d.ts7
-rw-r--r--packages/bun-types/util.d.ts690
-rw-r--r--tsconfig.json5
8 files changed, 1342 insertions, 153 deletions
diff --git a/packages/bun-types/console.d.ts b/packages/bun-types/console.d.ts
new file mode 100644
index 000000000..08ca64c77
--- /dev/null
+++ b/packages/bun-types/console.d.ts
@@ -0,0 +1,148 @@
+/**
+ * The `console` module provides a simple debugging console that is similar to the
+ * JavaScript console mechanism provided by web browsers.
+ *
+ * The module exports two specific components:
+ *
+ * * A `Console` class with methods such as `console.log()`, `console.error()` and`console.warn()` that can be used to write to any Node.js stream.
+ * * A global `console` instance configured to write to `process.stdout` and `process.stderr`. The global `console` can be used without calling`require('console')`.
+ *
+ * _**Warning**_: The global console object's methods are neither consistently
+ * synchronous like the browser APIs they resemble, nor are they consistently
+ * asynchronous like all other Node.js streams. See the `note on process I/O` for
+ * more information.
+ *
+ * Example using the global `console`:
+ *
+ * ```js
+ * console.log('hello world');
+ * // Prints: hello world, to stdout
+ * console.log('hello %s', 'world');
+ * // Prints: hello world, to stdout
+ * console.error(new Error('Whoops, something bad happened'));
+ * // Prints error message and stack trace to stderr:
+ * // Error: Whoops, something bad happened
+ * // at [eval]:5:15
+ * // at Script.runInThisContext (node:vm:132:18)
+ * // at Object.runInThisContext (node:vm:309:38)
+ * // at node:internal/process/execution:77:19
+ * // at [eval]-wrapper:6:22
+ * // at evalScript (node:internal/process/execution:76:60)
+ * // at node:internal/main/eval_string:23:3
+ *
+ * const name = 'Will Robinson';
+ * console.warn(`Danger ${name}! Danger!`);
+ * // Prints: Danger Will Robinson! Danger!, to stderr
+ * ```
+ *
+ * Example using the `Console` class:
+ *
+ * ```js
+ * const out = getStreamSomehow();
+ * const err = getStreamSomehow();
+ * const myConsole = new console.Console(out, err);
+ *
+ * myConsole.log('hello world');
+ * // Prints: hello world, to out
+ * myConsole.log('hello %s', 'world');
+ * // Prints: hello world, to out
+ * myConsole.error(new Error('Whoops, something bad happened'));
+ * // Prints: [Error: Whoops, something bad happened], to err
+ *
+ * const name = 'Will Robinson';
+ * myConsole.warn(`Danger ${name}! Danger!`);
+ * // Prints: Danger Will Robinson! Danger!, to err
+ * ```
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/console.js)
+ */
+declare module "console" {
+ import console = require("node:console");
+ export = console;
+}
+declare module "node:console" {
+ // import { InspectOptions } from "node:util";
+ // global {
+
+ /**
+ * The `console` module provides a simple debugging console that is similar to the
+ * JavaScript console mechanism provided by web browsers.
+ *
+ * The module exports two specific components:
+ *
+ * * A `Console` class with methods such as `console.log()`, `console.error()` and`console.warn()` that can be used to write to any Node.js stream.
+ * * A global `console` instance configured to write to `process.stdout` and `process.stderr`. The global `console` can be used without calling`require('console')`.
+ *
+ * _**Warning**_: The global console object's methods are neither consistently
+ * synchronous like the browser APIs they resemble, nor are they consistently
+ * asynchronous like all other Node.js streams. See the `note on process I/O` for
+ * more information.
+ *
+ * Example using the global `console`:
+ *
+ * ```js
+ * console.log('hello world');
+ * // Prints: hello world, to stdout
+ * console.log('hello %s', 'world');
+ * // Prints: hello world, to stdout
+ * console.error(new Error('Whoops, something bad happened'));
+ * // Prints error message and stack trace to stderr:
+ * // Error: Whoops, something bad happened
+ * // at [eval]:5:15
+ * // at Script.runInThisContext (node:vm:132:18)
+ * // at Object.runInThisContext (node:vm:309:38)
+ * // at node:internal/process/execution:77:19
+ * // at [eval]-wrapper:6:22
+ * // at evalScript (node:internal/process/execution:76:60)
+ * // at node:internal/main/eval_string:23:3
+ *
+ * const name = 'Will Robinson';
+ * console.warn(`Danger ${name}! Danger!`);
+ * // Prints: Danger Will Robinson! Danger!, to stderr
+ * ```
+ *
+ * Example using the `Console` class:
+ *
+ * ```js
+ * const out = getStreamSomehow();
+ * const err = getStreamSomehow();
+ * const myConsole = new console.Console(out, err);
+ *
+ * myConsole.log('hello world');
+ * // Prints: hello world, to out
+ * myConsole.log('hello %s', 'world');
+ * // Prints: hello world, to out
+ * myConsole.error(new Error('Whoops, something bad happened'));
+ * // Prints: [Error: Whoops, something bad happened], to err
+ *
+ * const name = 'Will Robinson';
+ * myConsole.warn(`Danger ${name}! Danger!`);
+ * // Prints: Danger Will Robinson! Danger!, to err
+ * ```
+ * @see [source](https://github.com/nodejs/node/blob/v16.4.2/lib/console.js)
+ */
+ // import {Writable} from "node:stream";
+ // namespace console {
+ // interface ConsoleConstructorOptions {
+ // stdout: Writable;
+ // stderr?: Writable | undefined;
+ // ignoreErrors?: boolean | undefined;
+ // colorMode?: boolean | "auto" | undefined;
+ // inspectOptions?: InspectOptions | undefined;
+ // /**
+ // * Set group indentation
+ // * @default 2
+ // */
+ // groupIndentation?: number | undefined;
+ // }
+ // interface ConsoleConstructor {
+ // prototype: Console;
+ // new (stdout: Writable, stderr?: Writable, ignoreErrors?: boolean): Console;
+ // new (options: ConsoleConstructorOptions): Console;
+ // }
+ // }
+
+ // }
+ // const console: Console;
+
+ export = console;
+}
diff --git a/packages/bun-types/index.d.ts b/packages/bun-types/index.d.ts
index c13e64289..981a4dbc7 100644
--- a/packages/bun-types/index.d.ts
+++ b/packages/bun-types/index.d.ts
@@ -10,6 +10,7 @@
/// <reference path="./bun-test.d.ts" />
/// <reference path="./bun.d.ts" />
/// <reference path="./child_process.d.ts" />
+/// <reference path="./console.d.ts" />
/// <reference path="./constants.d.ts" />
/// <reference path="./crypto.d.ts" />
/// <reference path="./dns.d.ts" />
@@ -27,6 +28,7 @@
/// <reference path="./net.d.ts" />
/// <reference path="./os.d.ts" />
/// <reference path="./path.d.ts" />
+/// <reference path="./perf_hooks.d.ts" />
/// <reference path="./punycode.d.ts" />
/// <reference path="./querystring.d.ts" />
/// <reference path="./readline.d.ts" />
diff --git a/packages/bun-types/perf_hooks.d.ts b/packages/bun-types/perf_hooks.d.ts
new file mode 100644
index 000000000..802b0e082
--- /dev/null
+++ b/packages/bun-types/perf_hooks.d.ts
@@ -0,0 +1,625 @@
+/**
+ * This module provides an implementation of a subset of the W3C [Web Performance APIs](https://w3c.github.io/perf-timing-primer/) as well as additional APIs for
+ * Node.js-specific performance measurements.
+ *
+ * Node.js supports the following [Web Performance APIs](https://w3c.github.io/perf-timing-primer/):
+ *
+ * * [High Resolution Time](https://www.w3.org/TR/hr-time-2)
+ * * [Performance Timeline](https://w3c.github.io/performance-timeline/)
+ * * [User Timing](https://www.w3.org/TR/user-timing/)
+ *
+ * ```js
+ * const { PerformanceObserver, performance } = require('perf_hooks');
+ *
+ * const obs = new PerformanceObserver((items) => {
+ * console.log(items.getEntries()[0].duration);
+ * performance.clearMarks();
+ * });
+ * obs.observe({ type: 'measure' });
+ * performance.measure('Start to Now');
+ *
+ * performance.mark('A');
+ * doSomeLongRunningProcess(() => {
+ * performance.measure('A to Now', 'A');
+ *
+ * performance.mark('B');
+ * performance.measure('A to B', 'A', 'B');
+ * });
+ * ```
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/perf_hooks.js)
+ */
+declare module "perf_hooks" {
+ // import { AsyncResource } from "node:async_hooks";
+ // type EntryType = "node" | "mark" | "measure" | "gc" | "function" | "http2" | "http";
+ // interface NodeGCPerformanceDetail {
+ // /**
+ // * When `performanceEntry.entryType` is equal to 'gc', `the performance.kind` property identifies
+ // * the type of garbage collection operation that occurred.
+ // * See perf_hooks.constants for valid values.
+ // */
+ // readonly kind?: number | undefined;
+ // /**
+ // * When `performanceEntry.entryType` is equal to 'gc', the `performance.flags`
+ // * property contains additional information about garbage collection operation.
+ // * See perf_hooks.constants for valid values.
+ // */
+ // readonly flags?: number | undefined;
+ // }
+ // /**
+ // * @since v8.5.0
+ // */
+ // class PerformanceEntry {
+ // protected constructor();
+ // /**
+ // * The total number of milliseconds elapsed for this entry. This value will not
+ // * be meaningful for all Performance Entry types.
+ // * @since v8.5.0
+ // */
+ // readonly duration: number;
+ // /**
+ // * The name of the performance entry.
+ // * @since v8.5.0
+ // */
+ // readonly name: string;
+ // /**
+ // * The high resolution millisecond timestamp marking the starting time of the
+ // * Performance Entry.
+ // * @since v8.5.0
+ // */
+ // readonly startTime: number;
+ // /**
+ // * The type of the performance entry. It may be one of:
+ // *
+ // * * `'node'` (Node.js only)
+ // * * `'mark'` (available on the Web)
+ // * * `'measure'` (available on the Web)
+ // * * `'gc'` (Node.js only)
+ // * * `'function'` (Node.js only)
+ // * * `'http2'` (Node.js only)
+ // * * `'http'` (Node.js only)
+ // * @since v8.5.0
+ // */
+ // readonly entryType: EntryType;
+ // /**
+ // * Additional detail specific to the `entryType`.
+ // * @since v16.0.0
+ // */
+ // readonly detail?: NodeGCPerformanceDetail | unknown | undefined; // TODO: Narrow this based on entry type.
+ // toJSON(): any;
+ // }
+ // class PerformanceMark extends PerformanceEntry {
+ // readonly duration: 0;
+ // readonly entryType: "mark";
+ // }
+ // class PerformanceMeasure extends PerformanceEntry {
+ // readonly entryType: "measure";
+ // }
+ // /**
+ // * _This property is an extension by Node.js. It is not available in Web browsers._
+ // *
+ // * Provides timing details for Node.js itself. The constructor of this class
+ // * is not exposed to users.
+ // * @since v8.5.0
+ // */
+ // class PerformanceNodeTiming extends PerformanceEntry {
+ // /**
+ // * The high resolution millisecond timestamp at which the Node.js process
+ // * completed bootstrapping. If bootstrapping has not yet finished, the property
+ // * has the value of -1.
+ // * @since v8.5.0
+ // */
+ // readonly bootstrapComplete: number;
+ // /**
+ // * The high resolution millisecond timestamp at which the Node.js environment was
+ // * initialized.
+ // * @since v8.5.0
+ // */
+ // readonly environment: number;
+ // /**
+ // * The high resolution millisecond timestamp of the amount of time the event loop
+ // * has been idle within the event loop's event provider (e.g. `epoll_wait`). This
+ // * does not take CPU usage into consideration. If the event loop has not yet
+ // * started (e.g., in the first tick of the main script), the property has the
+ // * value of 0.
+ // * @since v14.10.0, v12.19.0
+ // */
+ // readonly idleTime: number;
+ // /**
+ // * The high resolution millisecond timestamp at which the Node.js event loop
+ // * exited. If the event loop has not yet exited, the property has the value of -1\.
+ // * It can only have a value of not -1 in a handler of the `'exit'` event.
+ // * @since v8.5.0
+ // */
+ // readonly loopExit: number;
+ // /**
+ // * The high resolution millisecond timestamp at which the Node.js event loop
+ // * started. If the event loop has not yet started (e.g., in the first tick of the
+ // * main script), the property has the value of -1.
+ // * @since v8.5.0
+ // */
+ // readonly loopStart: number;
+ // /**
+ // * The high resolution millisecond timestamp at which the V8 platform was
+ // * initialized.
+ // * @since v8.5.0
+ // */
+ // readonly v8Start: number;
+ // }
+ // interface EventLoopUtilization {
+ // idle: number;
+ // active: number;
+ // utilization: number;
+ // }
+ // /**
+ // * @param util1 The result of a previous call to eventLoopUtilization()
+ // * @param util2 The result of a previous call to eventLoopUtilization() prior to util1
+ // */
+ // type EventLoopUtilityFunction = (util1?: EventLoopUtilization, util2?: EventLoopUtilization) => EventLoopUtilization;
+ // interface MarkOptions {
+ // /**
+ // * Additional optional detail to include with the mark.
+ // */
+ // detail?: unknown | undefined;
+ // /**
+ // * An optional timestamp to be used as the mark time.
+ // * @default `performance.now()`.
+ // */
+ // startTime?: number | undefined;
+ // }
+ // interface MeasureOptions {
+ // /**
+ // * Additional optional detail to include with the mark.
+ // */
+ // detail?: unknown | undefined;
+ // /**
+ // * Duration between start and end times.
+ // */
+ // duration?: number | undefined;
+ // /**
+ // * Timestamp to be used as the end time, or a string identifying a previously recorded mark.
+ // */
+ // end?: number | string | undefined;
+ // /**
+ // * Timestamp to be used as the start time, or a string identifying a previously recorded mark.
+ // */
+ // start?: number | string | undefined;
+ // }
+ // interface TimerifyOptions {
+ // /**
+ // * A histogram object created using
+ // * `perf_hooks.createHistogram()` that will record runtime durations in
+ // * nanoseconds.
+ // */
+ // histogram?: RecordableHistogram | undefined;
+ // }
+ interface Performance {
+ /**
+ * If name is not provided, removes all PerformanceMark objects from the Performance Timeline.
+ * If name is provided, removes only the named mark.
+ * @param name
+ */
+ // clearMarks(name?: string): void;
+ /**
+ * If name is not provided, removes all PerformanceMeasure objects from the Performance Timeline.
+ * If name is provided, removes only the named measure.
+ * @param name
+ * @since v16.7.0
+ */
+ // clearMeasures(name?: string): void;
+ /**
+ * Returns a list of `PerformanceEntry` objects in chronological order with respect to `performanceEntry.startTime`.
+ * If you are only interested in performance entries of certain types or that have certain names, see
+ * `performance.getEntriesByType()` and `performance.getEntriesByName()`.
+ * @since v16.7.0
+ */
+ // getEntries(): PerformanceEntry[];
+ /**
+ * Returns a list of `PerformanceEntry` objects in chronological order with respect to `performanceEntry.startTime`
+ * whose `performanceEntry.name` is equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to `type`.
+ * @param name
+ * @param type
+ * @since v16.7.0
+ */
+ // getEntriesByName(name: string, type?: EntryType): PerformanceEntry[];
+ /**
+ * Returns a list of `PerformanceEntry` objects in chronological order with respect to `performanceEntry.startTime`
+ * whose `performanceEntry.entryType` is equal to `type`.
+ * @param type
+ * @since v16.7.0
+ */
+ // getEntriesByType(type: EntryType): PerformanceEntry[];
+ /**
+ * Creates a new PerformanceMark entry in the Performance Timeline.
+ * A PerformanceMark is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'mark',
+ * and whose performanceEntry.duration is always 0.
+ * Performance marks are used to mark specific significant moments in the Performance Timeline.
+ * @param name
+ * @return The PerformanceMark entry that was created
+ */
+ // mark(name?: string, options?: MarkOptions): PerformanceMark;
+ /**
+ * Creates a new PerformanceMeasure entry in the Performance Timeline.
+ * A PerformanceMeasure is a subclass of PerformanceEntry whose performanceEntry.entryType is always 'measure',
+ * and whose performanceEntry.duration measures the number of milliseconds elapsed since startMark and endMark.
+ *
+ * The startMark argument may identify any existing PerformanceMark in the the Performance Timeline, or may identify
+ * any of the timestamp properties provided by the PerformanceNodeTiming class. If the named startMark does not exist,
+ * then startMark is set to timeOrigin by default.
+ *
+ * The endMark argument must identify any existing PerformanceMark in the the Performance Timeline or any of the timestamp
+ * properties provided by the PerformanceNodeTiming class. If the named endMark does not exist, an error will be thrown.
+ * @param name
+ * @param startMark
+ * @param endMark
+ * @return The PerformanceMeasure entry that was created
+ */
+ // measure(name: string, startMark?: string, endMark?: string): PerformanceMeasure;
+ // measure(name: string, options: MeasureOptions): PerformanceMeasure;
+ /**
+ * An instance of the PerformanceNodeTiming class that provides performance metrics for specific Node.js operational milestones.
+ */
+ // readonly nodeTiming: PerformanceNodeTiming;
+ /**
+ * @return the current high resolution millisecond timestamp
+ */
+ now(): number;
+ /**
+ * The timeOrigin specifies the high resolution millisecond timestamp from which all performance metric durations are measured.
+ */
+ readonly timeOrigin: number;
+ /**
+ * Wraps a function within a new function that measures the running time of the wrapped function.
+ * A PerformanceObserver must be subscribed to the 'function' event type in order for the timing details to be accessed.
+ * @param fn
+ */
+ // timerify<T extends (...params: any[]) => any>(fn: T, options?: TimerifyOptions): T;
+ /**
+ * eventLoopUtilization is similar to CPU utilization except that it is calculated using high precision wall-clock time.
+ * It represents the percentage of time the event loop has spent outside the event loop's event provider (e.g. epoll_wait).
+ * No other CPU idle time is taken into consideration.
+ */
+ // eventLoopUtilization: EventLoopUtilityFunction;
+ }
+ // interface PerformanceObserverEntryList {
+ // /**
+ // * Returns a list of `PerformanceEntry` objects in chronological order
+ // * with respect to `performanceEntry.startTime`.
+ // *
+ // * ```js
+ // * const {
+ // * performance,
+ // * PerformanceObserver
+ // * } = require('perf_hooks');
+ // *
+ // * const obs = new PerformanceObserver((perfObserverList, observer) => {
+ // * console.log(perfObserverList.getEntries());
+ // *
+ // * * [
+ // * * PerformanceEntry {
+ // * * name: 'test',
+ // * * entryType: 'mark',
+ // * * startTime: 81.465639,
+ // * * duration: 0
+ // * * },
+ // * * PerformanceEntry {
+ // * * name: 'meow',
+ // * * entryType: 'mark',
+ // * * startTime: 81.860064,
+ // * * duration: 0
+ // * * }
+ // * * ]
+ // *
+ // *
+ // * performance.clearMarks();
+ // * performance.clearMeasures();
+ // * observer.disconnect();
+ // * });
+ // * obs.observe({ type: 'mark' });
+ // *
+ // * performance.mark('test');
+ // * performance.mark('meow');
+ // * ```
+ // * @since v8.5.0
+ // */
+ // getEntries(): PerformanceEntry[];
+ // /**
+ // * Returns a list of `PerformanceEntry` objects in chronological order
+ // * with respect to `performanceEntry.startTime` whose `performanceEntry.name` is
+ // * equal to `name`, and optionally, whose `performanceEntry.entryType` is equal to`type`.
+ // *
+ // * ```js
+ // * const {
+ // * performance,
+ // * PerformanceObserver
+ // * } = require('perf_hooks');
+ // *
+ // * const obs = new PerformanceObserver((perfObserverList, observer) => {
+ // * console.log(perfObserverList.getEntriesByName('meow'));
+ // *
+ // * * [
+ // * * PerformanceEntry {
+ // * * name: 'meow',
+ // * * entryType: 'mark',
+ // * * startTime: 98.545991,
+ // * * duration: 0
+ // * * }
+ // * * ]
+ // *
+ // * console.log(perfObserverList.getEntriesByName('nope')); // []
+ // *
+ // * console.log(perfObserverList.getEntriesByName('test', 'mark'));
+ // *
+ // * * [
+ // * * PerformanceEntry {
+ // * * name: 'test',
+ // * * entryType: 'mark',
+ // * * startTime: 63.518931,
+ // * * duration: 0
+ // * * }
+ // * * ]
+ // *
+ // * console.log(perfObserverList.getEntriesByName('test', 'measure')); // []
+ // *
+ // * performance.clearMarks();
+ // * performance.clearMeasures();
+ // * observer.disconnect();
+ // * });
+ // * obs.observe({ entryTypes: ['mark', 'measure'] });
+ // *
+ // * performance.mark('test');
+ // * performance.mark('meow');
+ // * ```
+ // * @since v8.5.0
+ // */
+ // getEntriesByName(name: string, type?: EntryType): PerformanceEntry[];
+ // /**
+ // * Returns a list of `PerformanceEntry` objects in chronological order
+ // * with respect to `performanceEntry.startTime` whose `performanceEntry.entryType`is equal to `type`.
+ // *
+ // * ```js
+ // * const {
+ // * performance,
+ // * PerformanceObserver
+ // * } = require('perf_hooks');
+ // *
+ // * const obs = new PerformanceObserver((perfObserverList, observer) => {
+ // * console.log(perfObserverList.getEntriesByType('mark'));
+ // *
+ // * * [
+ // * * PerformanceEntry {
+ // * * name: 'test',
+ // * * entryType: 'mark',
+ // * * startTime: 55.897834,
+ // * * duration: 0
+ // * * },
+ // * * PerformanceEntry {
+ // * * name: 'meow',
+ // * * entryType: 'mark',
+ // * * startTime: 56.350146,
+ // * * duration: 0
+ // * * }
+ // * * ]
+ // *
+ // * performance.clearMarks();
+ // * performance.clearMeasures();
+ // * observer.disconnect();
+ // * });
+ // * obs.observe({ type: 'mark' });
+ // *
+ // * performance.mark('test');
+ // * performance.mark('meow');
+ // * ```
+ // * @since v8.5.0
+ // */
+ // getEntriesByType(type: EntryType): PerformanceEntry[];
+ // }
+ // type PerformanceObserverCallback = (list: PerformanceObserverEntryList, observer: PerformanceObserver) => void;
+ // class PerformanceObserver extends AsyncResource {
+ // constructor(callback: PerformanceObserverCallback);
+ // /**
+ // * Disconnects the `PerformanceObserver` instance from all notifications.
+ // * @since v8.5.0
+ // */
+ // disconnect(): void;
+ // /**
+ // * Subscribes the `PerformanceObserver` instance to notifications of new `PerformanceEntry` instances identified either by `options.entryTypes`or `options.type`:
+ // *
+ // * ```js
+ // * const {
+ // * performance,
+ // * PerformanceObserver
+ // * } = require('perf_hooks');
+ // *
+ // * const obs = new PerformanceObserver((list, observer) => {
+ // * // Called once asynchronously. `list` contains three items.
+ // * });
+ // * obs.observe({ type: 'mark' });
+ // *
+ // * for (let n = 0; n < 3; n++)
+ // * performance.mark(`test${n}`);
+ // * ```
+ // * @since v8.5.0
+ // */
+ // observe(
+ // options:
+ // | {
+ // entryTypes: ReadonlyArray<EntryType>;
+ // buffered?: boolean | undefined;
+ // }
+ // | {
+ // type: EntryType;
+ // buffered?: boolean | undefined;
+ // },
+ // ): void;
+ // }
+ // namespace constants {
+ // const NODE_PERFORMANCE_GC_MAJOR: number;
+ // const NODE_PERFORMANCE_GC_MINOR: number;
+ // const NODE_PERFORMANCE_GC_INCREMENTAL: number;
+ // const NODE_PERFORMANCE_GC_WEAKCB: number;
+ // const NODE_PERFORMANCE_GC_FLAGS_NO: number;
+ // const NODE_PERFORMANCE_GC_FLAGS_CONSTRUCT_RETAINED: number;
+ // const NODE_PERFORMANCE_GC_FLAGS_FORCED: number;
+ // const NODE_PERFORMANCE_GC_FLAGS_SYNCHRONOUS_PHANTOM_PROCESSING: number;
+ // const NODE_PERFORMANCE_GC_FLAGS_ALL_AVAILABLE_GARBAGE: number;
+ // const NODE_PERFORMANCE_GC_FLAGS_ALL_EXTERNAL_MEMORY: number;
+ // const NODE_PERFORMANCE_GC_FLAGS_SCHEDULE_IDLE: number;
+ // }
+ const performance: Performance;
+ // interface EventLoopMonitorOptions {
+ // /**
+ // * The sampling rate in milliseconds.
+ // * Must be greater than zero.
+ // * @default 10
+ // */
+ // resolution?: number | undefined;
+ // }
+ // interface Histogram {
+ // /**
+ // * Returns a `Map` object detailing the accumulated percentile distribution.
+ // * @since v11.10.0
+ // */
+ // readonly percentiles: Map<number, number>;
+ // /**
+ // * The number of times the event loop delay exceeded the maximum 1 hour event
+ // * loop delay threshold.
+ // * @since v11.10.0
+ // */
+ // readonly exceeds: number;
+ // /**
+ // * The minimum recorded event loop delay.
+ // * @since v11.10.0
+ // */
+ // readonly min: number;
+ // /**
+ // * The maximum recorded event loop delay.
+ // * @since v11.10.0
+ // */
+ // readonly max: number;
+ // /**
+ // * The mean of the recorded event loop delays.
+ // * @since v11.10.0
+ // */
+ // readonly mean: number;
+ // /**
+ // * The standard deviation of the recorded event loop delays.
+ // * @since v11.10.0
+ // */
+ // readonly stddev: number;
+ // /**
+ // * Resets the collected histogram data.
+ // * @since v11.10.0
+ // */
+ // reset(): void;
+ // /**
+ // * Returns the value at the given percentile.
+ // * @since v11.10.0
+ // * @param percentile A percentile value in the range (0, 100].
+ // */
+ // percentile(percentile: number): number;
+ // }
+ // interface IntervalHistogram extends Histogram {
+ // /**
+ // * Enables the update interval timer. Returns `true` if the timer was
+ // * started, `false` if it was already started.
+ // * @since v11.10.0
+ // */
+ // enable(): boolean;
+ // /**
+ // * Disables the update interval timer. Returns `true` if the timer was
+ // * stopped, `false` if it was already stopped.
+ // * @since v11.10.0
+ // */
+ // disable(): boolean;
+ // }
+ // interface RecordableHistogram extends Histogram {
+ // /**
+ // * @since v15.9.0, v14.18.0
+ // * @param val The amount to record in the histogram.
+ // */
+ // record(val: number | bigint): void;
+ // /**
+ // * Calculates the amount of time (in nanoseconds) that has passed since the
+ // * previous call to `recordDelta()` and records that amount in the histogram.
+ // *
+ // * ## Examples
+ // * @since v15.9.0, v14.18.0
+ // */
+ // recordDelta(): void;
+ // /**
+ // * Adds the values from other to this histogram.
+ // * @since v17.4.0, v16.14.0
+ // * @param other Recordable Histogram to combine with
+ // */
+ // add(other: RecordableHistogram): void;
+ // }
+ /**
+ * _This property is an extension by Node.js. It is not available in Web browsers._
+ *
+ * Creates an `IntervalHistogram` object that samples and reports the event loop
+ * delay over time. The delays will be reported in nanoseconds.
+ *
+ * Using a timer to detect approximate event loop delay works because the
+ * execution of timers is tied specifically to the lifecycle of the libuv
+ * event loop. That is, a delay in the loop will cause a delay in the execution
+ * of the timer, and those delays are specifically what this API is intended to
+ * detect.
+ *
+ * ```js
+ * const { monitorEventLoopDelay } = require('perf_hooks');
+ * const h = monitorEventLoopDelay({ resolution: 20 });
+ * h.enable();
+ * // Do something.
+ * h.disable();
+ * console.log(h.min);
+ * console.log(h.max);
+ * console.log(h.mean);
+ * console.log(h.stddev);
+ * console.log(h.percentiles);
+ * console.log(h.percentile(50));
+ * console.log(h.percentile(99));
+ * ```
+ * @since v11.10.0
+ */
+ // function monitorEventLoopDelay(options?: EventLoopMonitorOptions): IntervalHistogram;
+ // interface CreateHistogramOptions {
+ // /**
+ // * The minimum recordable value. Must be an integer value greater than 0.
+ // * @default 1
+ // */
+ // min?: number | bigint | undefined;
+ // /**
+ // * The maximum recordable value. Must be an integer value greater than min.
+ // * @default Number.MAX_SAFE_INTEGER
+ // */
+ // max?: number | bigint | undefined;
+ // /**
+ // * The number of accuracy digits. Must be a number between 1 and 5.
+ // * @default 3
+ // */
+ // figures?: number | undefined;
+ // }
+ /**
+ * Returns a `RecordableHistogram`.
+ * @since v15.9.0, v14.18.0
+ */
+ // function createHistogram(options?: CreateHistogramOptions): RecordableHistogram;
+
+ // import { performance as _performance } from "perf_hooks";
+ // global {
+ // /**
+ // * `performance` is a global reference for `require('perf_hooks').performance`
+ // * https://nodejs.org/api/globals.html#performance
+ // * @since v16.0.0
+ // */
+ // var performance: typeof globalThis extends {
+ // onmessage: any;
+ // performance: infer T;
+ // }
+ // ? T
+ // : typeof _performance;
+ // }
+}
+declare module "node:perf_hooks" {
+ export * from "perf_hooks";
+}
diff --git a/packages/bun-types/tests/console.test-d.ts b/packages/bun-types/tests/console.test-d.ts
index 5a4d6efa8..9392b7e9f 100644
--- a/packages/bun-types/tests/console.test-d.ts
+++ b/packages/bun-types/tests/console.test-d.ts
@@ -1,3 +1,17 @@
+import * as c1 from "node:console";
+import * as c2 from "console";
+
+c1.log();
+c2.log();
+
+for await (const line of c1) {
+ console.log("Received:", line);
+}
+
+for await (const line of c2) {
+ console.log("Received:", line);
+}
+
for await (const line of console) {
console.log("Received:", line);
}
diff --git a/packages/bun-types/tests/perf_hooks.test-d.ts b/packages/bun-types/tests/perf_hooks.test-d.ts
new file mode 100644
index 000000000..6f6106048
--- /dev/null
+++ b/packages/bun-types/tests/perf_hooks.test-d.ts
@@ -0,0 +1,4 @@
+import { performance } from "node:perf_hooks";
+
+performance.now();
+performance.timeOrigin;
diff --git a/packages/bun-types/tests/util.test-d.ts b/packages/bun-types/tests/util.test-d.ts
new file mode 100644
index 000000000..0bd0aaa28
--- /dev/null
+++ b/packages/bun-types/tests/util.test-d.ts
@@ -0,0 +1,7 @@
+import util from "node:util";
+import types from "node:util/types";
+
+util.types;
+types.isAnyArrayBuffer;
+types.isCryptoKey;
+util.inspect;
diff --git a/packages/bun-types/util.d.ts b/packages/bun-types/util.d.ts
index 0f9359b10..36e5f8814 100644
--- a/packages/bun-types/util.d.ts
+++ b/packages/bun-types/util.d.ts
@@ -9,6 +9,9 @@
* @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/util.js)
*/
declare module "util" {
+ import * as types from "node:util/types";
+
+ export { types };
export interface InspectOptions {
/**
* If set to `true`, getters are going to be
@@ -61,10 +64,7 @@ declare module "util" {
| "date"
| "regexp"
| "module";
- export type CustomInspectFunction = (
- depth: number,
- options: InspectOptionsStylized,
- ) => string;
+ export type CustomInspectFunction = (depth: number, options: InspectOptionsStylized) => string;
export interface InspectOptionsStylized extends InspectOptions {
stylize(text: string, styleType: Style): string;
}
@@ -341,12 +341,7 @@ declare module "util" {
* @param object Any JavaScript primitive or `Object`.
* @return The representation of `object`.
*/
- export function inspect(
- object: any,
- showHidden?: boolean,
- depth?: number | null,
- color?: boolean,
- ): string;
+ export function inspect(object: any, showHidden?: boolean, depth?: number | null, color?: boolean): string;
export function inspect(object: any, options?: InspectOptions): string;
export namespace inspect {
let colors: Dict<[number, number]>;
@@ -499,10 +494,7 @@ declare module "util" {
* ```
* @deprecated Legacy: Use ES2015 class syntax and `extends` keyword instead.
*/
- export function inherits(
- constructor: unknown,
- superConstructor: unknown,
- ): void;
+ export function inherits(constructor: unknown, superConstructor: unknown): void;
export type DebugLoggerFunction = (msg: string, ...param: unknown[]) => void;
export interface DebugLogger extends DebugLoggerFunction {
enabled: boolean;
@@ -563,10 +555,7 @@ declare module "util" {
* @param callback A callback invoked the first time the logging function is called with a function argument that is a more optimized logging function.
* @return The logging function
*/
- export function debuglog(
- section: string,
- callback?: (fn: DebugLoggerFunction) => void,
- ): DebugLogger;
+ export function debuglog(section: string, callback?: (fn: DebugLoggerFunction) => void): DebugLogger;
export const debug: typeof debuglog;
/**
* Returns `true` if the given `object` is a `Boolean`. Otherwise, returns `false`.
@@ -651,9 +640,7 @@ declare module "util" {
* ```
* @deprecated Since v4.0.0 - Use `value === undefined || value === null` instead.
*/
- export function isNullOrUndefined(
- object: unknown,
- ): object is null | undefined;
+ export function isNullOrUndefined(object: unknown): object is null | undefined;
/**
* Returns `true` if the given `object` is a `Number`. Otherwise, returns `false`.
*
@@ -817,11 +804,7 @@ declare module "util" {
* @param code A deprecation code. See the `list of deprecated APIs` for a list of codes.
* @return The deprecated function wrapped to emit a warning.
*/
- export function deprecate<T extends Function>(
- fn: T,
- msg: string,
- code?: string,
- ): T;
+ export function deprecate<T extends Function>(fn: T, msg: string, code?: string): T;
/**
* Returns `true` if there is deep strict equality between `val1` and `val2`.
* Otherwise, returns `false`.
@@ -888,9 +871,7 @@ declare module "util" {
* @param original An `async` function
* @return a callback style function
*/
- export function callbackify(
- fn: () => Promise<void>,
- ): (callback: (err: ErrnoException) => void) => void;
+ export function callbackify(fn: () => Promise<void>): (callback: (err: ErrnoException) => void) => void;
export function callbackify<TResult>(
fn: () => Promise<TResult>,
): (callback: (err: ErrnoException, result: TResult) => void) => void;
@@ -899,64 +880,28 @@ declare module "util" {
): (arg1: T1, callback: (err: ErrnoException) => void) => void;
export function callbackify<T1, TResult>(
fn: (arg1: T1) => Promise<TResult>,
- ): (
- arg1: T1,
- callback: (err: ErrnoException, result: TResult) => void,
- ) => void;
+ ): (arg1: T1, callback: (err: ErrnoException, result: TResult) => void) => void;
export function callbackify<T1, T2>(
fn: (arg1: T1, arg2: T2) => Promise<void>,
): (arg1: T1, arg2: T2, callback: (err: ErrnoException) => void) => void;
export function callbackify<T1, T2, TResult>(
fn: (arg1: T1, arg2: T2) => Promise<TResult>,
- ): (
- arg1: T1,
- arg2: T2,
- callback: (err: ErrnoException | null, result: TResult) => void,
- ) => void;
+ ): (arg1: T1, arg2: T2, callback: (err: ErrnoException | null, result: TResult) => void) => void;
export function callbackify<T1, T2, T3>(
fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<void>,
- ): (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- callback: (err: ErrnoException) => void,
- ) => void;
+ ): (arg1: T1, arg2: T2, arg3: T3, callback: (err: ErrnoException) => void) => void;
export function callbackify<T1, T2, T3, TResult>(
fn: (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>,
- ): (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- callback: (err: ErrnoException | null, result: TResult) => void,
- ) => void;
+ ): (arg1: T1, arg2: T2, arg3: T3, callback: (err: ErrnoException | null, result: TResult) => void) => void;
export function callbackify<T1, T2, T3, T4>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>,
- ): (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- callback: (err: ErrnoException) => void,
- ) => void;
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: ErrnoException) => void) => void;
export function callbackify<T1, T2, T3, T4, TResult>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>,
- ): (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- callback: (err: ErrnoException | null, result: TResult) => void,
- ) => void;
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: ErrnoException | null, result: TResult) => void) => void;
export function callbackify<T1, T2, T3, T4, T5>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>,
- ): (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- arg5: T5,
- callback: (err: ErrnoException) => void,
- ) => void;
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: ErrnoException) => void) => void;
export function callbackify<T1, T2, T3, T4, T5, TResult>(
fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>,
): (
@@ -968,32 +913,10 @@ declare module "util" {
callback: (err: ErrnoException | null, result: TResult) => void,
) => void;
export function callbackify<T1, T2, T3, T4, T5, T6>(
- fn: (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- arg5: T5,
- arg6: T6,
- ) => Promise<void>,
- ): (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- arg5: T5,
- arg6: T6,
- callback: (err: ErrnoException) => void,
- ) => void;
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<void>,
+ ): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, callback: (err: ErrnoException) => void) => void;
export function callbackify<T1, T2, T3, T4, T5, T6, TResult>(
- fn: (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- arg5: T5,
- arg6: T6,
- ) => Promise<TResult>,
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<TResult>,
): (
arg1: T1,
arg2: T2,
@@ -1003,12 +926,10 @@ declare module "util" {
arg6: T6,
callback: (err: ErrnoException | null, result: TResult) => void,
) => void;
- export interface CustomPromisifyLegacy<TCustom extends Function>
- extends Function {
+ export interface CustomPromisifyLegacy<TCustom extends Function> extends Function {
__promisify__: TCustom;
}
- export interface CustomPromisifySymbol<TCustom extends Function>
- extends Function {
+ export interface CustomPromisifySymbol<TCustom extends Function> extends Function {
[promisify.custom]: TCustom;
}
export type CustomPromisify<TCustom extends Function> =
@@ -1080,79 +1001,38 @@ declare module "util" {
* bindBar().then((a) => console.log(a)); // '42'
* ```
*/
- export function promisify<TCustom extends Function>(
- fn: CustomPromisify<TCustom>,
- ): TCustom;
+ export function promisify<TCustom extends Function>(fn: CustomPromisify<TCustom>): TCustom;
export function promisify<TResult>(
fn: (callback: (err: any, result: TResult) => void) => void,
): () => Promise<TResult>;
- export function promisify(
- fn: (callback: (err?: any) => void) => void,
- ): () => Promise<void>;
+ export function promisify(fn: (callback: (err?: any) => void) => void): () => Promise<void>;
export function promisify<T1, TResult>(
fn: (arg1: T1, callback: (err: any, result: TResult) => void) => void,
): (arg1: T1) => Promise<TResult>;
- export function promisify<T1>(
- fn: (arg1: T1, callback: (err?: any) => void) => void,
- ): (arg1: T1) => Promise<void>;
+ export function promisify<T1>(fn: (arg1: T1, callback: (err?: any) => void) => void): (arg1: T1) => Promise<void>;
export function promisify<T1, T2, TResult>(
- fn: (
- arg1: T1,
- arg2: T2,
- callback: (err: any, result: TResult) => void,
- ) => void,
+ fn: (arg1: T1, arg2: T2, callback: (err: any, result: TResult) => void) => void,
): (arg1: T1, arg2: T2) => Promise<TResult>;
export function promisify<T1, T2>(
fn: (arg1: T1, arg2: T2, callback: (err?: any) => void) => void,
): (arg1: T1, arg2: T2) => Promise<void>;
export function promisify<T1, T2, T3, TResult>(
- fn: (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- callback: (err: any, result: TResult) => void,
- ) => void,
+ fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err: any, result: TResult) => void) => void,
): (arg1: T1, arg2: T2, arg3: T3) => Promise<TResult>;
export function promisify<T1, T2, T3>(
fn: (arg1: T1, arg2: T2, arg3: T3, callback: (err?: any) => void) => void,
): (arg1: T1, arg2: T2, arg3: T3) => Promise<void>;
export function promisify<T1, T2, T3, T4, TResult>(
- fn: (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- callback: (err: any, result: TResult) => void,
- ) => void,
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err: any, result: TResult) => void) => void,
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<TResult>;
export function promisify<T1, T2, T3, T4>(
- fn: (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- callback: (err?: any) => void,
- ) => void,
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, callback: (err?: any) => void) => void,
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<void>;
export function promisify<T1, T2, T3, T4, T5, TResult>(
- fn: (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- arg5: T5,
- callback: (err: any, result: TResult) => void,
- ) => void,
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err: any, result: TResult) => void) => void,
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<TResult>;
export function promisify<T1, T2, T3, T4, T5>(
- fn: (
- arg1: T1,
- arg2: T2,
- arg3: T3,
- arg4: T4,
- arg5: T5,
- callback: (err?: any) => void,
- ) => void,
+ fn: (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, callback: (err?: any) => void) => void,
): (arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<void>;
export function promisify(fn: Function): Function;
export namespace promisify {
@@ -1181,3 +1061,511 @@ declare module "sys" {
declare module "node:sys" {
export * from "util";
}
+
+declare module "util/types" {
+ export * from "util/types";
+}
+declare module "util/types" {
+ import { KeyObject } from "node:crypto";
+ import { ArrayBufferView } from "bun";
+
+ /**
+ * Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) or
+ * [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
+ *
+ * See also `util.types.isArrayBuffer()` and `util.types.isSharedArrayBuffer()`.
+ *
+ * ```js
+ * util.types.isAnyArrayBuffer(new ArrayBuffer()); // Returns true
+ * util.types.isAnyArrayBuffer(new SharedArrayBuffer()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isAnyArrayBuffer(object: unknown): object is ArrayBufferLike;
+ /**
+ * Returns `true` if the value is an `arguments` object.
+ *
+ * ```js
+ * function foo() {
+ * util.types.isArgumentsObject(arguments); // Returns true
+ * }
+ * ```
+ * @since v10.0.0
+ */
+ function isArgumentsObject(object: unknown): object is IArguments;
+ /**
+ * Returns `true` if the value is a built-in [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instance.
+ * This does _not_ include [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instances. Usually, it is
+ * desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
+ *
+ * ```js
+ * util.types.isArrayBuffer(new ArrayBuffer()); // Returns true
+ * util.types.isArrayBuffer(new SharedArrayBuffer()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isArrayBuffer(object: unknown): object is ArrayBuffer;
+ /**
+ * Returns `true` if the value is an instance of one of the [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) views, such as typed
+ * array objects or [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView). Equivalent to
+ * [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
+ *
+ * ```js
+ * util.types.isArrayBufferView(new Int8Array()); // true
+ * util.types.isArrayBufferView(Buffer.from('hello world')); // true
+ * util.types.isArrayBufferView(new DataView(new ArrayBuffer(16))); // true
+ * util.types.isArrayBufferView(new ArrayBuffer()); // false
+ * ```
+ * @since v10.0.0
+ */
+ function isArrayBufferView(object: unknown): object is ArrayBufferView;
+ /**
+ * Returns `true` if the value is an [async function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).
+ * This only reports back what the JavaScript engine is seeing;
+ * in particular, the return value may not match the original source code if
+ * a transpilation tool was used.
+ *
+ * ```js
+ * util.types.isAsyncFunction(function foo() {}); // Returns false
+ * util.types.isAsyncFunction(async function foo() {}); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isAsyncFunction(object: unknown): boolean;
+ /**
+ * Returns `true` if the value is a `BigInt64Array` instance.
+ *
+ * ```js
+ * util.types.isBigInt64Array(new BigInt64Array()); // Returns true
+ * util.types.isBigInt64Array(new BigUint64Array()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isBigInt64Array(value: unknown): value is BigInt64Array;
+ /**
+ * Returns `true` if the value is a `BigUint64Array` instance.
+ *
+ * ```js
+ * util.types.isBigUint64Array(new BigInt64Array()); // Returns false
+ * util.types.isBigUint64Array(new BigUint64Array()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isBigUint64Array(value: unknown): value is BigUint64Array;
+ /**
+ * Returns `true` if the value is a boolean object, e.g. created
+ * by `new Boolean()`.
+ *
+ * ```js
+ * util.types.isBooleanObject(false); // Returns false
+ * util.types.isBooleanObject(true); // Returns false
+ * util.types.isBooleanObject(new Boolean(false)); // Returns true
+ * util.types.isBooleanObject(new Boolean(true)); // Returns true
+ * util.types.isBooleanObject(Boolean(false)); // Returns false
+ * util.types.isBooleanObject(Boolean(true)); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isBooleanObject(object: unknown): object is Boolean;
+ /**
+ * Returns `true` if the value is any boxed primitive object, e.g. created
+ * by `new Boolean()`, `new String()` or `Object(Symbol())`.
+ *
+ * For example:
+ *
+ * ```js
+ * util.types.isBoxedPrimitive(false); // Returns false
+ * util.types.isBoxedPrimitive(new Boolean(false)); // Returns true
+ * util.types.isBoxedPrimitive(Symbol('foo')); // Returns false
+ * util.types.isBoxedPrimitive(Object(Symbol('foo'))); // Returns true
+ * util.types.isBoxedPrimitive(Object(BigInt(5))); // Returns true
+ * ```
+ * @since v10.11.0
+ */
+ function isBoxedPrimitive(object: unknown): object is String | Number | BigInt | Boolean | Symbol;
+ /**
+ * Returns `true` if the value is a built-in [`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView) instance.
+ *
+ * ```js
+ * const ab = new ArrayBuffer(20);
+ * util.types.isDataView(new DataView(ab)); // Returns true
+ * util.types.isDataView(new Float64Array()); // Returns false
+ * ```
+ *
+ * See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
+ * @since v10.0.0
+ */
+ function isDataView(object: unknown): object is DataView;
+ /**
+ * Returns `true` if the value is a built-in [`Date`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) instance.
+ *
+ * ```js
+ * util.types.isDate(new Date()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isDate(object: unknown): object is Date;
+ /**
+ * Returns `true` if the value is a native `External` value.
+ *
+ * A native `External` value is a special type of object that contains a
+ * raw C++ pointer (`void*`) for access from native code, and has no other
+ * properties. Such objects are created either by Node.js internals or native
+ * addons. In JavaScript, they are [frozen](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) objects with a`null` prototype.
+ *
+ * ```c
+ * #include <js_native_api.h>
+ * #include <stdlib.h>
+ * napi_value result;
+ * static napi_value MyNapi(napi_env env, napi_callback_info info) {
+ * int* raw = (int*) malloc(1024);
+ * napi_status status = napi_create_external(env, (void*) raw, NULL, NULL, &#x26;result);
+ * if (status != napi_ok) {
+ * napi_throw_error(env, NULL, "napi_create_external failed");
+ * return NULL;
+ * }
+ * return result;
+ * }
+ * ...
+ * DECLARE_NAPI_PROPERTY("myNapi", MyNapi)
+ * ...
+ * ```
+ *
+ * ```js
+ * const native = require('napi_addon.node');
+ * const data = native.myNapi();
+ * util.types.isExternal(data); // returns true
+ * util.types.isExternal(0); // returns false
+ * util.types.isExternal(new String('foo')); // returns false
+ * ```
+ *
+ * For further information on `napi_create_external`, refer to `napi_create_external()`.
+ * @since v10.0.0
+ */
+ function isExternal(object: unknown): boolean;
+ /**
+ * Returns `true` if the value is a built-in [`Float32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array) instance.
+ *
+ * ```js
+ * util.types.isFloat32Array(new ArrayBuffer()); // Returns false
+ * util.types.isFloat32Array(new Float32Array()); // Returns true
+ * util.types.isFloat32Array(new Float64Array()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isFloat32Array(object: unknown): object is Float32Array;
+ /**
+ * Returns `true` if the value is a built-in [`Float64Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array) instance.
+ *
+ * ```js
+ * util.types.isFloat64Array(new ArrayBuffer()); // Returns false
+ * util.types.isFloat64Array(new Uint8Array()); // Returns false
+ * util.types.isFloat64Array(new Float64Array()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isFloat64Array(object: unknown): object is Float64Array;
+ /**
+ * Returns `true` if the value is a generator function.
+ * This only reports back what the JavaScript engine is seeing;
+ * in particular, the return value may not match the original source code if
+ * a transpilation tool was used.
+ *
+ * ```js
+ * util.types.isGeneratorFunction(function foo() {}); // Returns false
+ * util.types.isGeneratorFunction(function* foo() {}); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isGeneratorFunction(object: unknown): object is GeneratorFunction;
+ /**
+ * Returns `true` if the value is a generator object as returned from a
+ * built-in generator function.
+ * This only reports back what the JavaScript engine is seeing;
+ * in particular, the return value may not match the original source code if
+ * a transpilation tool was used.
+ *
+ * ```js
+ * function* foo() {}
+ * const generator = foo();
+ * util.types.isGeneratorObject(generator); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isGeneratorObject(object: unknown): object is Generator;
+ /**
+ * Returns `true` if the value is a built-in [`Int8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int8Array) instance.
+ *
+ * ```js
+ * util.types.isInt8Array(new ArrayBuffer()); // Returns false
+ * util.types.isInt8Array(new Int8Array()); // Returns true
+ * util.types.isInt8Array(new Float64Array()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isInt8Array(object: unknown): object is Int8Array;
+ /**
+ * Returns `true` if the value is a built-in [`Int16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int16Array) instance.
+ *
+ * ```js
+ * util.types.isInt16Array(new ArrayBuffer()); // Returns false
+ * util.types.isInt16Array(new Int16Array()); // Returns true
+ * util.types.isInt16Array(new Float64Array()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isInt16Array(object: unknown): object is Int16Array;
+ /**
+ * Returns `true` if the value is a built-in [`Int32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Int32Array) instance.
+ *
+ * ```js
+ * util.types.isInt32Array(new ArrayBuffer()); // Returns false
+ * util.types.isInt32Array(new Int32Array()); // Returns true
+ * util.types.isInt32Array(new Float64Array()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isInt32Array(object: unknown): object is Int32Array;
+ /**
+ * Returns `true` if the value is a built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance.
+ *
+ * ```js
+ * util.types.isMap(new Map()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isMap<T>(
+ object: T | {},
+ ): object is T extends ReadonlyMap<any, any>
+ ? unknown extends T
+ ? never
+ : ReadonlyMap<any, any>
+ : Map<unknown, unknown>;
+ /**
+ * Returns `true` if the value is an iterator returned for a built-in [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) instance.
+ *
+ * ```js
+ * const map = new Map();
+ * util.types.isMapIterator(map.keys()); // Returns true
+ * util.types.isMapIterator(map.values()); // Returns true
+ * util.types.isMapIterator(map.entries()); // Returns true
+ * util.types.isMapIterator(map[Symbol.iterator]()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isMapIterator(object: unknown): boolean;
+ /**
+ * Returns `true` if the value is an instance of a [Module Namespace Object](https://tc39.github.io/ecma262/#sec-module-namespace-exotic-objects).
+ *
+ * ```js
+ * import * as ns from './a.js';
+ *
+ * util.types.isModuleNamespaceObject(ns); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isModuleNamespaceObject(value: unknown): boolean;
+ /**
+ * Returns `true` if the value is an instance of a built-in `Error` type.
+ *
+ * ```js
+ * util.types.isNativeError(new Error()); // Returns true
+ * util.types.isNativeError(new TypeError()); // Returns true
+ * util.types.isNativeError(new RangeError()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isNativeError(object: unknown): object is Error;
+ /**
+ * Returns `true` if the value is a number object, e.g. created
+ * by `new Number()`.
+ *
+ * ```js
+ * util.types.isNumberObject(0); // Returns false
+ * util.types.isNumberObject(new Number(0)); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isNumberObject(object: unknown): object is Number;
+ /**
+ * Returns `true` if the value is a built-in [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise).
+ *
+ * ```js
+ * util.types.isPromise(Promise.resolve(42)); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isPromise(object: unknown): object is Promise<unknown>;
+ /**
+ * Returns `true` if the value is a [`Proxy`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) instance.
+ *
+ * ```js
+ * const target = {};
+ * const proxy = new Proxy(target, {});
+ * util.types.isProxy(target); // Returns false
+ * util.types.isProxy(proxy); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isProxy(object: unknown): boolean;
+ /**
+ * Returns `true` if the value is a regular expression object.
+ *
+ * ```js
+ * util.types.isRegExp(/abc/); // Returns true
+ * util.types.isRegExp(new RegExp('abc')); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isRegExp(object: unknown): object is RegExp;
+ /**
+ * Returns `true` if the value is a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance.
+ *
+ * ```js
+ * util.types.isSet(new Set()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isSet<T>(
+ object: T | {},
+ ): object is T extends ReadonlySet<any> ? (unknown extends T ? never : ReadonlySet<any>) : Set<unknown>;
+ /**
+ * Returns `true` if the value is an iterator returned for a built-in [`Set`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set) instance.
+ *
+ * ```js
+ * const set = new Set();
+ * util.types.isSetIterator(set.keys()); // Returns true
+ * util.types.isSetIterator(set.values()); // Returns true
+ * util.types.isSetIterator(set.entries()); // Returns true
+ * util.types.isSetIterator(set[Symbol.iterator]()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isSetIterator(object: unknown): boolean;
+ /**
+ * Returns `true` if the value is a built-in [`SharedArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) instance.
+ * This does _not_ include [`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) instances. Usually, it is
+ * desirable to test for both; See `util.types.isAnyArrayBuffer()` for that.
+ *
+ * ```js
+ * util.types.isSharedArrayBuffer(new ArrayBuffer()); // Returns false
+ * util.types.isSharedArrayBuffer(new SharedArrayBuffer()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isSharedArrayBuffer(object: unknown): object is SharedArrayBuffer;
+ /**
+ * Returns `true` if the value is a string object, e.g. created
+ * by `new String()`.
+ *
+ * ```js
+ * util.types.isStringObject('foo'); // Returns false
+ * util.types.isStringObject(new String('foo')); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isStringObject(object: unknown): object is String;
+ /**
+ * Returns `true` if the value is a symbol object, created
+ * by calling `Object()` on a `Symbol` primitive.
+ *
+ * ```js
+ * const symbol = Symbol('foo');
+ * util.types.isSymbolObject(symbol); // Returns false
+ * util.types.isSymbolObject(Object(symbol)); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isSymbolObject(object: unknown): object is Symbol;
+ /**
+ * Returns `true` if the value is a built-in [`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) instance.
+ *
+ * ```js
+ * util.types.isTypedArray(new ArrayBuffer()); // Returns false
+ * util.types.isTypedArray(new Uint8Array()); // Returns true
+ * util.types.isTypedArray(new Float64Array()); // Returns true
+ * ```
+ *
+ * See also [`ArrayBuffer.isView()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer/isView).
+ * @since v10.0.0
+ */
+ function isTypedArray(object: unknown): object is TypedArray;
+ /**
+ * Returns `true` if the value is a built-in [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) instance.
+ *
+ * ```js
+ * util.types.isUint8Array(new ArrayBuffer()); // Returns false
+ * util.types.isUint8Array(new Uint8Array()); // Returns true
+ * util.types.isUint8Array(new Float64Array()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isUint8Array(object: unknown): object is Uint8Array;
+ /**
+ * Returns `true` if the value is a built-in [`Uint8ClampedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8ClampedArray) instance.
+ *
+ * ```js
+ * util.types.isUint8ClampedArray(new ArrayBuffer()); // Returns false
+ * util.types.isUint8ClampedArray(new Uint8ClampedArray()); // Returns true
+ * util.types.isUint8ClampedArray(new Float64Array()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isUint8ClampedArray(object: unknown): object is Uint8ClampedArray;
+ /**
+ * Returns `true` if the value is a built-in [`Uint16Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint16Array) instance.
+ *
+ * ```js
+ * util.types.isUint16Array(new ArrayBuffer()); // Returns false
+ * util.types.isUint16Array(new Uint16Array()); // Returns true
+ * util.types.isUint16Array(new Float64Array()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isUint16Array(object: unknown): object is Uint16Array;
+ /**
+ * Returns `true` if the value is a built-in [`Uint32Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint32Array) instance.
+ *
+ * ```js
+ * util.types.isUint32Array(new ArrayBuffer()); // Returns false
+ * util.types.isUint32Array(new Uint32Array()); // Returns true
+ * util.types.isUint32Array(new Float64Array()); // Returns false
+ * ```
+ * @since v10.0.0
+ */
+ function isUint32Array(object: unknown): object is Uint32Array;
+ /**
+ * Returns `true` if the value is a built-in [`WeakMap`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap) instance.
+ *
+ * ```js
+ * util.types.isWeakMap(new WeakMap()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isWeakMap(object: unknown): object is WeakMap<object, unknown>;
+ /**
+ * Returns `true` if the value is a built-in [`WeakSet`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet) instance.
+ *
+ * ```js
+ * util.types.isWeakSet(new WeakSet()); // Returns true
+ * ```
+ * @since v10.0.0
+ */
+ function isWeakSet(object: unknown): object is WeakSet<object>;
+ /**
+ * Returns `true` if `value` is a `KeyObject`, `false` otherwise.
+ * @since v16.2.0
+ */
+ function isKeyObject(object: unknown): object is KeyObject;
+ /**
+ * Returns `true` if `value` is a `CryptoKey`, `false` otherwise.
+ * @since v16.2.0
+ */
+ function isCryptoKey(object: unknown): object is CryptoKey;
+}
+declare module "node:util" {
+ export * from "util";
+}
+declare module "node:util/types" {
+ export * from "util/types";
+}
diff --git a/tsconfig.json b/tsconfig.json
index dfde95345..2777ef03f 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -22,6 +22,7 @@
"src/bun.js/builtins",
"src/api/demo",
"test/snapshots",
- "test/snapshots-no-hmr"
+ "test/snapshots-no-hmr",
+ "node_modules"
]
-}
+} \ No newline at end of file