irc-colors
Advanced tools
Comparing version
@@ -5,3 +5,3 @@ var irc = require('irc'); | ||
var channel = '#rolytest'; | ||
var client = new irc.Client('chat.freenode.net', 'rolybot1234', { | ||
var client = new irc.Client('bethere.fdfnet.net', 'rolybot1234', { | ||
channels: [channel] | ||
@@ -14,3 +14,4 @@ }); | ||
client.say(channel, 'italic: ' + c.italic(message)); | ||
client.say(channel, 'red: ' + c.red(message)); | ||
}); | ||
@@ -24,18 +24,18 @@ var Hash = require('hashish'); | ||
var styles = { | ||
'\x0F': 'normal', | ||
'\x1F': 'underline', | ||
'\x02': 'bold', | ||
'\x16': 'italic' | ||
normal : '\x0F', | ||
underline : '\x1F', | ||
bold : '\x02', | ||
italic : '\x16' | ||
}; | ||
// coloring character | ||
// Coloring character. | ||
var c = '\x03'; | ||
var pos2 = c.length + 2; | ||
var zero = '\u200B'; | ||
var zero = styles.bold + styles.bold; | ||
// make color functions for both foreground and background | ||
// Make color functions for both foreground and background. | ||
Hash(colors).forEach(function(colornames, code) { | ||
// foreground | ||
// Foreground. | ||
var fg = function(str) { | ||
@@ -45,3 +45,3 @@ return c + code + zero + str + c; | ||
// background | ||
// Background. | ||
var bg = function(str) { | ||
@@ -63,4 +63,4 @@ var pos = str.indexOf(c); | ||
// style functions | ||
Hash(styles).forEach(function(style, code) { | ||
// Style functions. | ||
Hash(styles).forEach(function(code, style) { | ||
exports[style] = function(str) { | ||
@@ -72,3 +72,3 @@ return code + str + code; | ||
// extras | ||
// Extras. | ||
exports.rainbow = function(str, colorArr) { | ||
@@ -90,7 +90,7 @@ var rainbow = ['red', 'olive', 'yellow', 'green', | ||
exports.stripColors = function(str) { | ||
return str.replace(/(\x03\d{0,2}(,\d{0,2})?|\u200B)/g, ''); | ||
return str.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, ''); | ||
}; | ||
exports.stripStyle = function(str) { | ||
return str.replace(/[\x0F\x02\x16\x1F]/g, ''); | ||
return str.replace(/([\x0F\x02\x16\x1F])(.+)\1/g, '$2'); | ||
}; | ||
@@ -102,3 +102,3 @@ | ||
// adds all functions to each other so they can be chained | ||
// Adds all functions to each other so they can be chained. | ||
var addGetters = function(f1, name) { | ||
@@ -119,3 +119,3 @@ Hash(exports).exclude([name]).forEach(function(f2, name) { | ||
// adds functions to global String object | ||
// Adds functions to global String object. | ||
exports.global = function() { | ||
@@ -122,0 +122,0 @@ var t, irc = {}; |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"repository": { | ||
@@ -12,0 +12,0 @@ "type": "git", |
@@ -1,6 +0,8 @@ | ||
# irc.colors.js [](http://travis-ci.org/fent/irc-colors.js) | ||
# irc.colors.js | ||
Easily use colored output and formatting in your irc bots. | ||
[](http://travis-ci.org/fent/irc-colors.js) [](https://gemnasium.com/fent/irc-colors.js) | ||
# Usage | ||
@@ -7,0 +9,0 @@ |
@@ -5,8 +5,66 @@ var vows = require('vows'); | ||
// activate global syntax | ||
// modifies the String prototype for a sugary syntax | ||
// Activate global syntax. | ||
// Modifies the String prototype for a sugary syntax. | ||
c.global(); | ||
var txt = 'test me'; | ||
var zero = c.bold(''); | ||
var tests = { | ||
'blue': [ | ||
txt, | ||
'\x0312' + zero + txt + '\x03' | ||
], | ||
'white': [ | ||
txt, | ||
'\x0300' + zero + txt + '\x03' | ||
], | ||
'blue.white': [ | ||
txt, | ||
'\x0300' + zero + '\x0312' + zero + txt + '\x03\x03' | ||
], | ||
'bold': [ | ||
txt, | ||
'\x02' + txt + '\x02' | ||
], | ||
'bold.grey': [ | ||
txt, | ||
'\x0314' + zero + '\x02' + txt + '\x02\x03' | ||
], | ||
'underline': [ | ||
txt, | ||
'\x1F' + txt + '\x1F' | ||
], | ||
'green.underline': [ | ||
txt, | ||
'\x1F\x0303' + zero + txt + '\x03\x1F' | ||
], | ||
'bold.white.black': [ | ||
txt, | ||
'\x0301' + zero + '\x0300' + zero + '\x02' + txt + '\x02\x03\x03' | ||
], | ||
'white.black.italic': [ | ||
txt, | ||
'\x16\x0301' + zero + '\x0300' + zero + txt + '\x03\x03\x16' | ||
], | ||
'bggray': [ | ||
txt, | ||
'\x0301,14' + txt + '\x03' | ||
], | ||
'rainbow': [ | ||
'hello', | ||
'\x0304' + zero + 'h\x03\x0307' + zero + 'e\x03\x0308' + zero + | ||
'l\x03\x0303' + zero + 'l\x03\x0312' + zero + 'o\x03' | ||
], | ||
'rainbow.stripColors': ['hello', 'hello'], | ||
'bold.black.stripStyle': [ | ||
txt, | ||
'\x0301' + zero + txt + '\x03' | ||
], | ||
'black.bold.stripStyle': [ | ||
txt, | ||
'\x0301' + zero + txt + '\x03' | ||
], | ||
'rainbow.bold.stripColorsAndStyle': ['hello', 'hello'] | ||
}; | ||
var txt = 'teeeeeest me'; | ||
var topicMacro = function(reg) { | ||
@@ -19,5 +77,4 @@ return { | ||
if (tests.hasOwnProperty(key)) { | ||
var fn = reg ? c : tests[key][0].irc | ||
, s = key.split('.') | ||
; | ||
var fn = reg ? c : tests[key][0].irc; | ||
var s = key.split('.'); | ||
@@ -38,28 +95,17 @@ for (var i in s) { | ||
var tests = { | ||
'blue' : [txt, '\x0312\u200B' + txt + '\x03'], | ||
'white' : [txt, '\x0300\u200B' + txt + '\x03'], | ||
'blue.white' : [txt, '\x0300\u200B\x0312\u200B' + txt + '\x03\x03'], | ||
'bold' : [txt, '\x02' + txt + '\x02'], | ||
'bold.grey' : [txt, '\x0314\u200B\x02' + txt + '\x02\x03'], | ||
'underline' : [txt, '\x1F' + txt + '\x1F'], | ||
'green.underline' : [txt, '\x1F\x0303\u200B' + txt + '\x03\x1F'], | ||
'bold.white.black' : [txt, '\x0301\u200B\x0300\u200B\x02' + txt + '\x02\x03\x03'], | ||
'white.black.italic' : [txt, '\x16\x0301\u200B\x0300\u200B' + txt + '\x03\x03\x16'], | ||
'bggray' : [txt, '\x0301,14' + txt + '\x03'], | ||
'rainbow' : ['hello', '\x0304\u200Bh\x03\x0307\u200Be\x03\x0308\u200Bl\x03\x0303\u200Bl\x03\x0312\u200Bo\x03'], | ||
'rainbow.stripColors' : ['hello', 'hello'], | ||
'bold.white.black.stripStyle' : [txt, '\x0301\u200B\x0300\u200B' + txt + '\x03\x03'], | ||
'rainbow.bold.stripColorsAndStyle' : ['hello', 'hello'] | ||
}; | ||
var regular = topicMacro(true); | ||
var globalSyntax = topicMacro(false); | ||
function equal(expectedStr, gotStr) { | ||
var expectedBuf = new Buffer(expectedStr, 'utf8'); | ||
var gotBuf = new Buffer(gotStr, 'utf8'); | ||
assert.deepEqual(expectedBuf, gotBuf); | ||
} | ||
function test(key) { | ||
regular[key] = function(topic) { | ||
assert.equal(topic[key], tests[key][1]); | ||
equal(topic[key], tests[key][1]); | ||
}; | ||
globalSyntax[key] = function(topic) { | ||
assert.equal(topic[key], tests[key][1]); | ||
equal(topic[key], tests[key][1]); | ||
}; | ||
@@ -75,4 +121,4 @@ } | ||
vows.describe('Test').addBatch({ | ||
'Using regular syntax': regular | ||
, 'Using global syntax': globalSyntax | ||
'Using regular syntax': regular, | ||
'Using global syntax': globalSyntax | ||
}).export(module); |
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
21832
1.49%234
25.13%88
2.33%