Comparing version 0.5.2 to 1.0.0
@@ -1,10 +0,7 @@ | ||
var shim = require('./shim'); | ||
var utils = require('./utils'); | ||
var TextSerializer = require('./TextSerializer'); | ||
var forEach = shim.forEach; | ||
var getKeys = shim.getKeys; | ||
var colorDiff = require('color-diff'); | ||
var ansiStyles = utils.extend({}, require('ansi-styles')); | ||
forEach(getKeys(ansiStyles), function (styleName) { | ||
Object.keys(ansiStyles).forEach(function (styleName) { | ||
ansiStyles[styleName.toLowerCase()] = ansiStyles[styleName]; | ||
@@ -59,6 +56,6 @@ }); | ||
diffPalettes[16] = shim.map(getKeys(colorPalettes[16]), convertColorToObject); | ||
diffPalettes['bg16'] = shim.map(shim.filter(getKeys(colorPalettes[16]), function (color) { | ||
diffPalettes[16] = Object.keys(colorPalettes[16]).map(convertColorToObject); | ||
diffPalettes['bg16'] = Object.keys(colorPalettes[16]).filter(function (color) { | ||
return color !== "#808080"; | ||
}), convertColorToObject); | ||
}).map(convertColorToObject); | ||
diffPalettes[256] = [].concat(diffPalettes[16]); | ||
@@ -84,6 +81,6 @@ var nextAnsiColorNumber = 16; | ||
forEach([ | ||
[ | ||
0x08, 0x12, 0x1c, 0x26, 0x30, 0x3a, 0x44, 0x4e, 0x58, 0x60, 0x66, 0x76, | ||
0x80, 0x8a, 0x94, 0x9e, 0xa8, 0xb2, 0xbc, 0xc6, 0xd0, 0xda, 0xe4, 0xee | ||
], function (value) { | ||
].forEach(function (value) { | ||
registerNext256PaletteEntry({R: value, G: value, B: value}); | ||
@@ -97,3 +94,3 @@ }); | ||
var styles = stylesString.split(/\s*,\s*/); | ||
forEach(styles, function (styleName) { | ||
styles.forEach(function (styleName) { | ||
if (ansiStyles[styleName]) { | ||
@@ -100,0 +97,0 @@ content = ansiStyles[styleName].open + content + ansiStyles[styleName].close; |
@@ -1,6 +0,1 @@ | ||
var shim = require('./shim'); | ||
var forEach = shim.forEach; | ||
var getKeys = shim.getKeys; | ||
var map = shim.map; | ||
var htmlStyles = { | ||
@@ -35,3 +30,3 @@ bold: 'font-weight: bold', | ||
forEach(getKeys(htmlStyles), function (styleName) { | ||
Object.keys(htmlStyles).forEach(function (styleName) { | ||
htmlStyles[styleName.toLowerCase()] = htmlStyles[styleName]; | ||
@@ -47,3 +42,3 @@ }); | ||
HtmlSerializer.prototype.serializeLines = function (lines) { | ||
return map(lines, function (line) { | ||
return lines.map(function (line) { | ||
return ' <div>' + (this.serializeLine(line).join('') || ' ') + '</div>'; | ||
@@ -54,3 +49,3 @@ }, this).join('\n'); | ||
HtmlSerializer.prototype.serializeLine = function (line) { | ||
return map(line, function (outputEntry) { | ||
return line.map(function (outputEntry) { | ||
return this[outputEntry.style] ? | ||
@@ -80,3 +75,3 @@ this[outputEntry.style].apply(this, outputEntry.args) : | ||
var styleProperties = []; | ||
forEach(stylesString.split(/\s*,\s*/), function (styleName) { | ||
stylesString.split(/\s*,\s*/).forEach(function (styleName) { | ||
if (rgbRegexp.test(styleName)) { | ||
@@ -83,0 +78,0 @@ if (styleName.substring(0, 2) === 'bg') { |
/*global window*/ | ||
var shim = require('./shim'); | ||
var map = shim.map; | ||
var forEach = shim.forEach; | ||
var utils = require('./utils'); | ||
@@ -120,3 +117,3 @@ var extend = utils.extend; | ||
var lines = content.split(/\n/); | ||
forEach(lines, function (lineContent, index) { | ||
lines.forEach(function (lineContent, index) { | ||
this.write({ style: 'text', args: [lineContent].concat(args) }); | ||
@@ -135,4 +132,4 @@ if (index < lines.length - 1) { | ||
var result = this.clone(); | ||
forEach(this.output, function (line, index) { | ||
result.output[index] = map(line, function (outputEntry) { | ||
this.output.forEach(function (line, index) { | ||
result.output[index] = line.map(function (outputEntry) { | ||
return outputEntry.style === 'text' ? | ||
@@ -159,3 +156,3 @@ { style: 'text', args: [outputEntry.args[0]] } : | ||
var blockOutput = map(pen.output, function (line) { | ||
var blockOutput = pen.output.map(function (line) { | ||
return [].concat(line); | ||
@@ -203,3 +200,3 @@ }); | ||
this.output = map(this.output, function (line) { | ||
this.output = this.output.map(function (line) { | ||
return outputToPrepend.concat(line); | ||
@@ -224,3 +221,3 @@ }); | ||
forEach([ | ||
[ | ||
'bold', 'dim', 'italic', 'underline', 'inverse', 'hidden', | ||
@@ -231,3 +228,3 @@ 'strikeThrough', 'black', 'red', 'green', 'yellow', 'blue', | ||
'bgWhite' | ||
], function (textStyle) { | ||
].forEach(function (textStyle) { | ||
MagicPen.prototype[textStyle] = MagicPen.prototype[textStyle.toLowerCase()] = function (content) { | ||
@@ -252,3 +249,3 @@ return this.text.call(this, content, textStyle); | ||
var size = { height: 1, width: 0 }; | ||
forEach(line, function (outputEntry) { | ||
line.forEach(function (outputEntry) { | ||
switch (outputEntry.style) { | ||
@@ -270,3 +267,3 @@ case 'text': | ||
var size = { height: 0, width: 0 }; | ||
forEach(lines, function (line) { | ||
lines.forEach(function (line) { | ||
var lineSize = callculateLineSize(line); | ||
@@ -273,0 +270,0 @@ size.height += lineSize.height; |
@@ -1,4 +0,1 @@ | ||
var shim = require('./shim'); | ||
var map = shim.map; | ||
var forEach = shim.forEach; | ||
var duplicateText = require('./duplicateText'); | ||
@@ -16,3 +13,3 @@ | ||
TextSerializer.prototype.serialize = function (lines) { | ||
return map(lines, this.serializeLine, this).join('\n'); | ||
return lines.map(this.serializeLine, this).join('\n'); | ||
}; | ||
@@ -24,3 +21,3 @@ | ||
var startIndex = 0; | ||
forEach(line, function (outputEntry, blockIndex) { | ||
line.forEach(function (outputEntry, blockIndex) { | ||
var inlineBlock = this[outputEntry.style] ? | ||
@@ -30,3 +27,3 @@ this[outputEntry.style].apply(this, outputEntry.args) : | ||
var blockLines = map(String(inlineBlock).split('\n'), function (serializedBlockLine) { | ||
var blockLines = String(inlineBlock).split('\n').map(function (serializedBlockLine) { | ||
return { | ||
@@ -38,7 +35,7 @@ content: serializedBlockLine, | ||
var longestBlockLine = 0; | ||
forEach(blockLines, function (blockLine) { | ||
blockLines.forEach(function (blockLine) { | ||
longestBlockLine = Math.max(longestBlockLine, blockLine.length); | ||
}); | ||
forEach(blockLines, function (blockLine, index) { | ||
blockLines.forEach(function (blockLine, index) { | ||
serializedLines[index] = serializedLines[index] || ''; | ||
@@ -45,0 +42,0 @@ var padding = duplicateText(' ', startIndex - stripAnsi(serializedLines[index]).length); |
@@ -1,11 +0,6 @@ | ||
var shim = require('./shim'); | ||
var forEach = shim.forEach; | ||
var getKeys = shim.getKeys; | ||
module.exports = { | ||
extend: function (target) { | ||
var sources = Array.prototype.slice.call(arguments, 1); | ||
forEach(sources, function (source) { | ||
forEach(getKeys(source), function (key) { | ||
sources.forEach(function (source) { | ||
Object.keys(source).forEach(function (key) { | ||
target[key] = source[key]; | ||
@@ -12,0 +7,0 @@ }); |
186
magicpen.js
@@ -25,11 +25,8 @@ /*! | ||
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),(o.weknowhow||(o.weknowhow={})).MagicPen=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
var shim = require(7); | ||
var utils = require(8); | ||
var utils = require(6); | ||
var TextSerializer = require(4); | ||
var forEach = shim.forEach; | ||
var getKeys = shim.getKeys; | ||
var colorDiff = require(13); | ||
var colorDiff = require(11); | ||
var ansiStyles = utils.extend({}, require(9)); | ||
forEach(getKeys(ansiStyles), function (styleName) { | ||
var ansiStyles = utils.extend({}, require(7)); | ||
Object.keys(ansiStyles).forEach(function (styleName) { | ||
ansiStyles[styleName.toLowerCase()] = ansiStyles[styleName]; | ||
@@ -84,6 +81,6 @@ }); | ||
diffPalettes[16] = shim.map(getKeys(colorPalettes[16]), convertColorToObject); | ||
diffPalettes['bg16'] = shim.map(shim.filter(getKeys(colorPalettes[16]), function (color) { | ||
diffPalettes[16] = Object.keys(colorPalettes[16]).map(convertColorToObject); | ||
diffPalettes['bg16'] = Object.keys(colorPalettes[16]).filter(function (color) { | ||
return color !== "#808080"; | ||
}), convertColorToObject); | ||
}).map(convertColorToObject); | ||
diffPalettes[256] = [].concat(diffPalettes[16]); | ||
@@ -109,6 +106,6 @@ var nextAnsiColorNumber = 16; | ||
forEach([ | ||
[ | ||
0x08, 0x12, 0x1c, 0x26, 0x30, 0x3a, 0x44, 0x4e, 0x58, 0x60, 0x66, 0x76, | ||
0x80, 0x8a, 0x94, 0x9e, 0xa8, 0xb2, 0xbc, 0xc6, 0xd0, 0xda, 0xe4, 0xee | ||
], function (value) { | ||
].forEach(function (value) { | ||
registerNext256PaletteEntry({R: value, G: value, B: value}); | ||
@@ -122,3 +119,3 @@ }); | ||
var styles = stylesString.split(/\s*,\s*/); | ||
forEach(styles, function (styleName) { | ||
styles.forEach(function (styleName) { | ||
if (ansiStyles[styleName]) { | ||
@@ -161,7 +158,2 @@ content = ansiStyles[styleName].open + content + ansiStyles[styleName].close; | ||
},{}],2:[function(require,module,exports){ | ||
var shim = require(7); | ||
var forEach = shim.forEach; | ||
var getKeys = shim.getKeys; | ||
var map = shim.map; | ||
var htmlStyles = { | ||
@@ -196,3 +188,3 @@ bold: 'font-weight: bold', | ||
forEach(getKeys(htmlStyles), function (styleName) { | ||
Object.keys(htmlStyles).forEach(function (styleName) { | ||
htmlStyles[styleName.toLowerCase()] = htmlStyles[styleName]; | ||
@@ -208,3 +200,3 @@ }); | ||
HtmlSerializer.prototype.serializeLines = function (lines) { | ||
return map(lines, function (line) { | ||
return lines.map(function (line) { | ||
return ' <div>' + (this.serializeLine(line).join('') || ' ') + '</div>'; | ||
@@ -215,3 +207,3 @@ }, this).join('\n'); | ||
HtmlSerializer.prototype.serializeLine = function (line) { | ||
return map(line, function (outputEntry) { | ||
return line.map(function (outputEntry) { | ||
return this[outputEntry.style] ? | ||
@@ -241,3 +233,3 @@ this[outputEntry.style].apply(this, outputEntry.args) : | ||
var styleProperties = []; | ||
forEach(stylesString.split(/\s*,\s*/), function (styleName) { | ||
stylesString.split(/\s*,\s*/).forEach(function (styleName) { | ||
if (rgbRegexp.test(styleName)) { | ||
@@ -263,6 +255,3 @@ if (styleName.substring(0, 2) === 'bg') { | ||
/*global window*/ | ||
var shim = require(7); | ||
var map = shim.map; | ||
var forEach = shim.forEach; | ||
var utils = require(8); | ||
var utils = require(6); | ||
var extend = utils.extend; | ||
@@ -293,3 +282,3 @@ var duplicateText = require(5); | ||
MagicPen.defaultFormat = 'html'; // Browser | ||
} else if (require(15)) { | ||
} else if (require(13)) { | ||
MagicPen.defaultFormat = 'ansi'; // colored console | ||
@@ -383,3 +372,3 @@ } else { | ||
var lines = content.split(/\n/); | ||
forEach(lines, function (lineContent, index) { | ||
lines.forEach(function (lineContent, index) { | ||
this.write({ style: 'text', args: [lineContent].concat(args) }); | ||
@@ -398,4 +387,4 @@ if (index < lines.length - 1) { | ||
var result = this.clone(); | ||
forEach(this.output, function (line, index) { | ||
result.output[index] = map(line, function (outputEntry) { | ||
this.output.forEach(function (line, index) { | ||
result.output[index] = line.map(function (outputEntry) { | ||
return outputEntry.style === 'text' ? | ||
@@ -422,3 +411,3 @@ { style: 'text', args: [outputEntry.args[0]] } : | ||
var blockOutput = map(pen.output, function (line) { | ||
var blockOutput = pen.output.map(function (line) { | ||
return [].concat(line); | ||
@@ -466,3 +455,3 @@ }); | ||
this.output = map(this.output, function (line) { | ||
this.output = this.output.map(function (line) { | ||
return outputToPrepend.concat(line); | ||
@@ -487,3 +476,3 @@ }); | ||
forEach([ | ||
[ | ||
'bold', 'dim', 'italic', 'underline', 'inverse', 'hidden', | ||
@@ -494,3 +483,3 @@ 'strikeThrough', 'black', 'red', 'green', 'yellow', 'blue', | ||
'bgWhite' | ||
], function (textStyle) { | ||
].forEach(function (textStyle) { | ||
MagicPen.prototype[textStyle] = MagicPen.prototype[textStyle.toLowerCase()] = function (content) { | ||
@@ -515,3 +504,3 @@ return this.text.call(this, content, textStyle); | ||
var size = { height: 1, width: 0 }; | ||
forEach(line, function (outputEntry) { | ||
line.forEach(function (outputEntry) { | ||
switch (outputEntry.style) { | ||
@@ -533,3 +522,3 @@ case 'text': | ||
var size = { height: 0, width: 0 }; | ||
forEach(lines, function (line) { | ||
lines.forEach(function (line) { | ||
var lineSize = callculateLineSize(line); | ||
@@ -559,5 +548,2 @@ size.height += lineSize.height; | ||
},{}],4:[function(require,module,exports){ | ||
var shim = require(7); | ||
var map = shim.map; | ||
var forEach = shim.forEach; | ||
var duplicateText = require(5); | ||
@@ -575,3 +561,3 @@ | ||
TextSerializer.prototype.serialize = function (lines) { | ||
return map(lines, this.serializeLine, this).join('\n'); | ||
return lines.map(this.serializeLine, this).join('\n'); | ||
}; | ||
@@ -583,3 +569,3 @@ | ||
var startIndex = 0; | ||
forEach(line, function (outputEntry, blockIndex) { | ||
line.forEach(function (outputEntry, blockIndex) { | ||
var inlineBlock = this[outputEntry.style] ? | ||
@@ -589,3 +575,3 @@ this[outputEntry.style].apply(this, outputEntry.args) : | ||
var blockLines = map(String(inlineBlock).split('\n'), function (serializedBlockLine) { | ||
var blockLines = String(inlineBlock).split('\n').map(function (serializedBlockLine) { | ||
return { | ||
@@ -597,7 +583,7 @@ content: serializedBlockLine, | ||
var longestBlockLine = 0; | ||
forEach(blockLines, function (blockLine) { | ||
blockLines.forEach(function (blockLine) { | ||
longestBlockLine = Math.max(longestBlockLine, blockLine.length); | ||
}); | ||
forEach(blockLines, function (blockLine, index) { | ||
blockLines.forEach(function (blockLine, index) { | ||
serializedLines[index] = serializedLines[index] || ''; | ||
@@ -636,88 +622,6 @@ var padding = duplicateText(' ', startIndex - stripAnsi(serializedLines[index]).length); | ||
module.exports = { | ||
getKeys: function (obj) { | ||
var result = []; | ||
for (var i in obj) { | ||
if (obj.hasOwnProperty(i)) { | ||
result.push(i); | ||
} | ||
} | ||
return result; | ||
}, | ||
forEach: function (arr, callback, that) { | ||
for (var i = 0, n = arr.length; i < n; i += 1) | ||
if (i in arr) | ||
callback.call(that, arr[i], i, arr); | ||
}, | ||
map: function (arr, mapper, that) { | ||
var other = new Array(arr.length); | ||
for (var i = 0, n = arr.length; i < n; i += 1) | ||
if (i in arr) | ||
other[i] = mapper.call(that, arr[i], i, arr); | ||
return other; | ||
}, | ||
filter: function (arr, predicate) { | ||
var length = +arr.length; | ||
var result = []; | ||
if (typeof predicate !== "function") | ||
throw new TypeError(); | ||
for (var i = 0; i < length; i += 1) { | ||
var value = arr[i]; | ||
if (predicate(value)) { | ||
result.push(value); | ||
} | ||
} | ||
return result; | ||
} | ||
}; | ||
},{}],7:[function(require,module,exports){ | ||
var shim = require(6); | ||
var prototypes = { | ||
forEach: Array.prototype.forEach, | ||
map: Array.prototype.map, | ||
filter: Array.prototype.filter | ||
}; | ||
function createShimMethod(key) { | ||
shim[key] = function (obj) { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return prototypes[key].apply(obj, args); | ||
}; | ||
} | ||
for (var key in prototypes) { | ||
if (prototypes.hasOwnProperty(key) && prototypes[key]) { | ||
createShimMethod(key); | ||
} | ||
} | ||
if (Object.keys) { | ||
shim['getKeys'] = Object.keys; | ||
} | ||
module.exports = shim; | ||
},{}],8:[function(require,module,exports){ | ||
var shim = require(7); | ||
var forEach = shim.forEach; | ||
var getKeys = shim.getKeys; | ||
module.exports = { | ||
extend: function (target) { | ||
var sources = Array.prototype.slice.call(arguments, 1); | ||
forEach(sources, function (source) { | ||
forEach(getKeys(source), function (key) { | ||
sources.forEach(function (source) { | ||
Object.keys(source).forEach(function (key) { | ||
target[key] = source[key]; | ||
@@ -730,3 +634,3 @@ }); | ||
},{}],9:[function(require,module,exports){ | ||
},{}],7:[function(require,module,exports){ | ||
'use strict'; | ||
@@ -773,3 +677,3 @@ var styles = module.exports; | ||
},{}],10:[function(require,module,exports){ | ||
},{}],8:[function(require,module,exports){ | ||
// shim for using process in browser | ||
@@ -839,3 +743,3 @@ | ||
},{}],11:[function(require,module,exports){ | ||
},{}],9:[function(require,module,exports){ | ||
/** | ||
@@ -955,3 +859,3 @@ * @author Markus Näsman | ||
},{}],12:[function(require,module,exports){ | ||
},{}],10:[function(require,module,exports){ | ||
/** | ||
@@ -1122,8 +1026,8 @@ * @author Markus Näsman | ||
},{}],13:[function(require,module,exports){ | ||
},{}],11:[function(require,module,exports){ | ||
'use strict'; | ||
var diff = require(12); | ||
var convert = require(11); | ||
var palette = require(14); | ||
var diff = require(10); | ||
var convert = require(9); | ||
var palette = require(12); | ||
@@ -1144,3 +1048,3 @@ var color = module.exports = {}; | ||
}; | ||
},{}],14:[function(require,module,exports){ | ||
},{}],12:[function(require,module,exports){ | ||
/** | ||
@@ -1183,4 +1087,4 @@ * @author Markus Näsman | ||
*/ | ||
var color_diff = require(12); | ||
var color_convert = require(11); | ||
var color_diff = require(10); | ||
var color_convert = require(9); | ||
@@ -1245,3 +1149,3 @@ /** | ||
},{}],15:[function(require,module,exports){ | ||
},{}],13:[function(require,module,exports){ | ||
(function (process){ | ||
@@ -1281,4 +1185,4 @@ 'use strict'; | ||
}).call(this,require(10)) | ||
}).call(this,require(8)) | ||
},{}]},{},[3])(3) | ||
}); |
{ | ||
"name": "magicpen", | ||
"version": "0.5.2", | ||
"version": "1.0.0", | ||
"description": "Styled output in both consoles and browsers", | ||
@@ -5,0 +5,0 @@ "main": "./lib/MagicPen.js", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
443339
26
2123