Pinsave/counterstrike
1
1/**2 * The `node:repl` module provides a Read-Eval-Print-Loop (REPL) implementation3 * that is available both as a standalone program or includible in other4 * applications. It can be accessed using:5 *6 * ```js7 * import repl from 'node:repl';8 * ```9 * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/repl.js)10 */11declare module "repl" {12 import { AsyncCompleter, Completer, Interface } from "node:readline";13 import { Context } from "node:vm";14 import { InspectOptions } from "node:util";15 interface ReplOptions {16 /**17 * The input prompt to display.18 * @default "> "19 */20 prompt?: string | undefined;21 /**22 * The `Readable` stream from which REPL input will be read.23 * @default process.stdin24 */25 input?: NodeJS.ReadableStream | undefined;26 /**27 * The `Writable` stream to which REPL output will be written.28 * @default process.stdout29 */30 output?: NodeJS.WritableStream | undefined;31 /**32 * If `true`, specifies that the output should be treated as a TTY terminal, and have33 * ANSI/VT100 escape codes written to it.34 * Default: checking the value of the `isTTY` property on the output stream upon35 * instantiation.36 */37 terminal?: boolean | undefined;38 /**39 * The function to be used when evaluating each given line of input.40 * **Default:** an async wrapper for the JavaScript `eval()` function. An `eval` function can41 * error with `repl.Recoverable` to indicate the input was incomplete and prompt for42 * additional lines. See the [custom evaluation functions](https://nodejs.org/dist/latest-v24.x/docs/api/repl.html#custom-evaluation-functions)43 * section for more details.44 */45 eval?: REPLEval | undefined;46 /**47 * Defines if the repl prints output previews or not.48 * @default `true` Always `false` in case `terminal` is falsy.49 */50 preview?: boolean | undefined;51 /**52 * If `true`, specifies that the default `writer` function should include ANSI color53 * styling to REPL output. If a custom `writer` function is provided then this has no54 * effect.55 * @default the REPL instance's `terminal` value56 */57 useColors?: boolean | undefined;58 /**59 * If `true`, specifies that the default evaluation function will use the JavaScript60 * `global` as the context as opposed to creating a new separate context for the REPL61 * instance. The node CLI REPL sets this value to `true`.62 * @default false63 */64 useGlobal?: boolean | undefined;65 /**66 * If `true`, specifies that the default writer will not output the return value of a67 * command if it evaluates to `undefined`.68 * @default false69 */70 ignoreUndefined?: boolean | undefined;71 /**72 * The function to invoke to format the output of each command before writing to `output`.73 * @default a wrapper for `util.inspect`74 *75 * @see https://nodejs.org/dist/latest-v24.x/docs/api/repl.html#repl_customizing_repl_output76 */77 writer?: REPLWriter | undefined;78 /**79 * An optional function used for custom Tab auto completion.80 *81 * @see https://nodejs.org/dist/latest-v24.x/docs/api/readline.html#readline_use_of_the_completer_function82 */83 completer?: Completer | AsyncCompleter | undefined;84 /**85 * A flag that specifies whether the default evaluator executes all JavaScript commands in86 * strict mode or default (sloppy) mode.87 * Accepted values are:88 * - `repl.REPL_MODE_SLOPPY` - evaluates expressions in sloppy mode.89 * - `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is equivalent to90 * prefacing every repl statement with `'use strict'`.91 */92 replMode?: typeof REPL_MODE_SLOPPY | typeof REPL_MODE_STRICT | undefined;93 /**94 * Stop evaluating the current piece of code when `SIGINT` is received, i.e. `Ctrl+C` is95 * pressed. This cannot be used together with a custom `eval` function.96 * @default false97 */98 breakEvalOnSigint?: boolean | undefined;99 }100 type REPLEval = (101 this: REPLServer,102 evalCmd: string,103 context: Context,104 file: string,105 cb: (err: Error | null, result: any) => void,106 ) => void;107 type REPLWriter = (this: REPLServer, obj: any) => string;108 /**109 * This is the default "writer" value, if none is passed in the REPL options,110 * and it can be overridden by custom print functions.111 */112 const writer: REPLWriter & {113 options: InspectOptions;114 };115 type REPLCommandAction = (this: REPLServer, text: string) => void;116 interface REPLCommand {117 /**118 * Help text to be displayed when `.help` is entered.119 */120 help?: string | undefined;121 /**122 * The function to execute, optionally accepting a single string argument.123 */124 action: REPLCommandAction;125 }126 /**127 * Instances of `repl.REPLServer` are created using the {@link start} method128 * or directly using the JavaScript `new` keyword.129 *130 * ```js131 * import repl from 'node:repl';132 *133 * const options = { useColors: true };134 *135 * const firstInstance = repl.start(options);136 * const secondInstance = new repl.REPLServer(options);137 * ```138 * @since v0.1.91139 */140 class REPLServer extends Interface {141 /**142 * The `vm.Context` provided to the `eval` function to be used for JavaScript143 * evaluation.144 */145 readonly context: Context;146 /**147 * @deprecated since v14.3.0 - Use `input` instead.148 */149 readonly inputStream: NodeJS.ReadableStream;150 /**151 * @deprecated since v14.3.0 - Use `output` instead.152 */153 readonly outputStream: NodeJS.WritableStream;154 /**155 * The `Readable` stream from which REPL input will be read.156 */157 readonly input: NodeJS.ReadableStream;158 /**159 * The `Writable` stream to which REPL output will be written.160 */161 readonly output: NodeJS.WritableStream;162 /**163 * The commands registered via `replServer.defineCommand()`.164 */165 readonly commands: NodeJS.ReadOnlyDict<REPLCommand>;166 /**167 * A value indicating whether the REPL is currently in "editor mode".168 *169 * @see https://nodejs.org/dist/latest-v24.x/docs/api/repl.html#repl_commands_and_special_keys170 */171 readonly editorMode: boolean;172 /**173 * A value indicating whether the `_` variable has been assigned.174 *175 * @see https://nodejs.org/dist/latest-v24.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable176 */177 readonly underscoreAssigned: boolean;178 /**179 * The last evaluation result from the REPL (assigned to the `_` variable inside of the REPL).180 *181 * @see https://nodejs.org/dist/latest-v24.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable182 */183 readonly last: any;184 /**185 * A value indicating whether the `_error` variable has been assigned.186 *187 * @since v9.8.0188 * @see https://nodejs.org/dist/latest-v24.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable189 */190 readonly underscoreErrAssigned: boolean;191 /**192 * The last error raised inside the REPL (assigned to the `_error` variable inside of the REPL).193 *194 * @since v9.8.0195 * @see https://nodejs.org/dist/latest-v24.x/docs/api/repl.html#repl_assignment_of_the_underscore_variable196 */197 readonly lastError: any;198 /**199 * Specified in the REPL options, this is the function to be used when evaluating each200 * given line of input. If not specified in the REPL options, this is an async wrapper201 * for the JavaScript `eval()` function.202 */203 readonly eval: REPLEval;204 /**205 * Specified in the REPL options, this is a value indicating whether the default206 * `writer` function should include ANSI color styling to REPL output.207 */208 readonly useColors: boolean;209 /**210 * Specified in the REPL options, this is a value indicating whether the default `eval`211 * function will use the JavaScript `global` as the context as opposed to creating a new212 * separate context for the REPL instance.213 */214 readonly useGlobal: boolean;215 /**216 * Specified in the REPL options, this is a value indicating whether the default `writer`217 * function should output the result of a command if it evaluates to `undefined`.218 */219 readonly ignoreUndefined: boolean;220 /**221 * Specified in the REPL options, this is the function to invoke to format the output of222 * each command before writing to `outputStream`. If not specified in the REPL options,223 * this will be a wrapper for `util.inspect`.224 */225 readonly writer: REPLWriter;226 /**227 * Specified in the REPL options, this is the function to use for custom Tab auto-completion.228 */229 readonly completer: Completer | AsyncCompleter;230 /**231 * Specified in the REPL options, this is a flag that specifies whether the default `eval`232 * function should execute all JavaScript commands in strict mode or default (sloppy) mode.233 * Possible values are:234 * - `repl.REPL_MODE_SLOPPY` - evaluates expressions in sloppy mode.235 * - `repl.REPL_MODE_STRICT` - evaluates expressions in strict mode. This is equivalent to236 * prefacing every repl statement with `'use strict'`.237 */238 readonly replMode: typeof REPL_MODE_SLOPPY | typeof REPL_MODE_STRICT;239 /**240 * NOTE: According to the documentation:241 *242 * > Instances of `repl.REPLServer` are created using the `repl.start()` method and243 * > _should not_ be created directly using the JavaScript `new` keyword.244 *245 * `REPLServer` cannot be subclassed due to implementation specifics in NodeJS.246 *247 * @see https://nodejs.org/dist/latest-v24.x/docs/api/repl.html#repl_class_replserver248 */249 private constructor();250 /**251 * The `replServer.defineCommand()` method is used to add new `.`\-prefixed commands252 * to the REPL instance. Such commands are invoked by typing a `.` followed by the `keyword`. The `cmd` is either a `Function` or an `Object` with the following253 * properties:254 *255 * The following example shows two new commands added to the REPL instance:256 *257 * ```js258 * import repl from 'node:repl';259 *260 * const replServer = repl.start({ prompt: '> ' });261 * replServer.defineCommand('sayhello', {262 * help: 'Say hello',263 * action(name) {264 * this.clearBufferedCommand();265 * console.log(`Hello, ${name}!`);266 * this.displayPrompt();267 * },268 * });269 * replServer.defineCommand('saybye', function saybye() {270 * console.log('Goodbye!');271 * this.close();272 * });273 * ```274 *275 * The new commands can then be used from within the REPL instance:276 *277 * ```console278 * > .sayhello Node.js User279 * Hello, Node.js User!280 * > .saybye281 * Goodbye!282 * ```283 * @since v0.3.0284 * @param keyword The command keyword (_without_ a leading `.` character).285 * @param cmd The function to invoke when the command is processed.286 */287 defineCommand(keyword: string, cmd: REPLCommandAction | REPLCommand): void;288 /**289 * The `replServer.displayPrompt()` method readies the REPL instance for input290 * from the user, printing the configured `prompt` to a new line in the `output` and resuming the `input` to accept new input.291 *292 * When multi-line input is being entered, a pipe `'|'` is printed rather than the293 * 'prompt'.294 *295 * When `preserveCursor` is `true`, the cursor placement will not be reset to `0`.296 *297 * The `replServer.displayPrompt` method is primarily intended to be called from298 * within the action function for commands registered using the `replServer.defineCommand()` method.299 * @since v0.1.91300 */301 displayPrompt(preserveCursor?: boolean): void;302 /**303 * The `replServer.clearBufferedCommand()` method clears any command that has been304 * buffered but not yet executed. This method is primarily intended to be305 * called from within the action function for commands registered using the `replServer.defineCommand()` method.306 * @since v9.0.0307 */308 clearBufferedCommand(): void;309 /**310 * Initializes a history log file for the REPL instance. When executing the311 * Node.js binary and using the command-line REPL, a history file is initialized312 * by default. However, this is not the case when creating a REPL313 * programmatically. Use this method to initialize a history log file when working314 * with REPL instances programmatically.315 * @since v11.10.0316 * @param historyPath the path to the history file317 * @param callback called when history writes are ready or upon error318 */319 setupHistory(path: string, callback: (err: Error | null, repl: this) => void): void;320 /**321 * events.EventEmitter322 * 1. close - inherited from `readline.Interface`323 * 2. line - inherited from `readline.Interface`324 * 3. pause - inherited from `readline.Interface`325 * 4. resume - inherited from `readline.Interface`326 * 5. SIGCONT - inherited from `readline.Interface`327 * 6. SIGINT - inherited from `readline.Interface`328 * 7. SIGTSTP - inherited from `readline.Interface`329 * 8. exit330 * 9. reset331 */332 addListener(event: string, listener: (...args: any[]) => void): this;333 addListener(event: "close", listener: () => void): this;334 addListener(event: "line", listener: (input: string) => void): this;335 addListener(event: "pause", listener: () => void): this;336 addListener(event: "resume", listener: () => void): this;337 addListener(event: "SIGCONT", listener: () => void): this;338 addListener(event: "SIGINT", listener: () => void): this;339 addListener(event: "SIGTSTP", listener: () => void): this;340 addListener(event: "exit", listener: () => void): this;341 addListener(event: "reset", listener: (context: Context) => void): this;342 emit(event: string | symbol, ...args: any[]): boolean;343 emit(event: "close"): boolean;344 emit(event: "line", input: string): boolean;345 emit(event: "pause"): boolean;346 emit(event: "resume"): boolean;347 emit(event: "SIGCONT"): boolean;348 emit(event: "SIGINT"): boolean;349 emit(event: "SIGTSTP"): boolean;350 emit(event: "exit"): boolean;351 emit(event: "reset", context: Context): boolean;352 on(event: string, listener: (...args: any[]) => void): this;353 on(event: "close", listener: () => void): this;354 on(event: "line", listener: (input: string) => void): this;355 on(event: "pause", listener: () => void): this;356 on(event: "resume", listener: () => void): this;357 on(event: "SIGCONT", listener: () => void): this;358 on(event: "SIGINT", listener: () => void): this;359 on(event: "SIGTSTP", listener: () => void): this;360 on(event: "exit", listener: () => void): this;361 on(event: "reset", listener: (context: Context) => void): this;362 once(event: string, listener: (...args: any[]) => void): this;363 once(event: "close", listener: () => void): this;364 once(event: "line", listener: (input: string) => void): this;365 once(event: "pause", listener: () => void): this;366 once(event: "resume", listener: () => void): this;367 once(event: "SIGCONT", listener: () => void): this;368 once(event: "SIGINT", listener: () => void): this;369 once(event: "SIGTSTP", listener: () => void): this;370 once(event: "exit", listener: () => void): this;371 once(event: "reset", listener: (context: Context) => void): this;372 prependListener(event: string, listener: (...args: any[]) => void): this;373 prependListener(event: "close", listener: () => void): this;374 prependListener(event: "line", listener: (input: string) => void): this;375 prependListener(event: "pause", listener: () => void): this;376 prependListener(event: "resume", listener: () => void): this;377 prependListener(event: "SIGCONT", listener: () => void): this;378 prependListener(event: "SIGINT", listener: () => void): this;379 prependListener(event: "SIGTSTP", listener: () => void): this;380 prependListener(event: "exit", listener: () => void): this;381 prependListener(event: "reset", listener: (context: Context) => void): this;382 prependOnceListener(event: string, listener: (...args: any[]) => void): this;383 prependOnceListener(event: "close", listener: () => void): this;384 prependOnceListener(event: "line", listener: (input: string) => void): this;385 prependOnceListener(event: "pause", listener: () => void): this;386 prependOnceListener(event: "resume", listener: () => void): this;387 prependOnceListener(event: "SIGCONT", listener: () => void): this;388 prependOnceListener(event: "SIGINT", listener: () => void): this;389 prependOnceListener(event: "SIGTSTP", listener: () => void): this;390 prependOnceListener(event: "exit", listener: () => void): this;391 prependOnceListener(event: "reset", listener: (context: Context) => void): this;392 }393 /**394 * A flag passed in the REPL options. Evaluates expressions in sloppy mode.395 */396 const REPL_MODE_SLOPPY: unique symbol;397 /**398 * A flag passed in the REPL options. Evaluates expressions in strict mode.399 * This is equivalent to prefacing every repl statement with `'use strict'`.400 */401 const REPL_MODE_STRICT: unique symbol;402 /**403 * The `repl.start()` method creates and starts a {@link REPLServer} instance.404 *405 * If `options` is a string, then it specifies the input prompt:406 *407 * ```js408 * import repl from 'node:repl';409 *410 * // a Unix style prompt411 * repl.start('$ ');412 * ```413 * @since v0.1.91414 */415 function start(options?: string | ReplOptions): REPLServer;416 /**417 * Indicates a recoverable error that a `REPLServer` can use to support multi-line input.418 *419 * @see https://nodejs.org/dist/latest-v24.x/docs/api/repl.html#repl_recoverable_errors420 */421 class Recoverable extends SyntaxError {422 err: Error;423 constructor(err: Error);424 }425}426declare module "node:repl" {427 export * from "repl";428}429 