irc-colors
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -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 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
70
0
17968
1
9
102
2
+ Addedhashish@0.0.x
+ Addedarray-buffer-byte-length@1.0.1(transitive)
+ Addedarraybuffer.prototype.slice@1.0.3(transitive)
+ Addedavailable-typed-arrays@1.0.7(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addeddata-view-buffer@1.0.1(transitive)
+ Addeddata-view-byte-length@1.0.1(transitive)
+ Addeddata-view-byte-offset@1.0.0(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddefine-properties@1.2.1(transitive)
+ Addedes-abstract@1.23.3(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.0.0(transitive)
+ Addedes-set-tostringtag@2.0.3(transitive)
+ Addedes-to-primitive@1.2.1(transitive)
+ Addedfor-each@0.3.3(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedfunction.prototype.name@1.1.6(transitive)
+ Addedfunctions-have-names@1.2.3(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedget-symbol-description@1.0.2(transitive)
+ Addedglobalthis@1.0.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-bigints@1.0.2(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhashish@0.0.4(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinternal-slot@1.0.7(transitive)
+ Addedis-array-buffer@3.0.4(transitive)
+ Addedis-bigint@1.0.4(transitive)
+ Addedis-boolean-object@1.1.2(transitive)
+ Addedis-callable@1.2.7(transitive)
+ Addedis-data-view@1.0.1(transitive)
+ Addedis-date-object@1.0.5(transitive)
+ Addedis-negative-zero@2.0.3(transitive)
+ Addedis-number-object@1.0.7(transitive)
+ Addedis-regex@1.1.4(transitive)
+ Addedis-shared-array-buffer@1.0.3(transitive)
+ Addedis-string@1.0.7(transitive)
+ Addedis-symbol@1.0.4(transitive)
+ Addedis-typed-array@1.1.13(transitive)
+ Addedis-weakref@1.0.2(transitive)
+ Addedisarray@2.0.5(transitive)
+ Addedobject-inspect@1.13.2(transitive)
+ Addedobject-keys@1.1.1(transitive)
+ Addedobject.assign@4.1.5(transitive)
+ Addedpossible-typed-array-names@1.0.0(transitive)
+ Addedregexp.prototype.flags@1.5.2(transitive)
+ Addedsafe-array-concat@1.1.2(transitive)
+ Addedsafe-regex-test@1.0.3(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedset-function-name@2.0.2(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstring.prototype.trim@1.2.9(transitive)
+ Addedstring.prototype.trimend@1.0.8(transitive)
+ Addedstring.prototype.trimstart@1.0.8(transitive)
+ Addedtraverse@0.6.10(transitive)
+ Addedtyped-array-buffer@1.0.2(transitive)
+ Addedtyped-array-byte-length@1.0.1(transitive)
+ Addedtyped-array-byte-offset@1.0.2(transitive)
+ Addedtyped-array-length@1.0.6(transitive)
+ Addedtypedarray.prototype.slice@1.0.3(transitive)
+ Addedunbox-primitive@1.0.2(transitive)
+ Addedwhich-boxed-primitive@1.0.2(transitive)
+ Addedwhich-typed-array@1.1.15(transitive)