diff --git a/ReadMe.md b/ReadMe.md index 3582d35..4d965e3 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -8,7 +8,7 @@ sys.puts('hello'.green); // outputs green text sys.puts('i like cake and pies'.underline.red) // outputs red underlined text sys.puts('inverse the color'.inverse); // inverses the color - sys.puts('OMG Rainbows!'.rainbow); // rainbow (ignores spaces) + sys.puts('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)

colors and styles!

- bold @@ -27,4 +27,4 @@ ### Authors -#### Alexis Sellier (cloudhead) , Marak Squires , Justin Campbell \ No newline at end of file +#### Alexis Sellier (cloudhead) , Marak Squires , Justin Campbell diff --git a/colors.js b/colors.js index 02d2865..c56ff20 100644 --- a/colors.js +++ b/colors.js @@ -23,49 +23,53 @@ THE SOFTWARE. */ +// prototypes the string object to have additional method calls that add terminal colors ['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'].forEach(function (style) { - Object.defineProperty(String.prototype, style, { - get: function () { - return stylize(this, style); - } - }); + Object.defineProperty(String.prototype, style, { + get: function () { + return stylize(this, style); + } + }); }); +// prototypes string with method "rainbow" +// rainbow will apply a the color spectrum to a string, changing colors every letter Object.defineProperty(String.prototype, 'rainbow', { - get: function () { - var rainbowcolors = ['red','yellow','green','blue','magenta']; //RoY G BiV - var exploded = this.split(""); - var i=0; - exploded = exploded.map(function(letter) { - if (letter==" ") { - return letter; - } else { - return stylize(letter,rainbowcolors[i++ % rainbowcolors.length]); - } - }); - return exploded.join(""); - } + get: function () { + var rainbowcolors = ['red','yellow','green','blue','magenta']; //RoY G BiV + var exploded = this.split(""); + var i=0; + exploded = exploded.map(function(letter) { + if (letter==" ") { + return letter; + } + else { + return stylize(letter,rainbowcolors[i++ % rainbowcolors.length]); + } + }); + return exploded.join(""); + } }); function stylize(str, style) { - var styles = { - //styles - 'bold' : [1, 22], - 'italic' : [3, 23], - 'underline' : [4, 24], - 'inverse' : [7, 27], - //grayscale - 'white' : [37, 39], - 'grey' : [90, 39], - 'black' : [90, 39], - //colors - 'blue' : [34, 39], - 'cyan' : [36, 39], - 'green' : [32, 39], - 'magenta' : [35, 39], - 'red' : [31, 39], - 'yellow' : [33, 39] - }; - return '\033[' + styles[style][0] + 'm' + str + - '\033[' + styles[style][1] + 'm'; + var styles = { + //styles + 'bold' : [1, 22], + 'italic' : [3, 23], + 'underline' : [4, 24], + 'inverse' : [7, 27], + //grayscale + 'white' : [37, 39], + 'grey' : [90, 39], + 'black' : [90, 39], + //colors + 'blue' : [34, 39], + 'cyan' : [36, 39], + 'green' : [32, 39], + 'magenta' : [35, 39], + 'red' : [31, 39], + 'yellow' : [33, 39] + }; + return '\033[' + styles[style][0] + 'm' + str + + '\033[' + styles[style][1] + 'm'; }; \ No newline at end of file diff --git a/example.js b/example.js index a990998..5c08c9c 100644 --- a/example.js +++ b/example.js @@ -1,6 +1,6 @@ var sys = require('sys'); var colors = require('./colors'); -sys.puts('Colors are fun!'.rainbow); +sys.puts('Rainbows are fun!'.rainbow); sys.puts('So '.italic + 'are'.underline + ' styles! '.bold + 'inverse'.inverse); // styles not widely supported sys.puts('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported \ No newline at end of file diff --git a/package.json b/package.json index 15df8fa..61e4a09 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "colors", "description": "get colors in your node.js console like what", - "version": "0.2.0", + "version": "0.3.0", "author": "Marak Squires", "repository": { "type": "git", @@ -10,7 +10,5 @@ "engine": [ "node >=0.1.90" ], - "main": "colors" , - "licenses": [{ "type": "MIT" }] - "contributers": ["Alexis Sellier", "Justin Campbell"] + "main": "colors" }