Socket
Socket
Sign inDemoInstall

irc-colors

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

irc-colors - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.npmignore

258

lib/irc-colors.js

@@ -1,144 +0,124 @@

(function() {
var addGetters, bg, c, code, color, colorArr, colors, f1, fg, funcs, i, name1, pos2, style, styles, _i, _len;
colors = {
'00': ['white'],
'01': ['black'],
'02': ['navy'],
'03': ['green'],
'04': ['red'],
'05': ['brown', 'maroon'],
'06': ['purple', 'violet'],
'07': ['olive'],
'08': ['yellow'],
'09': ['lightgreen', 'lime'],
'10': ['teal', 'bluecyan'],
'11': ['cyan', 'aqua'],
'12': ['blue', 'royal'],
'13': ['pink', 'lightpurple', 'fuchsia'],
'14': ['gray', 'grey'],
'15': ['lightgray', 'lightgrey', 'silver']
var Hash = require('hashish');
var colors = {
'00': ['white'],
'01': ['black'],
'02': ['navy'],
'03': ['green'],
'04': ['red'],
'05': ['brown', 'maroon'],
'06': ['purple', 'violet'],
'07': ['olive'],
'08': ['yellow'],
'09': ['lightgreen', 'lime'],
'10': ['teal', 'bluecyan'],
'11': ['cyan', 'aqua'],
'12': ['blue', 'royal'],
'13': ['pink', 'lightpurple', 'fuchsia'],
'14': ['gray', 'grey'],
'15': ['lightgray', 'lightgrey', 'silver']
};
var styles = {
'\x00': 'normal',
'\x01': 'underline',
'\x02': 'bold',
'\x16': 'italic'
};
// coloring character
var c = '\x03';
var pos2 = c.length + 2;
// make color functions for both foreground and background
Hash(colors).forEach(function(colornames, code) {
// foreground
var fg = function(str) {
return c + code + str + c;
};
styles = {
'\x00': 'normal',
'\x01': 'underline',
'\x02': 'bold',
'\x16': 'italic'
};
module.exports = funcs = {};
c = '\x03';
pos2 = c.length + 2;
for (i in colors) {
colorArr = colors[i];
fg = (function(i) {
return function(str) {
return "" + c + i + str + c;
};
})(i);
bg = (function(i) {
return function(str) {
var pos;
pos = str.indexOf(c);
if (pos !== 0) {
return "" + c + "01," + i + str + c;
} else {
return "" + (str.substr(pos, pos2)) + "," + i + (str.substr(pos2));
}
};
})(i);
for (_i = 0, _len = colorArr.length; _i < _len; _i++) {
color = colorArr[_i];
funcs[color] = fg;
funcs['bg' + color] = bg;
}
}
for (code in styles) {
style = styles[code];
funcs[style] = (function(code) {
return function(str) {
return "" + code + str + code;
};
})(code);
}
funcs.rainbow = function(str) {
var c, rainbowColors, s, _j, _len2, _ref;
rainbowColors = ['red', 'olive', 'yellow', 'green', 'blue', 'navy', 'violet'];
i = 0;
s = '';
_ref = str.split('');
for (_j = 0, _len2 = _ref.length; _j < _len2; _j++) {
c = _ref[_j];
if (c !== ' ') {
s += funcs[rainbowColors[i++ % rainbowColors.length]](c);
// background
var bg = function(str) {
var pos = str.indexOf(c);
if (pos !== 0) {
return c + '01,' + code + str + c;
} else {
return (str.substr(pos, pos2)) + ',' + code + (str.substr(pos2));
}
}
return s;
};
colornames.forEach(function(color) {
exports[color] = fg;
exports['bg' + color] = bg;
});
});
// style functions
Hash(styles).forEach(function(style, code) {
exports[style] = function(str) {
return code + str + code;
};
addGetters = function(name1, f1) {
var f2, name2, _results;
_results = [];
for (name2 in funcs) {
f2 = funcs[name2];
if (name1 !== name2) {
_results.push(f1.__defineGetter__(name2, (function(name2, f2) {
return function() {
var newF;
newF = function(str) {
return f2(f1(str));
};
addGetters(name2, newF);
return newF;
};
})(name2, f2)));
}
}
return _results;
};
for (name1 in funcs) {
f1 = funcs[name1];
addGetters(name1, f1);
}
module.exports.global = function() {
var addGlobalGetters, f1, irc, name1, t, _results;
t = null;
irc = {};
String.prototype.__defineGetter__('irc', function() {
t = this;
return irc;
});
// extras
exports.rainbow = function(str) {
var rainbow = ['red', 'olive', 'yellow', 'green',
'blue', 'navy', 'violet']
, l = rainbow.length
, i = 0
return str
.split('')
.map(function(c) {
return c !== ' ' ? exports[rainbow[i++ % l]](c) : c;
})
.join('');
};
// adds all functions to each other so they can be chained
var addGetters = function(f1, name) {
Hash(exports).exclude([name]).forEach(function(f2, name) {
f1.__defineGetter__(name, function() {
var f = function(str) { return f2(f1(str)); };
addGetters(f, name);
return f;
});
addGlobalGetters = function(name1, f1) {
var f2, name2, _results;
_results = [];
for (name2 in funcs) {
f2 = funcs[name2];
if (name1 !== name2) {
_results.push(f1.__defineGetter__(name2, (function(name2, f2) {
return function() {
var newF;
newF = function(str) {
return f2(f1(t));
};
addGlobalGetters(name2, newF);
return newF;
};
})(name2, f2)));
}
}
return _results;
};
_results = [];
for (name1 in funcs) {
f1 = funcs[name1];
if (name1 !== 'global') {
_results.push(irc[name1] = (function(name1, f1) {
var newF;
newF = function() {
return f1(t);
};
addGlobalGetters(name1, newF);
return newF;
})(name1, f1));
}
}
return _results;
});
};
Hash(exports).forEach(function(f, name) {
addGetters(f, name);
});
// adds functions to global String object
exports.global = function() {
var t, irc = {};
String.prototype.__defineGetter__('irc', function() {
t = this;
return irc;
});
var addGlobalGetters = function(f1, name) {
Hash(exports).exclude([name]).forEach(function(f2, name) {
f1.__defineGetter__(name, function() {
var f = function(str) { return f2(f1(t)); };
addGetters(f, name);
return f;
});
});
};
}).call(this);
Hash(exports).exclude(['global']).forEach(function(f1, name) {
var f = function() { return f1(t); };
addGlobalGetters(f, name);
irc[name] = f;
});
};
{
"name": "irc-colors",
"description": "Color and formatting for irc made easy.",
"keywords": ["irc", "color", "colour"],
"version": "1.0.1",
"keywords": [
"irc",
"color",
"colour"
],
"version": "1.0.2",
"repository": {

@@ -12,2 +16,5 @@ "type": "git",

"main": "./lib/irc-colors.js",
"scripts": {
"test": "vows test/*-test.js --spec"
},
"directories": {

@@ -19,9 +26,14 @@ "lib": "./lib"

},
"devDependencies" : {
"irc-js": ">=0.2.26"
"dependencies": {
"hashish": "0.0.x"
},
"licenses": [ {
"type": "MIT",
"url" : "http://github.com/fent/irc-colors.js/raw/master/LICENSE"
}]
}
"devDependencies": {
"vows": "0.5.x"
},
"licenses": [
{
"type": "MIT",
"url": "http://github.com/fent/irc-colors.js/raw/master/LICENSE"
}
]
}

@@ -1,12 +0,10 @@

Install
------------
# irc.colors.js [![Build Status](https://secure.travis-ci.org/fent/irc-colors.js.png)](http://travis-ci.org/fent/irc-colors.js)
npm install irc-colors
Easily use colored output and formatting in your irc bots.
Usage
------------------
# Usage
```javascript
c = require('irc-colors');
var c = require('irc-colors');
...

@@ -37,4 +35,4 @@ ircbot.say('#chan', c.blue('hello everyone')); // prints blue text

Colors
--------------
## Colors
![colors](https://github.com/fent/irc-colors.js/raw/master/img/colors.png)

@@ -47,10 +45,27 @@

Styles
------------
## Styles
![styles](https://github.com/fent/irc-colors.js/raw/master/img/styles.png)
Extras
-----------
## Extras
![extras](https://github.com/fent/irc-colors.js/raw/master/img/extras.png)
# Install
npm install irc-colors
# Tests
Tests are written with [vows](http://vowsjs.org/)
```bash
npm test
```
# License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc