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

magicpen

Package Overview
Dependencies
Maintainers
2
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magicpen - npm Package Compare versions

Comparing version 4.8.3 to 4.9.0

16

lib/AnsiSerializer.js

@@ -96,10 +96,14 @@ var utils = require('./utils');

AnsiSerializer.prototype.text = function () {
var args = themeMapper(this.theme, arguments);
AnsiSerializer.prototype.text = function (options) {
var content = String(options.content);
if (content === '') {
return '';
}
var content = args[0];
if (args.length > 1) {
for (var i = args.length -1; i > 0; i -= 1) {
var styleName = args[i];
var styles = themeMapper(this.theme, options.styles);
if (styles.length > 0) {
for (var i = styles.length -1; i >= 0; i -= 1) {
var styleName = styles[i];
if (ansiStyles[styleName]) {

@@ -106,0 +110,0 @@ content = ansiStyles[styleName].open + content + ansiStyles[styleName].close;

@@ -41,3 +41,3 @@ var cssStyles = require('./cssStyles');

if (this[outputEntry.style]) {
result.push(this[outputEntry.style].apply(this, outputEntry.args));
result.push(this[outputEntry.style](outputEntry.args));
}

@@ -52,15 +52,16 @@ }, this);

ColoredConsoleSerializer.prototype.text = function () {
var args = themeMapper(this.theme, arguments);
var content = String(args[0]);
ColoredConsoleSerializer.prototype.text = function (options) {
var content = String(options.content);
if (content === '') {
return null;
return '';
}
var styles = themeMapper(this.theme, options.styles);
var result = ['%c' + content.replace(/%/g, '%%')];
var styleProperties = [];
if (args.length > 1) {
for (var i = 1; i < args.length; i += 1) {
var styleName = args[i];
if (styles.length > 0) {
for (var i = 0; i < styles.length; i += 1) {
var styleName = styles[i];
if (rgbRegexp.test(styleName)) {

@@ -67,0 +68,0 @@ if (styleName.substring(0, 2) === 'bg') {

@@ -5,3 +5,3 @@ var utils = require('./utils');

function createPadding(length) {
return { style: 'text', args: [duplicateText(' ', length)] };
return { style: 'text', args: { content: duplicateText(' ', length), styles: [] } };
}

@@ -12,3 +12,3 @@

return outputEntry.style === 'block' ||
(outputEntry.style === 'text' && String(outputEntry.args[0]).indexOf('\n') !== -1);
(outputEntry.style === 'text' && String(outputEntry.args.content).indexOf('\n') !== -1);
});

@@ -19,3 +19,3 @@ }

switch (outputEntry.style) {
case 'text': return String(outputEntry.args[0]).split('\n').map(function (line) {
case 'text': return String(outputEntry.args.content).split('\n').map(function (line) {
if (line === '') {

@@ -25,6 +25,6 @@ return [];

var args = [line].concat(outputEntry.args.slice(1));
var args = { content: line, styles: outputEntry.args.styles };
return [{ style: 'text', args: args }];
});
case 'block': return flattenBlocksInLines(outputEntry.args[0]);
case 'block': return flattenBlocksInLines(outputEntry.args);
default: return [];

@@ -49,2 +49,3 @@ }

var blockLines = flattenBlocksInOutputEntry(outputEntry);
var blockLinesLengths = blockLines.map(function (line) {

@@ -51,0 +52,0 @@ return utils.calculateLineSize(line).width;

@@ -24,3 +24,3 @@ var cssStyles = require('./cssStyles');

return this[outputEntry.style] ?
this[outputEntry.style].apply(this, outputEntry.args) :
this[outputEntry.style](outputEntry.args) :
'';

@@ -36,6 +36,10 @@ }, this);

HtmlSerializer.prototype.text = function () {
var args = themeMapper(this.theme, arguments);
HtmlSerializer.prototype.text = function (options) {
var content = String(options.content);
var content = String(args[0])
if (content === '') {
return '';
}
content = content
.replace(/&/g, '&amp;')

@@ -47,6 +51,9 @@ .replace(/ /g, '&nbsp;')

if (args.length > 1) {
var styles = themeMapper(this.theme, options.styles);
if (styles.length > 0) {
var styleProperties = [];
for (var j = 1; j < args.length; j += 1) {
var styleName = args[j];
for (var j = 0; j < styles.length; j += 1) {
var styleName = styles[j];
if (rgbRegexp.test(styleName)) {

@@ -53,0 +60,0 @@ if (styleName.substring(0, 2) === 'bg') {

@@ -25,3 +25,3 @@ /*global window*/

this.output = [[]];
this.styles = {};
this.styles = Object.create(null);
this.installedPlugins = [];

@@ -77,4 +77,3 @@ this._themes = {};

return utils.arrayEquals(Array.prototype.slice.call(a.args, 1),
Array.prototype.slice.call(b.args, 1));
return utils.arrayEquals(a.args.styles, b.args.styles);
}

@@ -91,3 +90,3 @@

var entry = line[i];
if (entry.style === 'text' && entry.args[0] === '') {
if (entry.style === 'text' && entry.args.content === '') {
continue;

@@ -98,4 +97,7 @@ }

result[result.length - 1] = {
style: entry.style,
args: [lastEntry.args[0] + entry.args[0]].concat(entry.args.slice(1))
style: lastEntry.style,
args: {
content: lastEntry.args.content + entry.args.content,
styles: lastEntry.args.styles
}
};

@@ -118,4 +120,9 @@ } else {

if (hasSameTextStyling(lastEntry, options)) {
options.args[0] = lastEntry.args[0] + options.args[0];
lastLine[lastLine.length - 1] = options;
lastLine[lastLine.length - 1] = {
style: lastEntry.style,
args: {
content: lastEntry.args.content + options.args.content,
styles: lastEntry.args.styles
}
};
} else {

@@ -149,2 +156,9 @@ lastLine.push(options);

}
var styles = this.styles;
this.styles = Object.create(null);
for (var p in styles) {
this.styles[p] = styles[p];
}
this.styles[style] = handler;

@@ -178,13 +192,15 @@ this[style] = function () {

var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i += 1) {
args[i] = arguments[i];
var styles = new Array(arguments.length - 1);
for (var i = 1; i < arguments.length; i += 1) {
styles[i - 1] = arguments[i];
}
content = String(content);
if (content.indexOf('\n') !== -1) {
args = args.slice(1);
var lines = content.split(/\n/);
lines.forEach(function (lineContent, index) {
if (lineContent.length) {
this.write({ style: 'text', args: [lineContent].concat(args) });
this.write({
style: 'text',
args: { content: lineContent, styles: styles }
});
}

@@ -197,3 +213,6 @@ if (index < lines.length - 1) {

} else {
return this.write({ style: 'text', args: args });
return this.write({
style: 'text',
args: { content: content, styles: styles }
});
}

@@ -207,3 +226,3 @@ };

return outputEntry.style === 'text' ?
{ style: 'text', args: [outputEntry.args[0]] } :
{ style: 'text', args: { content: outputEntry.args.content, styles: [] } } :
outputEntry;

@@ -259,3 +278,3 @@ }));

});
return this.write({ style: 'block', args: [blockOutput] });
return this.write({ style: 'block', args: blockOutput });
};

@@ -316,3 +335,3 @@ function isRawOutput(options) {

return this.write({ style: 'raw', args: [outputProperty] });
return this.write({ style: 'raw', args: outputProperty });
}

@@ -331,3 +350,3 @@

style: 'block',
args: [amend(lastEntry.args[0], pen)]
args: amend(lastEntry.args, pen)
};

@@ -408,4 +427,3 @@ newOutput[output.length - 1] = lastLine;

this.text(duplicateText(' ', count));
return this;
return this.text(duplicateText(' ', count));
};

@@ -421,3 +439,3 @@

MagicPen.prototype[textStyle] = MagicPen.prototype[textStyle.toLowerCase()] = function (content) {
return this.text.call(this, content, textStyle);
return this.text(content, textStyle);
};

@@ -432,3 +450,3 @@ });

var clonedPen = new MagicPenClone();
clonedPen.styles = extend({}, this.styles);
clonedPen.styles = this.styles;
clonedPen.indentationLevel = 0;

@@ -503,3 +521,3 @@ clonedPen.output = [[]];

style: 'block',
args: [replaceText(output.clone(), outputEntry.args[0], regexp, cb)]
args: replaceText(output.clone(), outputEntry.args, regexp, cb)
});

@@ -513,7 +531,7 @@ } else if (outputEntry.style !== 'text') {

}
var styles = outputEntry.args.slice(1);
var m;
var first = true;
var lastIndex = 0;
var text = outputEntry.args[0];
var text = outputEntry.args.content;
var styles = outputEntry.args.styles;
while ((m = regexp.exec(text)) !== null && (regexp.global || first)) {

@@ -520,0 +538,0 @@ if (lastIndex < m.index) {

@@ -15,3 +15,3 @@ var flattenBlocksInLines = require('./flattenBlocksInLines');

return this[outputEntry.style] ?
String(this[outputEntry.style].apply(this, outputEntry.args)) :
String(this[outputEntry.style](outputEntry.args)) :
'';

@@ -21,4 +21,4 @@ }, this).join('');

TextSerializer.prototype.text = function (content) {
return content;
TextSerializer.prototype.text = function (options) {
return String(options.content);
};

@@ -25,0 +25,0 @@

@@ -1,6 +0,6 @@

module.exports = function (theme, args) {
if (args.length === 2) {
module.exports = function (theme, styles) {
if (styles.length === 1) {
var count = 0;
var stack = [];
var themeMapping = args[1];
var themeMapping = styles[0];
while(typeof themeMapping === 'string' && theme[themeMapping]) {

@@ -18,6 +18,6 @@ themeMapping = theme[themeMapping];

return [args[0]].concat(themeMapping);
return Array.isArray(themeMapping) ? themeMapping : [themeMapping];
}
return args;
return styles;
};

@@ -15,7 +15,7 @@ var utils = {

case 'text':
return { width: String(outputEntry.args[0]).length, height: 1 };
return { width: String(outputEntry.args.content).length, height: 1 };
case 'block':
return utils.calculateSize(outputEntry.args[0]);
return utils.calculateSize(outputEntry.args);
case 'raw':
var arg = outputEntry.args[0];
var arg = outputEntry.args;
return { width: arg.width, height: arg.height };

@@ -22,0 +22,0 @@ default: return { width: 0, height: 0 };

@@ -120,10 +120,14 @@ /*!

AnsiSerializer.prototype.text = function () {
var args = themeMapper(this.theme, arguments);
AnsiSerializer.prototype.text = function (options) {
var content = String(options.content);
if (content === '') {
return '';
}
var content = args[0];
if (args.length > 1) {
for (var i = args.length -1; i > 0; i -= 1) {
var styleName = args[i];
var styles = themeMapper(this.theme, options.styles);
if (styles.length > 0) {
for (var i = styles.length -1; i >= 0; i -= 1) {
var styleName = styles[i];
if (ansiStyles[styleName]) {

@@ -210,3 +214,3 @@ content = ansiStyles[styleName].open + content + ansiStyles[styleName].close;

if (this[outputEntry.style]) {
result.push(this[outputEntry.style].apply(this, outputEntry.args));
result.push(this[outputEntry.style](outputEntry.args));
}

@@ -221,15 +225,16 @@ }, this);

ColoredConsoleSerializer.prototype.text = function () {
var args = themeMapper(this.theme, arguments);
var content = String(args[0]);
ColoredConsoleSerializer.prototype.text = function (options) {
var content = String(options.content);
if (content === '') {
return null;
return '';
}
var styles = themeMapper(this.theme, options.styles);
var result = ['%c' + content.replace(/%/g, '%%')];
var styleProperties = [];
if (args.length > 1) {
for (var i = 1; i < args.length; i += 1) {
var styleName = args[i];
if (styles.length > 0) {
for (var i = 0; i < styles.length; i += 1) {
var styleName = styles[i];
if (rgbRegexp.test(styleName)) {

@@ -280,3 +285,3 @@ if (styleName.substring(0, 2) === 'bg') {

return this[outputEntry.style] ?
this[outputEntry.style].apply(this, outputEntry.args) :
this[outputEntry.style](outputEntry.args) :
'';

@@ -292,6 +297,10 @@ }, this);

HtmlSerializer.prototype.text = function () {
var args = themeMapper(this.theme, arguments);
HtmlSerializer.prototype.text = function (options) {
var content = String(options.content);
var content = String(args[0])
if (content === '') {
return '';
}
content = content
.replace(/&/g, '&amp;')

@@ -303,6 +312,9 @@ .replace(/ /g, '&nbsp;')

if (args.length > 1) {
var styles = themeMapper(this.theme, options.styles);
if (styles.length > 0) {
var styleProperties = [];
for (var j = 1; j < args.length; j += 1) {
var styleName = args[j];
for (var j = 0; j < styles.length; j += 1) {
var styleName = styles[j];
if (rgbRegexp.test(styleName)) {

@@ -359,3 +371,3 @@ if (styleName.substring(0, 2) === 'bg') {

this.output = [[]];
this.styles = {};
this.styles = Object.create(null);
this.installedPlugins = [];

@@ -411,4 +423,3 @@ this._themes = {};

return utils.arrayEquals(Array.prototype.slice.call(a.args, 1),
Array.prototype.slice.call(b.args, 1));
return utils.arrayEquals(a.args.styles, b.args.styles);
}

@@ -425,3 +436,3 @@

var entry = line[i];
if (entry.style === 'text' && entry.args[0] === '') {
if (entry.style === 'text' && entry.args.content === '') {
continue;

@@ -432,4 +443,7 @@ }

result[result.length - 1] = {
style: entry.style,
args: [lastEntry.args[0] + entry.args[0]].concat(entry.args.slice(1))
style: lastEntry.style,
args: {
content: lastEntry.args.content + entry.args.content,
styles: lastEntry.args.styles
}
};

@@ -452,4 +466,9 @@ } else {

if (hasSameTextStyling(lastEntry, options)) {
options.args[0] = lastEntry.args[0] + options.args[0];
lastLine[lastLine.length - 1] = options;
lastLine[lastLine.length - 1] = {
style: lastEntry.style,
args: {
content: lastEntry.args.content + options.args.content,
styles: lastEntry.args.styles
}
};
} else {

@@ -483,2 +502,9 @@ lastLine.push(options);

}
var styles = this.styles;
this.styles = Object.create(null);
for (var p in styles) {
this.styles[p] = styles[p];
}
this.styles[style] = handler;

@@ -512,13 +538,15 @@ this[style] = function () {

var args = new Array(arguments.length);
for (var i = 0; i < arguments.length; i += 1) {
args[i] = arguments[i];
var styles = new Array(arguments.length - 1);
for (var i = 1; i < arguments.length; i += 1) {
styles[i - 1] = arguments[i];
}
content = String(content);
if (content.indexOf('\n') !== -1) {
args = args.slice(1);
var lines = content.split(/\n/);
lines.forEach(function (lineContent, index) {
if (lineContent.length) {
this.write({ style: 'text', args: [lineContent].concat(args) });
this.write({
style: 'text',
args: { content: lineContent, styles: styles }
});
}

@@ -531,3 +559,6 @@ if (index < lines.length - 1) {

} else {
return this.write({ style: 'text', args: args });
return this.write({
style: 'text',
args: { content: content, styles: styles }
});
}

@@ -541,3 +572,3 @@ };

return outputEntry.style === 'text' ?
{ style: 'text', args: [outputEntry.args[0]] } :
{ style: 'text', args: { content: outputEntry.args.content, styles: [] } } :
outputEntry;

@@ -593,3 +624,3 @@ }));

});
return this.write({ style: 'block', args: [blockOutput] });
return this.write({ style: 'block', args: blockOutput });
};

@@ -650,3 +681,3 @@ function isRawOutput(options) {

return this.write({ style: 'raw', args: [outputProperty] });
return this.write({ style: 'raw', args: outputProperty });
}

@@ -665,3 +696,3 @@

style: 'block',
args: [amend(lastEntry.args[0], pen)]
args: amend(lastEntry.args, pen)
};

@@ -742,4 +773,3 @@ newOutput[output.length - 1] = lastLine;

this.text(duplicateText(' ', count));
return this;
return this.text(duplicateText(' ', count));
};

@@ -755,3 +785,3 @@

MagicPen.prototype[textStyle] = MagicPen.prototype[textStyle.toLowerCase()] = function (content) {
return this.text.call(this, content, textStyle);
return this.text(content, textStyle);
};

@@ -766,3 +796,3 @@ });

var clonedPen = new MagicPenClone();
clonedPen.styles = extend({}, this.styles);
clonedPen.styles = this.styles;
clonedPen.indentationLevel = 0;

@@ -837,3 +867,3 @@ clonedPen.output = [[]];

style: 'block',
args: [replaceText(output.clone(), outputEntry.args[0], regexp, cb)]
args: replaceText(output.clone(), outputEntry.args, regexp, cb)
});

@@ -847,7 +877,7 @@ } else if (outputEntry.style !== 'text') {

}
var styles = outputEntry.args.slice(1);
var m;
var first = true;
var lastIndex = 0;
var text = outputEntry.args[0];
var text = outputEntry.args.content;
var styles = outputEntry.args.styles;
while ((m = regexp.exec(text)) !== null && (regexp.global || first)) {

@@ -976,3 +1006,3 @@ if (lastIndex < m.index) {

return this[outputEntry.style] ?
String(this[outputEntry.style].apply(this, outputEntry.args)) :
String(this[outputEntry.style](outputEntry.args)) :
'';

@@ -982,4 +1012,4 @@ }, this).join('');

TextSerializer.prototype.text = function (content) {
return content;
TextSerializer.prototype.text = function (options) {
return String(options.content);
};

@@ -1075,3 +1105,3 @@

function createPadding(length) {
return { style: 'text', args: [duplicateText(' ', length)] };
return { style: 'text', args: { content: duplicateText(' ', length), styles: [] } };
}

@@ -1082,3 +1112,3 @@

return outputEntry.style === 'block' ||
(outputEntry.style === 'text' && String(outputEntry.args[0]).indexOf('\n') !== -1);
(outputEntry.style === 'text' && String(outputEntry.args.content).indexOf('\n') !== -1);
});

@@ -1089,3 +1119,3 @@ }

switch (outputEntry.style) {
case 'text': return String(outputEntry.args[0]).split('\n').map(function (line) {
case 'text': return String(outputEntry.args.content).split('\n').map(function (line) {
if (line === '') {

@@ -1095,6 +1125,6 @@ return [];

var args = [line].concat(outputEntry.args.slice(1));
var args = { content: line, styles: outputEntry.args.styles };
return [{ style: 'text', args: args }];
});
case 'block': return flattenBlocksInLines(outputEntry.args[0]);
case 'block': return flattenBlocksInLines(outputEntry.args);
default: return [];

@@ -1119,2 +1149,3 @@ }

var blockLines = flattenBlocksInOutputEntry(outputEntry);
var blockLinesLengths = blockLines.map(function (line) {

@@ -1163,7 +1194,7 @@ return utils.calculateLineSize(line).width;

},{}],10:[function(require,module,exports){
module.exports = function (theme, args) {
if (args.length === 2) {
module.exports = function (theme, styles) {
if (styles.length === 1) {
var count = 0;
var stack = [];
var themeMapping = args[1];
var themeMapping = styles[0];
while(typeof themeMapping === 'string' && theme[themeMapping]) {

@@ -1181,6 +1212,6 @@ themeMapping = theme[themeMapping];

return [args[0]].concat(themeMapping);
return Array.isArray(themeMapping) ? themeMapping : [themeMapping];
}
return args;
return styles;
};

@@ -1203,7 +1234,7 @@

case 'text':
return { width: String(outputEntry.args[0]).length, height: 1 };
return { width: String(outputEntry.args.content).length, height: 1 };
case 'block':
return utils.calculateSize(outputEntry.args[0]);
return utils.calculateSize(outputEntry.args);
case 'raw':
var arg = outputEntry.args[0];
var arg = outputEntry.args;
return { width: arg.width, height: arg.height };

@@ -1355,3 +1386,2 @@ default: return { width: 0, height: 0 };

process.version = ''; // empty string to avoid regexp issues
process.versions = {};

@@ -1358,0 +1388,0 @@ function noop() {}

{
"name": "magicpen",
"version": "4.8.3",
"version": "4.9.0",
"description": "Styled output in both consoles and browsers",

@@ -5,0 +5,0 @@ "main": "./lib/MagicPen.js",

Sorry, the diff of this file is too big to display

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