Sha256: 6f15abd13c83f16ea6540016f2a06996d4e07cb02573d9087323595c382f33bc

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

/*
  A console.log that won't leave you hanging when node exits
  90% of this file was ripped from node.js

  License: see: https://github.com/joyent/node/blob/master/lib/console.js
 */

 // console object
var formatRegExp = /%[sdj]/g;
function format(f) {
  var util = require('util');

  if (typeof f !== 'string') {
    var objects = [];
    for (var i = 0; i < arguments.length; i++) {
      objects.push(util.inspect(arguments[i]));
    }
    return objects.join(' ');
  }


  var i = 1;
  var args = arguments;
  var str = String(f).replace(formatRegExp, function(x) {
    switch (x) {
      case '%s': return String(args[i++]);
      case '%d': return Number(args[i++]);
      case '%j': return JSON.stringify(args[i++]);
      default:
        return x;
    }
  });
  for (var len = args.length, x = args[i]; i < len; x = args[++i]) {
    if (x === null || typeof x !== 'object') {
      str += ' ' + x;
    } else {
      str += ' ' + util.inspect(x);
    }
  }
  return str;
}

console.log = function() {
  var res = process.stdout.write(format.apply(this, arguments) + '\n');

  // this is the first time stdout got backed up
  if (!res && !process.stdout.pendingWrite) {
     process.stdout.pendingWrite = true;

     // magic sauce: keep node alive until stdout has flushed
     process.stdout.once('drain', function () {
       process.stdout.draining = false;
     });
  }
};

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
trans-0.5.10 template/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/deps/console.log.js
trans-0.5.9 template/node_modules/grunt-contrib-nodeunit/node_modules/nodeunit/deps/console.log.js
mobile_template-0.0.3 templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js
mobile_template-0.0.2 templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js
mobile_template-0.0.1 templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js