UNPKG

9.04 kBTypeScriptView Raw
1// Declare "static" methods in Error
2interface ErrorConstructor {
3 /** Create .stack property on a target object */
4 captureStackTrace(targetObject: object, constructorOpt?: Function): void;
5
6 /**
7 * Optional override for formatting stack traces
8 *
9 * @see https://v8.dev/docs/stack-trace-api#customizing-stack-traces
10 */
11 prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
12
13 stackTraceLimit: number;
14}
15
16/*-----------------------------------------------*
17 * *
18 * GLOBAL *
19 * *
20 ------------------------------------------------*/
21
22// For backwards compability
23interface NodeRequire extends NodeJS.Require { }
24interface RequireResolve extends NodeJS.RequireResolve { }
25interface NodeModule extends NodeJS.Module { }
26
27declare var process: NodeJS.Process;
28declare var console: Console;
29
30declare var __filename: string;
31declare var __dirname: string;
32
33declare var require: NodeRequire;
34declare var module: NodeModule;
35
36// Same as module.exports
37declare var exports: any;
38
39/**
40 * Only available if `--expose-gc` is passed to the process.
41 */
42declare var gc: undefined | (() => void);
43
44//#region borrowed
45// from https://github.com/microsoft/TypeScript/blob/38da7c600c83e7b31193a62495239a0fe478cb67/lib/lib.webworker.d.ts#L633 until moved to separate lib
46/** A controller object that allows you to abort one or more DOM requests as and when desired. */
47interface AbortController {
48 /**
49 * Returns the AbortSignal object associated with this object.
50 */
51
52 readonly signal: AbortSignal;
53 /**
54 * Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
55 */
56 abort(): void;
57}
58
59/** A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. */
60interface AbortSignal {
61 /**
62 * Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.
63 */
64 readonly aborted: boolean;
65}
66
67declare var AbortController: {
68 prototype: AbortController;
69 new(): AbortController;
70};
71
72declare var AbortSignal: {
73 prototype: AbortSignal;
74 new(): AbortSignal;
75 // TODO: Add abort() static
76};
77//#endregion borrowed
78
79//#region ArrayLike.at()
80interface RelativeIndexable<T> {
81 /**
82 * Takes an integer value and returns the item at that index,
83 * allowing for positive and negative integers.
84 * Negative integers count back from the last item in the array.
85 */
86 at(index: number): T | undefined;
87}
88interface String extends RelativeIndexable<string> {}
89interface Array<T> extends RelativeIndexable<T> {}
90interface Int8Array extends RelativeIndexable<number> {}
91interface Uint8Array extends RelativeIndexable<number> {}
92interface Uint8ClampedArray extends RelativeIndexable<number> {}
93interface Int16Array extends RelativeIndexable<number> {}
94interface Uint16Array extends RelativeIndexable<number> {}
95interface Int32Array extends RelativeIndexable<number> {}
96interface Uint32Array extends RelativeIndexable<number> {}
97interface Float32Array extends RelativeIndexable<number> {}
98interface Float64Array extends RelativeIndexable<number> {}
99interface BigInt64Array extends RelativeIndexable<bigint> {}
100interface BigUint64Array extends RelativeIndexable<bigint> {}
101//#endregion ArrayLike.at() end
102
103/*----------------------------------------------*
104* *
105* GLOBAL INTERFACES *
106* *
107*-----------------------------------------------*/
108declare namespace NodeJS {
109 interface CallSite {
110 /**
111 * Value of "this"
112 */
113 getThis(): unknown;
114
115 /**
116 * Type of "this" as a string.
117 * This is the name of the function stored in the constructor field of
118 * "this", if available. Otherwise the object's [[Class]] internal
119 * property.
120 */
121 getTypeName(): string | null;
122
123 /**
124 * Current function
125 */
126 getFunction(): Function | undefined;
127
128 /**
129 * Name of the current function, typically its name property.
130 * If a name property is not available an attempt will be made to try
131 * to infer a name from the function's context.
132 */
133 getFunctionName(): string | null;
134
135 /**
136 * Name of the property [of "this" or one of its prototypes] that holds
137 * the current function
138 */
139 getMethodName(): string | null;
140
141 /**
142 * Name of the script [if this function was defined in a script]
143 */
144 getFileName(): string | null;
145
146 /**
147 * Current line number [if this function was defined in a script]
148 */
149 getLineNumber(): number | null;
150
151 /**
152 * Current column number [if this function was defined in a script]
153 */
154 getColumnNumber(): number | null;
155
156 /**
157 * A call site object representing the location where eval was called
158 * [if this function was created using a call to eval]
159 */
160 getEvalOrigin(): string | undefined;
161
162 /**
163 * Is this a toplevel invocation, that is, is "this" the global object?
164 */
165 isToplevel(): boolean;
166
167 /**
168 * Does this call take place in code defined by a call to eval?
169 */
170 isEval(): boolean;
171
172 /**
173 * Is this call in native V8 code?
174 */
175 isNative(): boolean;
176
177 /**
178 * Is this a constructor call?
179 */
180 isConstructor(): boolean;
181 }
182
183 interface ErrnoException extends Error {
184 errno?: number | undefined;
185 code?: string | undefined;
186 path?: string | undefined;
187 syscall?: string | undefined;
188 }
189
190 interface ReadableStream extends EventEmitter {
191 readable: boolean;
192 read(size?: number): string | Buffer;
193 setEncoding(encoding: BufferEncoding): this;
194 pause(): this;
195 resume(): this;
196 isPaused(): boolean;
197 pipe<T extends WritableStream>(destination: T, options?: { end?: boolean | undefined; }): T;
198 unpipe(destination?: WritableStream): this;
199 unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void;
200 wrap(oldStream: ReadableStream): this;
201 [Symbol.asyncIterator](): AsyncIterableIterator<string | Buffer>;
202 }
203
204 interface WritableStream extends EventEmitter {
205 writable: boolean;
206 write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
207 write(str: string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
208 end(cb?: () => void): this;
209 end(data: string | Uint8Array, cb?: () => void): this;
210 end(str: string, encoding?: BufferEncoding, cb?: () => void): this;
211 }
212
213 interface ReadWriteStream extends ReadableStream, WritableStream { }
214
215 interface RefCounted {
216 ref(): this;
217 unref(): this;
218 }
219
220 type TypedArray =
221 | Uint8Array
222 | Uint8ClampedArray
223 | Uint16Array
224 | Uint32Array
225 | Int8Array
226 | Int16Array
227 | Int32Array
228 | BigUint64Array
229 | BigInt64Array
230 | Float32Array
231 | Float64Array;
232 type ArrayBufferView = TypedArray | DataView;
233
234 interface Require {
235 (id: string): any;
236 resolve: RequireResolve;
237 cache: Dict<NodeModule>;
238 /**
239 * @deprecated
240 */
241 extensions: RequireExtensions;
242 main: Module | undefined;
243 }
244
245 interface RequireResolve {
246 (id: string, options?: { paths?: string[] | undefined; }): string;
247 paths(request: string): string[] | null;
248 }
249
250 interface RequireExtensions extends Dict<(m: Module, filename: string) => any> {
251 '.js': (m: Module, filename: string) => any;
252 '.json': (m: Module, filename: string) => any;
253 '.node': (m: Module, filename: string) => any;
254 }
255 interface Module {
256 /**
257 * `true` if the module is running during the Node.js preload
258 */
259 isPreloading: boolean;
260 exports: any;
261 require: Require;
262 id: string;
263 filename: string;
264 loaded: boolean;
265 /** @deprecated since 14.6.0 Please use `require.main` and `module.children` instead. */
266 parent: Module | null | undefined;
267 children: Module[];
268 /**
269 * @since 11.14.0
270 *
271 * The directory name of the module. This is usually the same as the path.dirname() of the module.id.
272 */
273 path: string;
274 paths: string[];
275 }
276
277 interface Dict<T> {
278 [key: string]: T | undefined;
279 }
280
281 interface ReadOnlyDict<T> {
282 readonly [key: string]: T | undefined;
283 }
284}