Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.2.1 to 1.3.0

115

lib/irc-colors.js

@@ -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

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