source: trip-planner-front/node_modules/@types/node/repl.d.ts@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 17.7 KB
Line 
1declare module 'repl' {
2 import { Interface, Completer, AsyncCompleter } from 'readline';
3 import { Context } from 'vm';
4 import { InspectOptions } from 'util';
5
6 interface ReplOptions {
7 /**
8 * The input prompt to display.
9 * @default "> "
10 */
11 prompt?: string | undefined;
12 /**
13 * The `Readable` stream from which REPL input will be read.
14 * @default process.stdin
15 */
16 input?: NodeJS.ReadableStream | undefined;
17 /**
18 * The `Writable` stream to which REPL output will be written.
19 * @default process.stdout
20 */
21 output?: NodeJS.WritableStream | undefined;
22 /**
23 * If `true`, specifies that the output should be treated as a TTY terminal, and have
24 * ANSI/VT100 escape codes written to it.
25 * Default: checking the value of the `isTTY` property on the output stream upon
26 * instantiation.
27 */
28 terminal?: boolean | undefined;
29 /**
30 * The function to be used when evaluating each given line of input.
31 * Default: an async wrapper for the JavaScript `eval()` function. An `eval` function can
32 * error with `repl.Recoverable` to indicate the input was incomplete and prompt for
33 * additional lines.
34 *
35 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_default_evaluation
36 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_custom_evaluation_functions
37 */
38 eval?: REPLEval | undefined;
39 /**
40 * If `true`, specifies that the default `writer` function should include ANSI color
41 * styling to REPL output. If a custom `writer` function is provided then this has no
42 * effect.
43 * Default: the REPL instance's `terminal` value.
44 */
45 useColors?: boolean | undefined;
46 /**
47 * If `true`, specifies that the default evaluation function will use the JavaScript
48 * `global` as the context as opposed to creating a new separate context for the REPL
49 * instance. The node CLI REPL sets this value to `true`.
50 * Default: `false`.
51 */
52 useGlobal?: boolean | undefined;
53 /**
54 * If `true`, specifies that the default writer will not output the return value of a
55 * command if it evaluates to `undefined`.
56 * Default: `false`.
57 */
58 ignoreUndefined?: boolean | undefined;
59 /**
60 * The function to invoke to format the output of each command before writing to `output`.
61 * Default: a wrapper for `util.inspect`.
62 *
63 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_customizing_repl_output
64 */
65 writer?: REPLWriter | undefined;
66 /**
67 * An optional function used for custom Tab auto completion.
68 *
69 * @see https://nodejs.org/dist/latest-v11.x/docs/api/readline.html#readline_use_of_the_completer_function
70 */
71 completer?: Completer | AsyncCompleter | undefined;
72 /**
73 * A flag that specifies whether the default evaluator executes all JavaScript commands in
74 * strict mode or default (sloppy) mode.
75 * Accepted values are:
76 * - `repl.REPL_MODE_SLOPPY` - evaluates expressions in sloppy mode.
77 * - `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is equivalent to
78 * prefacing every repl statement with `'use strict'`.
79 */
80 replMode?: typeof REPL_MODE_SLOPPY | typeof REPL_MODE_STRICT | undefined;
81 /**
82 * Stop evaluating the current piece of code when `SIGINT` is received, i.e. `Ctrl+C` is
83 * pressed. This cannot be used together with a custom `eval` function.
84 * Default: `false`.
85 */
86 breakEvalOnSigint?: boolean | undefined;
87 }
88
89 type REPLEval = (this: REPLServer, evalCmd: string, context: Context, file: string, cb: (err: Error | null, result: any) => void) => void;
90 type REPLWriter = (this: REPLServer, obj: any) => string;
91
92 /**
93 * This is the default "writer" value, if none is passed in the REPL options,
94 * and it can be overridden by custom print functions.
95 */
96 const writer: REPLWriter & { options: InspectOptions };
97
98 type REPLCommandAction = (this: REPLServer, text: string) => void;
99
100 interface REPLCommand {
101 /**
102 * Help text to be displayed when `.help` is entered.
103 */
104 help?: string | undefined;
105 /**
106 * The function to execute, optionally accepting a single string argument.
107 */
108 action: REPLCommandAction;
109 }
110
111 /**
112 * Provides a customizable Read-Eval-Print-Loop (REPL).
113 *
114 * Instances of `repl.REPLServer` will accept individual lines of user input, evaluate those
115 * according to a user-defined evaluation function, then output the result. Input and output
116 * may be from `stdin` and `stdout`, respectively, or may be connected to any Node.js `stream`.
117 *
118 * Instances of `repl.REPLServer` support automatic completion of inputs, simplistic Emacs-style
119 * line editing, multi-line inputs, ANSI-styled output, saving and restoring current REPL session
120 * state, error recovery, and customizable evaluation functions.
121 *
122 * Instances of `repl.REPLServer` are created using the `repl.start()` method and _should not_
123 * be created directly using the JavaScript `new` keyword.
124 *
125 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_repl
126 */
127 class REPLServer extends Interface {
128 /**
129 * The `vm.Context` provided to the `eval` function to be used for JavaScript
130 * evaluation.
131 */
132 readonly context: Context;
133 /**
134 * Outdated alias for `input`.
135 */
136 readonly inputStream: NodeJS.ReadableStream;
137 /**
138 * Outdated alias for `output`.
139 */
140 readonly outputStream: NodeJS.WritableStream;
141 /**
142 * The `Readable` stream from which REPL input will be read.
143 */
144 readonly input: NodeJS.ReadableStream;
145 /**
146 * The `Writable` stream to which REPL output will be written.
147 */
148 readonly output: NodeJS.WritableStream;
149 /**
150 * The commands registered via `replServer.defineCommand()`.
151 */
152 readonly commands: { readonly [name: string]: REPLCommand | undefined };
153 /**
154 * A value indicating whether the REPL is currently in "editor mode".
155 *
156 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_commands_and_special_keys
157 */
158 readonly editorMode: boolean;
159 /**
160 * A value indicating whether the `_` variable has been assigned.
161 *
162 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
163 */
164 readonly underscoreAssigned: boolean;
165 /**
166 * The last evaluation result from the REPL (assigned to the `_` variable inside of the REPL).
167 *
168 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
169 */
170 readonly last: any;
171 /**
172 * A value indicating whether the `_error` variable has been assigned.
173 *
174 * @since v9.8.0
175 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
176 */
177 readonly underscoreErrAssigned: boolean;
178 /**
179 * The last error raised inside the REPL (assigned to the `_error` variable inside of the REPL).
180 *
181 * @since v9.8.0
182 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable
183 */
184 readonly lastError: any;
185 /**
186 * Specified in the REPL options, this is the function to be used when evaluating each
187 * given line of input. If not specified in the REPL options, this is an async wrapper
188 * for the JavaScript `eval()` function.
189 */
190 readonly eval: REPLEval;
191 /**
192 * Specified in the REPL options, this is a value indicating whether the default
193 * `writer` function should include ANSI color styling to REPL output.
194 */
195 readonly useColors: boolean;
196 /**
197 * Specified in the REPL options, this is a value indicating whether the default `eval`
198 * function will use the JavaScript `global` as the context as opposed to creating a new
199 * separate context for the REPL instance.
200 */
201 readonly useGlobal: boolean;
202 /**
203 * Specified in the REPL options, this is a value indicating whether the default `writer`
204 * function should output the result of a command if it evaluates to `undefined`.
205 */
206 readonly ignoreUndefined: boolean;
207 /**
208 * Specified in the REPL options, this is the function to invoke to format the output of
209 * each command before writing to `outputStream`. If not specified in the REPL options,
210 * this will be a wrapper for `util.inspect`.
211 */
212 readonly writer: REPLWriter;
213 /**
214 * Specified in the REPL options, this is the function to use for custom Tab auto-completion.
215 */
216 readonly completer: Completer | AsyncCompleter;
217 /**
218 * Specified in the REPL options, this is a flag that specifies whether the default `eval`
219 * function should execute all JavaScript commands in strict mode or default (sloppy) mode.
220 * Possible values are:
221 * - `repl.REPL_MODE_SLOPPY` - evaluates expressions in sloppy mode.
222 * - `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is equivalent to
223 * prefacing every repl statement with `'use strict'`.
224 */
225 readonly replMode: typeof REPL_MODE_SLOPPY | typeof REPL_MODE_STRICT;
226
227 /**
228 * NOTE: According to the documentation:
229 *
230 * > Instances of `repl.REPLServer` are created using the `repl.start()` method and
231 * > _should not_ be created directly using the JavaScript `new` keyword.
232 *
233 * `REPLServer` cannot be subclassed due to implementation specifics in NodeJS.
234 *
235 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_class_replserver
236 */
237 private constructor();
238
239 /**
240 * Used to add new `.`-prefixed commands to the REPL instance. Such commands are invoked
241 * by typing a `.` followed by the `keyword`.
242 *
243 * @param keyword The command keyword (_without_ a leading `.` character).
244 * @param cmd The function to invoke when the command is processed.
245 *
246 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_replserver_definecommand_keyword_cmd
247 */
248 defineCommand(keyword: string, cmd: REPLCommandAction | REPLCommand): void;
249 /**
250 * Readies the REPL instance for input from the user, printing the configured `prompt` to a
251 * new line in the `output` and resuming the `input` to accept new input.
252 *
253 * When multi-line input is being entered, an ellipsis is printed rather than the 'prompt'.
254 *
255 * This method is primarily intended to be called from within the action function for
256 * commands registered using the `replServer.defineCommand()` method.
257 *
258 * @param preserveCursor When `true`, the cursor placement will not be reset to `0`.
259 */
260 displayPrompt(preserveCursor?: boolean): void;
261 /**
262 * Clears any command that has been buffered but not yet executed.
263 *
264 * This method is primarily intended to be called from within the action function for
265 * commands registered using the `replServer.defineCommand()` method.
266 *
267 * @since v9.0.0
268 */
269 clearBufferedCommand(): void;
270
271 /**
272 * Initializes a history log file for the REPL instance. When executing the
273 * Node.js binary and using the command line REPL, a history file is initialized
274 * by default. However, this is not the case when creating a REPL
275 * programmatically. Use this method to initialize a history log file when working
276 * with REPL instances programmatically.
277 * @param path The path to the history file
278 */
279 setupHistory(path: string, cb: (err: Error | null, repl: this) => void): void;
280
281 /**
282 * events.EventEmitter
283 * 1. close - inherited from `readline.Interface`
284 * 2. line - inherited from `readline.Interface`
285 * 3. pause - inherited from `readline.Interface`
286 * 4. resume - inherited from `readline.Interface`
287 * 5. SIGCONT - inherited from `readline.Interface`
288 * 6. SIGINT - inherited from `readline.Interface`
289 * 7. SIGTSTP - inherited from `readline.Interface`
290 * 8. exit
291 * 9. reset
292 */
293
294 addListener(event: string, listener: (...args: any[]) => void): this;
295 addListener(event: "close", listener: () => void): this;
296 addListener(event: "line", listener: (input: string) => void): this;
297 addListener(event: "pause", listener: () => void): this;
298 addListener(event: "resume", listener: () => void): this;
299 addListener(event: "SIGCONT", listener: () => void): this;
300 addListener(event: "SIGINT", listener: () => void): this;
301 addListener(event: "SIGTSTP", listener: () => void): this;
302 addListener(event: "exit", listener: () => void): this;
303 addListener(event: "reset", listener: (context: Context) => void): this;
304
305 emit(event: string | symbol, ...args: any[]): boolean;
306 emit(event: "close"): boolean;
307 emit(event: "line", input: string): boolean;
308 emit(event: "pause"): boolean;
309 emit(event: "resume"): boolean;
310 emit(event: "SIGCONT"): boolean;
311 emit(event: "SIGINT"): boolean;
312 emit(event: "SIGTSTP"): boolean;
313 emit(event: "exit"): boolean;
314 emit(event: "reset", context: Context): boolean;
315
316 on(event: string, listener: (...args: any[]) => void): this;
317 on(event: "close", listener: () => void): this;
318 on(event: "line", listener: (input: string) => void): this;
319 on(event: "pause", listener: () => void): this;
320 on(event: "resume", listener: () => void): this;
321 on(event: "SIGCONT", listener: () => void): this;
322 on(event: "SIGINT", listener: () => void): this;
323 on(event: "SIGTSTP", listener: () => void): this;
324 on(event: "exit", listener: () => void): this;
325 on(event: "reset", listener: (context: Context) => void): this;
326
327 once(event: string, listener: (...args: any[]) => void): this;
328 once(event: "close", listener: () => void): this;
329 once(event: "line", listener: (input: string) => void): this;
330 once(event: "pause", listener: () => void): this;
331 once(event: "resume", listener: () => void): this;
332 once(event: "SIGCONT", listener: () => void): this;
333 once(event: "SIGINT", listener: () => void): this;
334 once(event: "SIGTSTP", listener: () => void): this;
335 once(event: "exit", listener: () => void): this;
336 once(event: "reset", listener: (context: Context) => void): this;
337
338 prependListener(event: string, listener: (...args: any[]) => void): this;
339 prependListener(event: "close", listener: () => void): this;
340 prependListener(event: "line", listener: (input: string) => void): this;
341 prependListener(event: "pause", listener: () => void): this;
342 prependListener(event: "resume", listener: () => void): this;
343 prependListener(event: "SIGCONT", listener: () => void): this;
344 prependListener(event: "SIGINT", listener: () => void): this;
345 prependListener(event: "SIGTSTP", listener: () => void): this;
346 prependListener(event: "exit", listener: () => void): this;
347 prependListener(event: "reset", listener: (context: Context) => void): this;
348
349 prependOnceListener(event: string, listener: (...args: any[]) => void): this;
350 prependOnceListener(event: "close", listener: () => void): this;
351 prependOnceListener(event: "line", listener: (input: string) => void): this;
352 prependOnceListener(event: "pause", listener: () => void): this;
353 prependOnceListener(event: "resume", listener: () => void): this;
354 prependOnceListener(event: "SIGCONT", listener: () => void): this;
355 prependOnceListener(event: "SIGINT", listener: () => void): this;
356 prependOnceListener(event: "SIGTSTP", listener: () => void): this;
357 prependOnceListener(event: "exit", listener: () => void): this;
358 prependOnceListener(event: "reset", listener: (context: Context) => void): this;
359 }
360
361 /**
362 * A flag passed in the REPL options. Evaluates expressions in sloppy mode.
363 */
364 const REPL_MODE_SLOPPY: symbol; // TODO: unique symbol
365
366 /**
367 * A flag passed in the REPL options. Evaluates expressions in strict mode.
368 * This is equivalent to prefacing every repl statement with `'use strict'`.
369 */
370 const REPL_MODE_STRICT: symbol; // TODO: unique symbol
371
372 /**
373 * Creates and starts a `repl.REPLServer` instance.
374 *
375 * @param options The options for the `REPLServer`. If `options` is a string, then it specifies
376 * the input prompt.
377 */
378 function start(options?: string | ReplOptions): REPLServer;
379
380 /**
381 * Indicates a recoverable error that a `REPLServer` can use to support multi-line input.
382 *
383 * @see https://nodejs.org/dist/latest-v10.x/docs/api/repl.html#repl_recoverable_errors
384 */
385 class Recoverable extends SyntaxError {
386 err: Error;
387
388 constructor(err: Error);
389 }
390}
Note: See TracBrowser for help on using the repository browser.