Comparing version 3.0.9 to 3.0.10
@@ -88,6 +88,8 @@ var utils = require('./utils'); | ||
var rgbRegexp = /^(?:bg)?#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i; | ||
AnsiSerializer.prototype.text = function (content) { | ||
AnsiSerializer.prototype.text = function () { | ||
var content = arguments[0]; | ||
if (arguments.length > 1) { | ||
var styles = Array.prototype.slice.call(arguments, 1); | ||
styles.forEach(function (styleName) { | ||
for (var i = 1; i < arguments.length; i += 1) { | ||
var styleName = arguments[i]; | ||
if (ansiStyles[styleName]) { | ||
@@ -121,3 +123,3 @@ content = ansiStyles[styleName].open + content + ansiStyles[styleName].close; | ||
} | ||
}); | ||
} | ||
} | ||
@@ -124,0 +126,0 @@ |
@@ -61,4 +61,4 @@ var htmlStyles = { | ||
var rgbRegexp = /^(?:bg)?#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i; | ||
HtmlSerializer.prototype.text = function (content) { | ||
content = String(content) | ||
HtmlSerializer.prototype.text = function () { | ||
var content = String(arguments[0]) | ||
.replace(/&/g, '&') | ||
@@ -71,5 +71,5 @@ .replace(/ /g, ' ') | ||
if (arguments.length > 1) { | ||
var styles = Array.prototype.slice.call(arguments, 1); | ||
var styleProperties = []; | ||
styles.forEach(function (styleName) { | ||
for (var i = 1; i < arguments.length; i += 1) { | ||
var styleName = arguments[i]; | ||
if (rgbRegexp.test(styleName)) { | ||
@@ -84,4 +84,4 @@ if (styleName.substring(0, 2) === 'bg') { | ||
} | ||
}); | ||
} | ||
content = '<span style="' + styleProperties.join('; ') + '">' + content + '</span>'; | ||
@@ -88,0 +88,0 @@ } |
@@ -90,23 +90,17 @@ /*global window*/ | ||
MagicPen.prototype.write = function () { | ||
if (typeof arguments[0] === 'string') { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return this.write({ style: arguments[0], args: args }); | ||
MagicPen.prototype.write = function (options) { | ||
if (this.styles[options.style]) { | ||
this.styles[options.style].apply(this, options.args); | ||
return this; | ||
} | ||
var lastLine = this.output[this.output.length - 1]; | ||
var lastEntry = lastLine[lastLine.length - 1]; | ||
if (hasSameTextStyling(lastEntry, options)) { | ||
options.args[0] = lastEntry.args[0] + options.args[0]; | ||
lastLine[lastLine.length - 1] = options; | ||
} else { | ||
var options = arguments[0]; | ||
if (this.styles[options.style]) { | ||
this.styles[options.style].apply(this, options.args); | ||
return this; | ||
} | ||
var lastLine = this.output[this.output.length - 1]; | ||
var lastEntry = lastLine[lastLine.length - 1]; | ||
if (hasSameTextStyling(lastEntry, options)) { | ||
options.args[0] = lastEntry.args[0] + options.args[0]; | ||
lastLine[lastLine.length - 1] = options; | ||
} else { | ||
lastLine.push(options); | ||
} | ||
lastLine.push(options); | ||
} | ||
return this; | ||
} | ||
return this; | ||
}; | ||
@@ -152,3 +146,4 @@ | ||
MagicPen.prototype.text = function (content) { | ||
MagicPen.prototype.text = function () { | ||
var content = arguments[0]; | ||
if (content === '') { | ||
@@ -158,3 +153,6 @@ return this; | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
var args = new Array(arguments.length); | ||
for (var i = 0; i < arguments.length; i += 1) { | ||
args[i] = arguments[i]; | ||
} | ||
content = String(content); | ||
@@ -215,3 +213,3 @@ if (content.indexOf('\n') !== -1) { | ||
}); | ||
return this.write('block', blockOutput); | ||
return this.write({ style: 'block', args: [blockOutput] }); | ||
}; | ||
@@ -218,0 +216,0 @@ |
var utils = { | ||
extend: function (target) { | ||
var sources = Array.prototype.slice.call(arguments, 1); | ||
sources.forEach(function (source) { | ||
for (var i = 1; i < arguments.length; i += 1) { | ||
var source = arguments[i]; | ||
Object.keys(source).forEach(function (key) { | ||
target[key] = source[key]; | ||
}); | ||
}); | ||
} | ||
return target; | ||
@@ -10,0 +10,0 @@ }, |
@@ -112,6 +112,8 @@ /*! | ||
var rgbRegexp = /^(?:bg)?#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i; | ||
AnsiSerializer.prototype.text = function (content) { | ||
AnsiSerializer.prototype.text = function () { | ||
var content = arguments[0]; | ||
if (arguments.length > 1) { | ||
var styles = Array.prototype.slice.call(arguments, 1); | ||
styles.forEach(function (styleName) { | ||
for (var i = 1; i < arguments.length; i += 1) { | ||
var styleName = arguments[i]; | ||
if (ansiStyles[styleName]) { | ||
@@ -145,3 +147,3 @@ content = ansiStyles[styleName].open + content + ansiStyles[styleName].close; | ||
} | ||
}); | ||
} | ||
} | ||
@@ -215,4 +217,4 @@ | ||
var rgbRegexp = /^(?:bg)?#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i; | ||
HtmlSerializer.prototype.text = function (content) { | ||
content = String(content) | ||
HtmlSerializer.prototype.text = function () { | ||
var content = String(arguments[0]) | ||
.replace(/&/g, '&') | ||
@@ -225,5 +227,5 @@ .replace(/ /g, ' ') | ||
if (arguments.length > 1) { | ||
var styles = Array.prototype.slice.call(arguments, 1); | ||
var styleProperties = []; | ||
styles.forEach(function (styleName) { | ||
for (var i = 1; i < arguments.length; i += 1) { | ||
var styleName = arguments[i]; | ||
if (rgbRegexp.test(styleName)) { | ||
@@ -238,4 +240,4 @@ if (styleName.substring(0, 2) === 'bg') { | ||
} | ||
}); | ||
} | ||
content = '<span style="' + styleProperties.join('; ') + '">' + content + '</span>'; | ||
@@ -338,23 +340,17 @@ } | ||
MagicPen.prototype.write = function () { | ||
if (typeof arguments[0] === 'string') { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return this.write({ style: arguments[0], args: args }); | ||
MagicPen.prototype.write = function (options) { | ||
if (this.styles[options.style]) { | ||
this.styles[options.style].apply(this, options.args); | ||
return this; | ||
} | ||
var lastLine = this.output[this.output.length - 1]; | ||
var lastEntry = lastLine[lastLine.length - 1]; | ||
if (hasSameTextStyling(lastEntry, options)) { | ||
options.args[0] = lastEntry.args[0] + options.args[0]; | ||
lastLine[lastLine.length - 1] = options; | ||
} else { | ||
var options = arguments[0]; | ||
if (this.styles[options.style]) { | ||
this.styles[options.style].apply(this, options.args); | ||
return this; | ||
} | ||
var lastLine = this.output[this.output.length - 1]; | ||
var lastEntry = lastLine[lastLine.length - 1]; | ||
if (hasSameTextStyling(lastEntry, options)) { | ||
options.args[0] = lastEntry.args[0] + options.args[0]; | ||
lastLine[lastLine.length - 1] = options; | ||
} else { | ||
lastLine.push(options); | ||
} | ||
lastLine.push(options); | ||
} | ||
return this; | ||
} | ||
return this; | ||
}; | ||
@@ -400,3 +396,4 @@ | ||
MagicPen.prototype.text = function (content) { | ||
MagicPen.prototype.text = function () { | ||
var content = arguments[0]; | ||
if (content === '') { | ||
@@ -406,3 +403,6 @@ return this; | ||
var args = Array.prototype.slice.call(arguments, 0); | ||
var args = new Array(arguments.length); | ||
for (var i = 0; i < arguments.length; i += 1) { | ||
args[i] = arguments[i]; | ||
} | ||
content = String(content); | ||
@@ -463,3 +463,3 @@ if (content.indexOf('\n') !== -1) { | ||
}); | ||
return this.write('block', blockOutput); | ||
return this.write({ style: 'block', args: [blockOutput] }); | ||
}; | ||
@@ -787,8 +787,8 @@ | ||
extend: function (target) { | ||
var sources = Array.prototype.slice.call(arguments, 1); | ||
sources.forEach(function (source) { | ||
for (var i = 1; i < arguments.length; i += 1) { | ||
var source = arguments[i]; | ||
Object.keys(source).forEach(function (key) { | ||
target[key] = source[key]; | ||
}); | ||
}); | ||
} | ||
return target; | ||
@@ -795,0 +795,0 @@ }, |
{ | ||
"name": "magicpen", | ||
"version": "3.0.9", | ||
"version": "3.0.10", | ||
"description": "Styled output in both consoles and browsers", | ||
@@ -5,0 +5,0 @@ "main": "./lib/MagicPen.js", |
@@ -344,3 +344,3 @@ /*global describe, it, beforeEach*/ | ||
it('ignores unknown styles', function () { | ||
pen.text('>').write('test', 'text').text('<'); | ||
pen.text('>').write({ style: 'test', args: ['text'] }).text('<'); | ||
expect(pen.toString(), 'to equal', '><'); | ||
@@ -448,3 +448,3 @@ }); | ||
it('ignores unknown styles', function () { | ||
pen.text('>').write('test', 'text').text('<'); | ||
pen.text('>').write({ style: 'test', args: ['text'] }).text('<'); | ||
expect(pen.toString('ansi'), 'to equal', '><'); | ||
@@ -492,3 +492,3 @@ }); | ||
pen.error('Danger').sp().write('error', 'danger'); | ||
pen.error('Danger').sp().write({ style: 'error', args: ['danger'] }); | ||
expect(pen.toString('ansi'), 'to equal', | ||
@@ -562,3 +562,3 @@ '\x1B[31mDanger\x1B[39m \x1B[31mdanger\x1B[39m'); | ||
it('ignores unknown styles', function () { | ||
pen.text('>').write('test', 'text').text('<'); | ||
pen.text('>').write({ style: 'test', args: ['text'] }).text('<'); | ||
expect(pen.toString('html'), 'to equal', | ||
@@ -635,3 +635,3 @@ '<div style="font-family: monospace; white-space: nowrap">\n' + | ||
pen.error('Danger').sp().write('error', 'danger'); | ||
pen.error('Danger').sp().write({ style: 'error', args: ['danger'] }); | ||
expect(pen.toString('html'), 'to equal', | ||
@@ -638,0 +638,0 @@ '<div style="font-family: monospace; white-space: nowrap">\n' + |
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
469030
2750