medikoo / cli-color

Colors and formatting for the console
ISC License
676 stars 34 forks source link

Using cli-color as in a module #26

Closed NetForces closed 9 years ago

NetForces commented 9 years ago

Here is a very simple example:

File node_functions.js:

var clc = require('/usr/lib/node_modules/cli-color');

module.exports = {
  pass: function () {
    console.log(clc.bgGreen.white.bold("PASS"))
  },
  fail: function () {
    console.log(clc.bgRed.white.bold("FAIL"))
  }
};

File test.js:

var tools = require('node_functions.js');
console.log(tools.fail());

The expected result would be simply the word FAIL in bold white over red backgroud.

However the result is:

conferences ssh 2015-06-29 14-07-38

I have no idea where the "undefined" comes from.

Running cli-color@1.0.0 with node v0.10.39

medikoo commented 9 years ago

It comes from console.log(tools.fail()), it logs result of tools.fail() call which returns undefined.

NetForces commented 9 years ago

Doh !

Changed the module for:

var clc = require('/usr/lib/node_modules/cli-color');

module.exports = {
  pass: function () {
    return(clc.bgGreen.white.bold("PASS"));
  },
  fail: function () {
    return(clc.bgRed.white.bold("FAIL"));
  }
};

Works great. Thanks.