irc-colors
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -1,4 +0,1 @@ | ||
var Hash = require('hashish'); | ||
var colors = { | ||
@@ -36,5 +33,8 @@ '00': ['white'], | ||
var allColors = { | ||
fg: [], bg: [], styles: Object.keys(styles), | ||
}; | ||
// Make color functions for both foreground and background. | ||
Hash(colors).forEach(function(colornames, code) { | ||
Object.keys(colors).forEach(function(code) { | ||
// Foreground. | ||
@@ -51,7 +51,9 @@ var fg = function(str) { | ||
} else { | ||
return (str.substr(pos, pos2)) + ',' + code + (str.substr(pos2)); | ||
return (str.substr(pos, pos2)) + ',' + code + (str.substr(pos2 + 2)); | ||
} | ||
}; | ||
colornames.forEach(function(color) { | ||
colors[code].forEach(function(color) { | ||
allColors.fg.push(color); | ||
allColors.bg.push('bg' + color); | ||
exports[color] = fg; | ||
@@ -64,3 +66,4 @@ exports['bg' + color] = bg; | ||
// Style functions. | ||
Hash(styles).forEach(function(code, style) { | ||
Object.keys(styles).forEach(function(style) { | ||
var code = styles[style]; | ||
exports[style] = function(str) { | ||
@@ -73,42 +76,53 @@ return code + str + code; | ||
// Extras. | ||
exports.rainbow = function(str, colorArr) { | ||
var rainbow = ['red', 'olive', 'yellow', 'green', | ||
'blue', 'navy', 'violet']; | ||
colorArr = colorArr ? colorArr : rainbow; | ||
var l = colorArr.length; | ||
var i = 0; | ||
var extras = { | ||
rainbow: function(str, colorArr) { | ||
var rainbow = ['red', 'olive', 'yellow', 'green', | ||
'blue', 'navy', 'violet']; | ||
colorArr = colorArr || rainbow; | ||
var l = colorArr.length; | ||
var i = 0; | ||
return str | ||
.split('') | ||
.map(function(c) { | ||
return c !== ' ' ? exports[colorArr[i++ % l]](c) : c; | ||
}) | ||
.join(''); | ||
}; | ||
return str | ||
.split('') | ||
.map(function(c) { | ||
return c !== ' ' ? exports[colorArr[i++ % l]](c) : c; | ||
}) | ||
.join(''); | ||
}, | ||
exports.stripColors = function(str) { | ||
return str.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, ''); | ||
}; | ||
stripColors: function(str) { | ||
return str.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, ''); | ||
}, | ||
exports.stripStyle = function(str) { | ||
return str.replace(/([\x0F\x02\x16\x1F])(.+)\1/g, '$2'); | ||
}; | ||
stripStyle: function(str) { | ||
return str.replace(/([\x0F\x02\x16\x1F])(.+)\1/g, '$2'); | ||
}, | ||
exports.stripColorsAndStyle = function(str) { | ||
return exports.stripColors(exports.stripStyle(str)); | ||
stripColorsAndStyle: function(str) { | ||
return exports.stripColors(exports.stripStyle(str)); | ||
}, | ||
}; | ||
Object.keys(extras).forEach(function(extra) { | ||
exports[extra] = extras[extra]; | ||
}); | ||
// 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; | ||
function addGetters(fn, types) { | ||
Object.keys(allColors).forEach(function(type) { | ||
if (types.indexOf(type) > -1) { return; } | ||
allColors[type].forEach(function(color) { | ||
fn.__defineGetter__(color, function() { | ||
var f = function(str) { return exports[color](fn(str)); }; | ||
addGetters(f, [].concat(types, type)); | ||
return f; | ||
}); | ||
}); | ||
}); | ||
}; | ||
} | ||
Hash(exports).forEach(function(f, name) { | ||
addGetters(f, name); | ||
Object.keys(allColors).forEach(function(type) { | ||
allColors[type].forEach(function(color) { | ||
addGetters(exports[color], [type]); | ||
}); | ||
}); | ||
@@ -119,24 +133,21 @@ | ||
exports.global = function() { | ||
var t, irc = {}; | ||
var str, irc = {}; | ||
String.prototype.__defineGetter__('irc', function() { | ||
t = this; | ||
str = this; | ||
return irc; | ||
}); | ||
var addGlobalGetters = function(f1, name) { | ||
Hash(exports).exclude([name]).forEach(function(f2, name) { | ||
f1.__defineGetter__(name, function() { | ||
var f = function() { return f2(f1(t)); }; | ||
addGetters(f, name); | ||
return f; | ||
}); | ||
for (var type in allColors) { | ||
allColors[type].forEach(function(color) { | ||
var fn = function() { return exports[color](str); }; | ||
addGetters(fn, [type]); | ||
irc[color] = fn; | ||
}); | ||
}; | ||
} | ||
Hash(exports).exclude(['global']).forEach(function(f1, name) { | ||
var f = function() { return f1(t); }; | ||
addGlobalGetters(f, name); | ||
irc[name] = f; | ||
Object.keys(extras).forEach(function(extra) { | ||
irc[extra] = function() { | ||
return extras[extra](str); }; | ||
}); | ||
}; |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"repository": { | ||
@@ -18,3 +18,3 @@ "type": "git", | ||
"scripts": { | ||
"test": "vows test/*-test.js --spec" | ||
"test": "istanbul cover vows -- --spec test/*-test.js" | ||
}, | ||
@@ -24,6 +24,4 @@ "directories": { | ||
}, | ||
"dependencies": { | ||
"hashish": "~0.0.4" | ||
}, | ||
"devDependencies": { | ||
"istanbul": "*", | ||
"vows": "*" | ||
@@ -30,0 +28,0 @@ }, |
@@ -34,3 +34,3 @@ # irc.colors.js | ||
Global syntax was inspired by [colors.js](https://github.com/Marak/colors.js) and because of that, there's possibility that you might want to use that module along with this one. That's why the *irc* property of a String needs to be called first to use the formatting functions. | ||
Global syntax was inspired by [colors.js](https://github.com/marak/colors.js) and because of that, there's possibility that you might want to use that module along with this one. That's why the *irc* property of a String needs to be called first to use the formatting functions. | ||
@@ -37,0 +37,0 @@ |
@@ -20,6 +20,2 @@ var vows = require('vows'); | ||
], | ||
'blue.white': [ | ||
txt, | ||
'\x0300' + zero + '\x0312' + zero + txt + '\x03\x03' | ||
], | ||
'bold': [ | ||
@@ -41,9 +37,9 @@ txt, | ||
], | ||
'bold.white.black': [ | ||
'bold.white': [ | ||
txt, | ||
'\x0301' + zero + '\x0300' + zero + '\x02' + txt + '\x02\x03\x03' | ||
'\x0300' + zero + '\x02' + txt + '\x02\x03' | ||
], | ||
'white.black.italic': [ | ||
'white.italic': [ | ||
txt, | ||
'\x16\x0301' + zero + '\x0300' + zero + txt + '\x03\x03\x16' | ||
'\x16\x0300' + zero + txt + '\x03\x16' | ||
], | ||
@@ -54,17 +50,25 @@ 'bggray': [ | ||
], | ||
'blue.bgblack': [ | ||
txt, | ||
'\x0312,01' + txt + '\x03' | ||
], | ||
'rainbow': [ | ||
'hello', | ||
'hello u', | ||
'\x0304' + zero + 'h\x03\x0307' + zero + 'e\x03\x0308' + zero + | ||
'l\x03\x0303' + zero + 'l\x03\x0312' + zero + 'o\x03' | ||
'l\x03\x0303' + zero + 'l\x03\x0312' + zero + 'o\x03 \x0302' + zero + | ||
'u\x03' | ||
], | ||
'rainbow.stripColors': ['hello', 'hello'], | ||
'bold.black.stripStyle': [ | ||
txt, | ||
'stripColors': [ | ||
'\x0304' + zero + 'h\x03\x0307' + zero + 'e\x03\x0308' + zero + | ||
'l\x03\x0303' + zero + 'l\x03\x0312' + zero + 'o\x03', | ||
'hello'], | ||
'stripStyle': [ | ||
'\x0301' + zero + '\x02' + txt + '\x02\x03', | ||
'\x0301' + zero + txt + '\x03' | ||
], | ||
'black.bold.stripStyle': [ | ||
txt, | ||
'\x0301' + zero + txt + '\x03' | ||
], | ||
'rainbow.bold.stripColorsAndStyle': ['hello', 'hello'] | ||
'stripColorsAndStyle': [ | ||
'\x02\x0304' + zero + 'h\x03\x0307' + zero + 'e\x03\x0308' + zero + | ||
'l\x03\x0303' + zero + 'l\x03\x0312' + zero + 'o\x03\x02', | ||
'hello' | ||
] | ||
}; | ||
@@ -71,0 +75,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
22287
0
250
2
- Removedhashish@~0.0.4
- Removedarray-buffer-byte-length@1.0.1(transitive)
- Removedarraybuffer.prototype.slice@1.0.3(transitive)
- Removedavailable-typed-arrays@1.0.7(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removeddata-view-buffer@1.0.1(transitive)
- Removeddata-view-byte-length@1.0.1(transitive)
- Removeddata-view-byte-offset@1.0.0(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removedes-abstract@1.23.5(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedes-set-tostringtag@2.0.3(transitive)
- Removedes-to-primitive@1.2.1(transitive)
- Removedfor-each@0.3.3(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedfunction.prototype.name@1.1.6(transitive)
- Removedfunctions-have-names@1.2.3(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedget-symbol-description@1.0.2(transitive)
- Removedglobalthis@1.0.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-bigints@1.0.2(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhas-tostringtag@1.0.2(transitive)
- Removedhashish@0.0.4(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinternal-slot@1.0.7(transitive)
- Removedis-array-buffer@3.0.4(transitive)
- Removedis-bigint@1.0.4(transitive)
- Removedis-boolean-object@1.1.2(transitive)
- Removedis-callable@1.2.7(transitive)
- Removedis-data-view@1.0.1(transitive)
- Removedis-date-object@1.0.5(transitive)
- Removedis-negative-zero@2.0.3(transitive)
- Removedis-number-object@1.0.7(transitive)
- Removedis-regex@1.1.4(transitive)
- Removedis-shared-array-buffer@1.0.3(transitive)
- Removedis-string@1.0.7(transitive)
- Removedis-symbol@1.0.4(transitive)
- Removedis-typed-array@1.1.13(transitive)
- Removedis-weakref@1.0.2(transitive)
- Removedisarray@2.0.5(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedobject.assign@4.1.5(transitive)
- Removedpossible-typed-array-names@1.0.0(transitive)
- Removedregexp.prototype.flags@1.5.3(transitive)
- Removedsafe-array-concat@1.1.2(transitive)
- Removedsafe-regex-test@1.0.3(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedset-function-name@2.0.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedstring.prototype.trim@1.2.9(transitive)
- Removedstring.prototype.trimend@1.0.8(transitive)
- Removedstring.prototype.trimstart@1.0.8(transitive)
- Removedtraverse@0.6.10(transitive)
- Removedtyped-array-buffer@1.0.2(transitive)
- Removedtyped-array-byte-length@1.0.1(transitive)
- Removedtyped-array-byte-offset@1.0.2(transitive)
- Removedtyped-array-length@1.0.6(transitive)
- Removedtypedarray.prototype.slice@1.0.3(transitive)
- Removedunbox-primitive@1.0.2(transitive)
- Removedwhich-boxed-primitive@1.0.2(transitive)
- Removedwhich-typed-array@1.1.15(transitive)