All files / lib/internal repl.js

100% Statements 54/54
100% Branches 13/13
100% Functions 1/1
100% Lines 54/54

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 551x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 67x 67x 26x 26x 26x 67x 67x 67x 67x 67x 67x 67x 67x 67x 2x 2x 67x 67x 2x 2x 2x 2x 2x 67x 67x 65x 65x 67x 67x 67x 2x 67x 65x 65x 67x 67x 67x 67x 67x  
'use strict';
 
const {
  Number,
  NumberIsNaN,
  NumberParseInt,
  ObjectCreate,
} = primordials;
 
const REPL = require('repl');
const { kStandaloneREPL } = require('internal/repl/utils');
 
module.exports = ObjectCreate(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 (NumberParseInt(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 (!NumberIsNaN(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);
}