HEX
Server: Apache
System: Linux webd004.cluster130.gra.hosting.ovh.net 5.15.206-ovh-vps-grsec-zfs-classid #1 SMP Fri May 15 02:41:25 UTC 2026 x86_64
User: frenchy (106757)
PHP: 7.4.33
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/frenchy/www/french-american.org/current/node_modules/vorpal/dist/intercept.js
'use strict';

/**
 * Module dependencies.
 */

var _ = require('lodash');

/**
 * Intercepts stdout, passes thru callback
 * also pass console.error thru stdout so it goes to callback too
 * (stdout.write and stderr.write are both refs to the same stream.write function)
 * returns an unhook() function, call when done intercepting
 *
 * @param {Function} callback
 * @return {Function}
 */

module.exports = function (callback) {
  var oldStdoutWrite = process.stdout.write;
  var oldConsoleError = console.error;
  process.stdout.write = function (write) {
    return function (string) {
      var args = _.toArray(arguments);
      args[0] = interceptor(string);
      write.apply(process.stdout, args);
    };
  }(process.stdout.write);

  console.error = function () {
    return function () {
      var args = _.toArray(arguments);
      args.unshift('\x1b[31m[ERROR]\x1b[0m');
      console.log.apply(console.log, args);
    };
  }(console.error);

  function interceptor(string) {
    // only intercept the string
    var result = callback(string);
    if (typeof result === 'string') {
      string = result.replace(/\n$/, '') + (result && /\n$/.test(string) ? '\n' : '');
    }
    return string;
  }
  // puts back to original
  return function unhook() {
    process.stdout.write = oldStdoutWrite;
    console.error = oldConsoleError;
  };
};