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.3.3 to 1.4.0

73

lib/irc-colors.js

@@ -0,1 +1,3 @@

'use strict';
const colors = {

@@ -28,3 +30,3 @@ '00': ['white'],

const styleChars = {};
Object.keys(styles).forEach(function(key) {
Object.keys(styles).forEach((key) => {
styleChars[styles[key]] = true;

@@ -43,10 +45,8 @@ });

// Make color functions for both foreground and background.
Object.keys(colors).forEach(function(code) {
Object.keys(colors).forEach((code) => {
// Foreground.
var fg = function(str) {
return c + code + zero + str + c;
};
var fg = str => c + code + zero + str + c;
// Background.
var bg = function(str) {
var bg = (str) => {
var pos = str.indexOf(c);

@@ -60,3 +60,3 @@ if (pos !== 0) {

colors[code].forEach(function(color) {
colors[code].forEach((color) => {
allColors.fg.push(color);

@@ -70,7 +70,5 @@ allColors.bg.push('bg' + color);

// Style functions.
Object.keys(styles).forEach(function(style) {
Object.keys(styles).forEach((style) => {
var code = styles[style];
exports[style] = function(str) {
return code + str + code;
};
exports[style] = str => code + str + code;
});

@@ -80,3 +78,3 @@

const custom = {
rainbow: function(str, colorArr) {
rainbow: (str, colorArr) => {
var rainbow = [

@@ -91,5 +89,3 @@ 'red', 'olive', 'yellow', 'green', 'blue', 'navy', 'violet'

.split('')
.map(function(c) {
return c !== ' ' ? exports[colorArr[i++ % l]](c) : c;
})
.map(c => c !== ' ' ? exports[colorArr[i++ % l]](c) : c)
.join('');

@@ -99,3 +95,3 @@ },

Object.keys(custom).forEach(function(extra) {
Object.keys(custom).forEach((extra) => {
allColors.custom.push(extra);

@@ -107,15 +103,12 @@ exports[extra] = custom[extra];

const extras = {
stripColors: function(str) {
return str.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, '');
},
stripColors: str => str.replace(/\x03\d{0,2}(,\d{0,2}|\x02\x02)?/g, ''),
stripStyle: function(str) {
stripStyle: (str) => {
var path = [];
var i, len, char;
for (i = 0, len = str.length; i < len; i++) {
char = str[i];
for (let i = 0, len = str.length; i < len; i++) {
let char = str[i];
if (styleChars[char] || char === c) {
var lastChar = path[path.length - 1];
let lastChar = path[path.length - 1];
if (lastChar && lastChar[0] === char) {
var p0 = lastChar[1];
let p0 = lastChar[1];
// Don't strip out styles with no characters inbetween.

@@ -137,6 +130,6 @@ // And don't strip out color codes.

// Traverse list backwards to make removing less complicated.
for (i = path.length - 1; i >= 0; i--) {
char = path[i];
for (let i = path.length - 1; i >= 0; i--) {
let char = path[i];
if (char[0] !== c) {
var pos = char[1];
let pos = char[1];
str = str.slice(0, pos) + str.slice(pos + 1);

@@ -148,8 +141,6 @@ }

stripColorsAndStyle: function(str) {
return exports.stripColors(exports.stripStyle(str));
},
stripColorsAndStyle: str => exports.stripColors(exports.stripStyle(str)),
};
Object.keys(extras).forEach(function(extra) {
Object.keys(extras).forEach((extra) => {
allColors.extras.push(extra);

@@ -161,9 +152,9 @@ exports[extra] = extras[extra];

function addGetters(fn, types) {
Object.keys(allColors).forEach(function(type) {
Object.keys(allColors).forEach((type) => {
if (types.indexOf(type) > -1) { return; }
allColors[type].forEach(function(color) {
allColors[type].forEach((color) => {
if (fn[color] != null) { return; }
Object.defineProperty(fn, color, {
get: function() {
var f = function(str) { return exports[color](fn(str)); };
get: () => {
var f = str => exports[color](fn(str));
addGetters(f, [].concat(types, type));

@@ -177,4 +168,4 @@ return f;

Object.keys(allColors).forEach(function(type) {
allColors[type].forEach(function(color) {
Object.keys(allColors).forEach((type) => {
allColors[type].forEach((color) => {
addGetters(exports[color], [type]);

@@ -186,3 +177,3 @@ });

// Adds functions to global String object.
exports.global = function() {
exports.global = () => {
var str, irc = {};

@@ -196,4 +187,4 @@

for (var type in allColors) {
allColors[type].forEach(function(color) {
var fn = function() { return exports[color](str); };
allColors[type].forEach((color) => {
var fn = () => exports[color](str);
addGetters(fn, [type]);

@@ -200,0 +191,0 @@ irc[color] = fn;

@@ -9,3 +9,3 @@ {

],
"version": "1.3.3",
"version": "1.4.0",
"repository": {

@@ -27,9 +27,9 @@ "type": "git",

"devDependencies": {
"istanbul": "*",
"vows": "*"
"istanbul": "^0.4.5",
"vows": "^0.8.1"
},
"engines": {
"node": ">=0.12"
"node": ">=4"
},
"license": "MIT"
}

@@ -69,3 +69,3 @@ # irc.colors.js

ircbot.on('message', function(from, message) {
ircbot.on('message', (from, message) => {
console.log(c.stripColorsAndStyle(message));

@@ -72,0 +72,0 @@ });

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