repl.start([options])
-
-
prompt
<string> 要显示的输入提示。默认值:'> '
(尾随空格)。¥
prompt
<string> The input prompt to display. Default:'> '
(with a trailing space). -
input
<stream.Readable> 将从中读取 REPL 输入的Readable
流。默认值:process.stdin
。¥
input
<stream.Readable> TheReadable
stream from which REPL input will be read. Default:process.stdin
. -
output
<stream.Writable> REPL 输出将写入的Writable
流。默认值:process.stdout
。¥
output
<stream.Writable> TheWritable
stream to which REPL output will be written. Default:process.stdout
. -
terminal
<boolean> 如果true
,则指定output
应被视为 TTY 终端。默认值:在实例化时检查output
流上isTTY
属性的值。¥
terminal
<boolean> Iftrue
, specifies that theoutput
should be treated as a TTY terminal. Default: checking the value of theisTTY
property on theoutput
stream upon instantiation. -
eval
<Function> 当评估每一给定输入行时要使用的函数。默认值:JavaScripteval()
函数的异步封装器。eval
函数可能会出现repl.Recoverable
错误,表明输入不完整并提示输入额外的行。有关更多详细信息,请参阅 自定义评估函数 部分。¥
eval
<Function> The function to be used when evaluating each given line of input. Default: an async wrapper for the JavaScripteval()
function. Aneval
function can error withrepl.Recoverable
to indicate the input was incomplete and prompt for additional lines. See the custom evaluation functions section for more details. -
useColors
<boolean> 如果为true
,则指定默认的writer
函数应在 REPL 输出中包含 ANSI 颜色样式。如果提供了自定义writer
函数,则此功能无效。默认值:如果 REPL 实例的terminal
值为true
,则检查output
流上的颜色支持。¥
useColors
<boolean> Iftrue
, specifies that the defaultwriter
function should include ANSI color styling to REPL output. If a customwriter
function is provided then this has no effect. Default: checking color support on theoutput
stream if the REPL instance'sterminal
value istrue
. -
useGlobal
<boolean> 如果为true
,则指定默认评估函数将使用 JavaScriptglobal
作为上下文,而不是为 REPL 实例创建新的单独上下文。node CLI REPL 将此值设置为true
。默认值:false
。¥
useGlobal
<boolean> Iftrue
, specifies that the default evaluation function will use the JavaScriptglobal
as the context as opposed to creating a new separate context for the REPL instance. The node CLI REPL sets this value totrue
. Default:false
. -
ignoreUndefined
<boolean> 如果为true
,则指定默认编写器在计算结果为undefined
时不会输出命令的返回值。默认值:false
。¥
ignoreUndefined
<boolean> Iftrue
, specifies that the default writer will not output the return value of a command if it evaluates toundefined
. Default:false
. -
writer
<Function> 在写入output
之前调用以格式化每个命令的输出的函数。默认值:util.inspect()
。¥
writer
<Function> The function to invoke to format the output of each command before writing tooutput
. Default:util.inspect()
. -
completer
<Function> 用于自定义 Tab 自动补齐的可选函数。有关示例,请参见readline.InterfaceCompleter
。¥
completer
<Function> An optional function used for custom Tab auto completion. Seereadline.InterfaceCompleter
for an example. -
replMode
<symbol> 指定默认求值器是在严格模式还是默认(宽松)模式下执行所有 JavaScript 命令的标志。可接受的值是:¥
replMode
<symbol> A flag that specifies whether the default evaluator executes all JavaScript commands in strict mode or default (sloppy) mode. Acceptable values are:-
repl.REPL_MODE_SLOPPY
在宽松模式下计算表达式。¥
repl.REPL_MODE_SLOPPY
to evaluate expressions in sloppy mode. -
repl.REPL_MODE_STRICT
在严格模式下计算表达式。这相当于在每个 repl 语句前面加上'use strict'
。¥
repl.REPL_MODE_STRICT
to evaluate expressions in strict mode. This is equivalent to prefacing every repl statement with'use strict'
.
-
-
breakEvalOnSigint
<boolean> 当收到SIGINT
时,例如按下 Ctrl+C 时,停止评估当前代码段。这不能与自定义eval
函数一起使用。默认值:false
。¥
breakEvalOnSigint
<boolean> Stop evaluating the current piece of code whenSIGINT
is received, such as when Ctrl+C is pressed. This cannot be used together with a customeval
function. Default:false
. -
preview
<boolean> 定义 repl 是否打印自动补齐和输出预览。默认值:true
使用默认 eval 函数,false
如果使用自定义 eval 函数。如果terminal
为假,则没有预览,preview
的值没有影响。¥
preview
<boolean> Defines if the repl prints autocomplete and output previews or not. Default:true
with the default eval function andfalse
in case a custom eval function is used. Ifterminal
is falsy, then there are no previews and the value ofpreview
has no effect.
-
-
¥Returns: <repl.REPLServer>
repl.start()
方法创建并启动了一个 repl.REPLServer
实例。
¥The repl.start()
method creates and starts a repl.REPLServer
instance.
如果 options
是字符串,则指定输入提示:
¥If options
is a string, then it specifies the input prompt:
import repl from 'node:repl';
// a Unix style prompt
repl.start('$ ');
const repl = require('node:repl');
// a Unix style prompt
repl.start('$ ');