mirror of
https://github.com/flynx/colors.js.git
synced 2025-10-29 11:00:11 +00:00
added some documentation to colors.js, replaced hard tabs with soft tabs, adjusted identation for sytle purposes, bumped version to 0.3.0. want to research package.json formats a bit more
This commit is contained in:
parent
96f8cd5626
commit
88509012ab
@ -8,7 +8,7 @@
|
|||||||
sys.puts('hello'.green); // outputs green text
|
sys.puts('hello'.green); // outputs green text
|
||||||
sys.puts('i like cake and pies'.underline.red) // outputs red underlined 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('inverse the color'.inverse); // inverses the color
|
||||||
sys.puts('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)
|
sys.puts('OMG Rainbows!'.rainbow); // rainbow (ignores spaces)
|
||||||
|
|
||||||
<h2>colors and styles!</h2>
|
<h2>colors and styles!</h2>
|
||||||
- bold
|
- bold
|
||||||
@ -27,4 +27,4 @@
|
|||||||
|
|
||||||
### Authors
|
### Authors
|
||||||
|
|
||||||
#### Alexis Sellier (cloudhead) , Marak Squires , Justin Campbell
|
#### Alexis Sellier (cloudhead) , Marak Squires , Justin Campbell
|
||||||
|
|||||||
80
colors.js
80
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) {
|
['bold', 'underline', 'italic', 'inverse', 'grey', 'yellow', 'red', 'green', 'blue', 'white', 'cyan', 'magenta'].forEach(function (style) {
|
||||||
Object.defineProperty(String.prototype, style, {
|
Object.defineProperty(String.prototype, style, {
|
||||||
get: function () {
|
get: function () {
|
||||||
return stylize(this, style);
|
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', {
|
Object.defineProperty(String.prototype, 'rainbow', {
|
||||||
get: function () {
|
get: function () {
|
||||||
var rainbowcolors = ['red','yellow','green','blue','magenta']; //RoY G BiV
|
var rainbowcolors = ['red','yellow','green','blue','magenta']; //RoY G BiV
|
||||||
var exploded = this.split("");
|
var exploded = this.split("");
|
||||||
var i=0;
|
var i=0;
|
||||||
exploded = exploded.map(function(letter) {
|
exploded = exploded.map(function(letter) {
|
||||||
if (letter==" ") {
|
if (letter==" ") {
|
||||||
return letter;
|
return letter;
|
||||||
} else {
|
}
|
||||||
return stylize(letter,rainbowcolors[i++ % rainbowcolors.length]);
|
else {
|
||||||
}
|
return stylize(letter,rainbowcolors[i++ % rainbowcolors.length]);
|
||||||
});
|
}
|
||||||
return exploded.join("");
|
});
|
||||||
}
|
return exploded.join("");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function stylize(str, style) {
|
function stylize(str, style) {
|
||||||
var styles = {
|
var styles = {
|
||||||
//styles
|
//styles
|
||||||
'bold' : [1, 22],
|
'bold' : [1, 22],
|
||||||
'italic' : [3, 23],
|
'italic' : [3, 23],
|
||||||
'underline' : [4, 24],
|
'underline' : [4, 24],
|
||||||
'inverse' : [7, 27],
|
'inverse' : [7, 27],
|
||||||
//grayscale
|
//grayscale
|
||||||
'white' : [37, 39],
|
'white' : [37, 39],
|
||||||
'grey' : [90, 39],
|
'grey' : [90, 39],
|
||||||
'black' : [90, 39],
|
'black' : [90, 39],
|
||||||
//colors
|
//colors
|
||||||
'blue' : [34, 39],
|
'blue' : [34, 39],
|
||||||
'cyan' : [36, 39],
|
'cyan' : [36, 39],
|
||||||
'green' : [32, 39],
|
'green' : [32, 39],
|
||||||
'magenta' : [35, 39],
|
'magenta' : [35, 39],
|
||||||
'red' : [31, 39],
|
'red' : [31, 39],
|
||||||
'yellow' : [33, 39]
|
'yellow' : [33, 39]
|
||||||
};
|
};
|
||||||
return '\033[' + styles[style][0] + 'm' + str +
|
return '\033[' + styles[style][0] + 'm' + str +
|
||||||
'\033[' + styles[style][1] + 'm';
|
'\033[' + styles[style][1] + 'm';
|
||||||
};
|
};
|
||||||
@ -1,6 +1,6 @@
|
|||||||
var sys = require('sys');
|
var sys = require('sys');
|
||||||
var colors = require('./colors');
|
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('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
|
sys.puts('Chains are also cool.'.bold.italic.underline.red); // styles not widely supported
|
||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "colors",
|
"name": "colors",
|
||||||
"description": "get colors in your node.js console like what",
|
"description": "get colors in your node.js console like what",
|
||||||
"version": "0.2.0",
|
"version": "0.3.0",
|
||||||
"author": "Marak Squires",
|
"author": "Marak Squires",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -10,7 +10,5 @@
|
|||||||
"engine": [
|
"engine": [
|
||||||
"node >=0.1.90"
|
"node >=0.1.90"
|
||||||
],
|
],
|
||||||
"main": "colors" ,
|
"main": "colors"
|
||||||
"licenses": [{ "type": "MIT" }]
|
|
||||||
"contributers": ["Alexis Sellier", "Justin Campbell"]
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user