Comparing version 2.1.0 to 2.1.1
@@ -62,2 +62,23 @@ /*global window*/ | ||
function normalizeLine(line) { | ||
if (line.length === 0) { | ||
return line; | ||
} | ||
var result = [line[0]]; | ||
for (var i = 1; i < line.length; i += 1) { | ||
var lastEntry = result[result.length - 1]; | ||
if (hasSameTextStyling(lastEntry, line[i])) { | ||
result[result.length - 1] = { | ||
style: line[i].style, | ||
args: [lastEntry.args[0] + line[i].args[0]].concat(line[i].args.slice(1)) | ||
}; | ||
} else { | ||
result.push(line[i]); | ||
} | ||
} | ||
return result; | ||
} | ||
MagicPen.prototype.write = function () { | ||
@@ -146,7 +167,7 @@ if (typeof arguments[0] === 'string') { | ||
this.output.forEach(function (line, index) { | ||
result.output[index] = line.map(function (outputEntry) { | ||
result.output[index] = normalizeLine(line.map(function (outputEntry) { | ||
return outputEntry.style === 'text' ? | ||
{ style: 'text', args: [outputEntry.args[0]] } : | ||
outputEntry; | ||
}); | ||
})); | ||
}); | ||
@@ -196,2 +217,3 @@ result.indentationLevel = this.indentationLevel; | ||
Array.prototype.push.apply(lastLine, pen.output[0]); | ||
this.output[this.output.length - 1] = normalizeLine(lastLine); | ||
@@ -221,3 +243,3 @@ this.output.push.apply(this.output, pen.output.slice(1)); | ||
this.output = this.output.map(function (line) { | ||
return outputToPrepend.concat(line); | ||
return normalizeLine(outputToPrepend.concat(line)); | ||
}); | ||
@@ -224,0 +246,0 @@ |
@@ -305,2 +305,23 @@ /*! | ||
function normalizeLine(line) { | ||
if (line.length === 0) { | ||
return line; | ||
} | ||
var result = [line[0]]; | ||
for (var i = 1; i < line.length; i += 1) { | ||
var lastEntry = result[result.length - 1]; | ||
if (hasSameTextStyling(lastEntry, line[i])) { | ||
result[result.length - 1] = { | ||
style: line[i].style, | ||
args: [lastEntry.args[0] + line[i].args[0]].concat(line[i].args.slice(1)) | ||
}; | ||
} else { | ||
result.push(line[i]); | ||
} | ||
} | ||
return result; | ||
} | ||
MagicPen.prototype.write = function () { | ||
@@ -389,7 +410,7 @@ if (typeof arguments[0] === 'string') { | ||
this.output.forEach(function (line, index) { | ||
result.output[index] = line.map(function (outputEntry) { | ||
result.output[index] = normalizeLine(line.map(function (outputEntry) { | ||
return outputEntry.style === 'text' ? | ||
{ style: 'text', args: [outputEntry.args[0]] } : | ||
outputEntry; | ||
}); | ||
})); | ||
}); | ||
@@ -439,2 +460,3 @@ result.indentationLevel = this.indentationLevel; | ||
Array.prototype.push.apply(lastLine, pen.output[0]); | ||
this.output[this.output.length - 1] = normalizeLine(lastLine); | ||
@@ -464,3 +486,3 @@ this.output.push.apply(this.output, pen.output.slice(1)); | ||
this.output = this.output.map(function (line) { | ||
return outputToPrepend.concat(line); | ||
return normalizeLine(outputToPrepend.concat(line)); | ||
}); | ||
@@ -1058,6 +1080,15 @@ | ||
var result = color.map_palette([target], relative); | ||
var result = color.map_palette([target], relative, 'closest'); | ||
return result[key]; | ||
}; | ||
color.furthest = function(target, relative) { | ||
var key = color.palette_map_key(target); | ||
var result = color.map_palette([target], relative, 'furthest'); | ||
return result[key]; | ||
}; | ||
},{}],12:[function(require,module,exports){ | ||
@@ -1122,7 +1153,9 @@ /** | ||
* @param [{rgbcolor}] b each element should have fields R,G,B | ||
* @param 'type' should have field closest or furthest | ||
* @return {palettemap} | ||
*/ | ||
function map_palette(a, b) | ||
function map_palette(a, b, type) | ||
{ | ||
var c = {}; | ||
type = type || 'closest'; | ||
for (var idx1 in a){ | ||
@@ -1136,7 +1169,15 @@ var color1 = a[idx1]; | ||
var current_color_diff = diff(color1,color2); | ||
if((best_color == undefined) || (current_color_diff < best_color_diff)) | ||
if((best_color == undefined) || ((type === 'closest') && (current_color_diff < best_color_diff))) | ||
{ | ||
best_color = color2; | ||
best_color_diff = current_color_diff; | ||
continue; | ||
} | ||
if((type === 'furthest') && (current_color_diff > best_color_diff)) | ||
{ | ||
best_color = color2; | ||
best_color_diff = current_color_diff; | ||
continue; | ||
} | ||
} | ||
@@ -1167,8 +1208,15 @@ c[palette_map_key(color1)] = best_color; | ||
'use strict'; | ||
var argv = process.argv; | ||
module.exports = (function () { | ||
if (process.argv.indexOf('--no-color') !== -1) { | ||
if (argv.indexOf('--no-color') !== -1 || | ||
argv.indexOf('--no-colors') !== -1 || | ||
argv.indexOf('--color=false') !== -1) { | ||
return false; | ||
} | ||
if (process.argv.indexOf('--color') !== -1) { | ||
if (argv.indexOf('--color') !== -1 || | ||
argv.indexOf('--colors') !== -1 || | ||
argv.indexOf('--color=true') !== -1 || | ||
argv.indexOf('--color=always') !== -1) { | ||
return true; | ||
@@ -1175,0 +1223,0 @@ } |
{ | ||
"name": "magicpen", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Styled output in both consoles and browsers", | ||
@@ -36,5 +36,5 @@ "main": "./lib/MagicPen.js", | ||
"color-diff": "^0.1.4", | ||
"supports-color": "^0.2.0" | ||
"supports-color": "^1.2.0" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -148,3 +148,3 @@ /*global describe, it, beforeEach*/ | ||
.indent().text('Third line') | ||
.prependLinesWith(pen.clone().gray(' // ')); | ||
.prependLinesWith(pen.clone().sp().gray('//').sp()); | ||
@@ -265,3 +265,3 @@ expect(pen.toString(), 'to equal', | ||
.indent().text('Third line') | ||
.prependLinesWith(pen.clone().gray(' // ')); | ||
.prependLinesWith(pen.clone().sp().gray('//').sp()); | ||
@@ -335,5 +335,5 @@ expect(pen.toString(), 'to equal', | ||
it('merges adjacent text entries with the same styling', function () { | ||
pen.red('Hello').red(' ').red('world'); | ||
pen.red('Hello').red(' ').red('world').append('red', '!'); | ||
expect(pen.toString('ansi'), 'to equal', | ||
'\x1B[31mHello world\x1B[39m'); | ||
'\x1B[31mHello world!\x1B[39m'); | ||
}); | ||
@@ -351,2 +351,15 @@ | ||
it('the content of a pen can be prepended to the start of each line', function () { | ||
pen.text('First line').nl() | ||
.text('Second line').nl() | ||
.indentLines() | ||
.indent().text('Third line') | ||
.prependLinesWith(pen.clone().sp().gray('//').sp()); | ||
expect(pen.toString('ansi'), 'to equal', | ||
' \u001b[90m//\u001b[39m First line\n' + | ||
' \u001b[90m//\u001b[39m Second line\n' + | ||
' \u001b[90m//\u001b[39m Third line'); | ||
}); | ||
it('the content of a pen can be appended in a block', function () { | ||
@@ -463,6 +476,6 @@ pen.red('Hello').block( | ||
it('merges adjacent text entries with the same styling', function () { | ||
pen.red('Hello').red(' ').red('world'); | ||
pen.red('Hello').red(' ').red('world').append('red', '!'); | ||
expect(pen.toString('html'), 'to equal', | ||
'<div style="font-family: monospace; white-space: nowrap">\n' + | ||
' <div><span style="color: red">Hello world</span></div>\n' + | ||
' <div><span style="color: red">Hello world!</span></div>\n' + | ||
'</div>'); | ||
@@ -498,9 +511,9 @@ }); | ||
.indent().text('Third line') | ||
.prependLinesWith(pen.clone().gray(' // ')); | ||
.prependLinesWith(pen.clone().sp().gray('//').sp()); | ||
expect(pen.toString('html'), 'to equal', | ||
'<div style="font-family: monospace; white-space: nowrap">\n' + | ||
' <div><span style="color: gray"> // </span>First line</div>\n' + | ||
' <div><span style="color: gray"> // </span>Second line</div>\n' + | ||
' <div><span style="color: gray"> // </span> Third line</div>\n' + | ||
' <div> <span style="color: gray">//</span> First line</div>\n' + | ||
' <div> <span style="color: gray">//</span> Second line</div>\n' + | ||
' <div> <span style="color: gray">//</span> Third line</div>\n' + | ||
'</div>'); | ||
@@ -507,0 +520,0 @@ }); |
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
451337
2300
+ Addedsupports-color@1.3.1(transitive)
- Removedsupports-color@0.2.0(transitive)
Updatedsupports-color@^1.2.0