Skip to content

Instantly share code, notes, and snippets.

@walling
Last active December 8, 2016 15:29
Show Gist options
  • Save walling/8a7a353fd38140ddb8364ad118cbf0eb to your computer and use it in GitHub Desktop.
Save walling/8a7a353fd38140ddb8364ad118cbf0eb to your computer and use it in GitHub Desktop.
Primitive replacement for chalk NPM
// ES5 version of chalk replacement with chaining :)
var util = require("util");
function C(text) {
var self = {};
Object.keys(util.inspect.colors).forEach(function(name) {
var color = util.inspect.colors[name];
self[name] = function() {
return C(util.format("\x1B[%sm%s\x1B[%sm", color[0], text, color[1]));
};
});
self.toString = self.valueOf = self.str = function() { return text; };
return self;
}
console.log("This is the message: %s", C("Yai!").green().underline());
var util = require("util");
function C(color, text) {
var c = util.inspect.colors[color];
return c ? util.format("\x1B[%sm%s\x1B[%sm", c[0], text, c[1]) : text;
}
console.log(C("green", "Yai!"));
console.log("Supported colors: %s", Object.keys(util.inspect.colors));
@walling
Copy link
Author

walling commented Dec 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment