UNPKG

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