UNPKG

nstdlib-nightly

Version:

Node.js standard library converted to runtime-agnostic ES modules.

53 lines (43 loc) 1.37 kB
// Source: https://github.com/nodejs/node/blob/65eff1eb/lib/internal/repl.js import * as REPL from "nstdlib/lib/repl"; import { kStandaloneREPL } from "nstdlib/lib/internal/repl/utils"; let _module_exports_ = {}; export { _module_exports_ as default }; _module_exports_ = { __proto__: REPL }; _module_exports_.createInternalRepl = createRepl; function createRepl(env, opts, cb) { if (typeof opts === "function") { cb = opts; opts = null; } opts = { [kStandaloneREPL]: true, ignoreUndefined: false, useGlobal: true, breakEvalOnSigint: true, ...opts, }; if (Number.parseInt(env.NODE_NO_READLINE)) { opts.terminal = false; } if (env.NODE_REPL_MODE) { opts.replMode = { strict: REPL.REPL_MODE_STRICT, sloppy: REPL.REPL_MODE_SLOPPY, }[env.NODE_REPL_MODE.toLowerCase().trim()]; } if (opts.replMode === undefined) { opts.replMode = REPL.REPL_MODE_SLOPPY; } const historySize = Number(env.NODE_REPL_HISTORY_SIZE); if (!Number.isNaN(historySize) && historySize > 0) { opts.historySize = historySize; } else { opts.historySize = 1000; } const repl = REPL.start(opts); const term = "terminal" in opts ? opts.terminal : process.stdout.isTTY; repl.setupHistory(term ? env.NODE_REPL_HISTORY : "", cb); } export const __proto__ = REPL; export const createInternalRepl = createRepl;