commit 270314c42b09ba393ab64598e375a53ce35010df Author: Marak Squires Date: Fri Jun 11 02:56:25 2010 -0400 first commit diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..c285ce6 --- /dev/null +++ b/ReadMe.md @@ -0,0 +1 @@ +colors are awesome yo \ No newline at end of file diff --git a/colors.js b/colors.js new file mode 100644 index 0000000..7ecdc80 --- /dev/null +++ b/colors.js @@ -0,0 +1,24 @@ +['bold', 'grey', 'yellow', 'red', 'green', 'white', 'cyan'].forEach(function (style) { + Object.defineProperty(String.prototype, style, { + get: function () { + return stylize(this, style); + } + }); +}); + +function stylize(str, style) { + var styles = { + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'yellow' : [33, 39], + 'cyan' : [36, 39], + 'white' : [37, 39], + 'green' : [32, 39], + 'red' : [31, 39], + 'grey' : [90, 39], + }; + return '\033[' + styles[style][0] + 'm' + str + + '\033[' + styles[style][1] + 'm'; +}; +