Comparing version 0.0.1 to 0.0.2
@@ -64,5 +64,2 @@ /*global weknowhow:true*/ | ||
this.styles = styles; | ||
this.styles.raw = function (content) { | ||
return content; | ||
}; | ||
} | ||
@@ -119,3 +116,3 @@ | ||
var PlainSerializer = createSerializer({ | ||
var TextSerializer = createSerializer({ | ||
text: function (content) { | ||
@@ -208,3 +205,3 @@ return content; | ||
var AnsiSerializer = createSerializer(extend({}, PlainSerializer.prototype.styles, { | ||
var AnsiSerializer = createSerializer(extend({}, TextSerializer.prototype.styles, { | ||
text: function (content) { | ||
@@ -288,3 +285,3 @@ if (arguments.length > 1) { | ||
var defaults = { | ||
mode: 'plain' | ||
mode: 'text' | ||
}; | ||
@@ -307,11 +304,2 @@ | ||
this.serializer = new MagicPen.serializers[this.mode](); | ||
forEach(getKeys(this.serializer.styles), function (style) { | ||
if (!that[style]) { | ||
that[style] = function () { | ||
var args = Array.prototype.slice.call(arguments); | ||
return this.write.call(this, { style: style, args: args }); | ||
}; | ||
} | ||
}); | ||
} | ||
@@ -325,3 +313,3 @@ | ||
MagicPen.serializers = { | ||
plain: PlainSerializer, | ||
text: TextSerializer, | ||
ansi: AnsiSerializer, | ||
@@ -332,7 +320,4 @@ html: HtmlSerializer | ||
MagicPen.prototype.write = function () { | ||
var args = Array.prototype.slice.call(arguments); | ||
if (args.length === 0) { | ||
return this; | ||
} else if (args.length === 1 && isOutputEntry(args[0])) { | ||
var options = args[0]; | ||
if (arguments.length === 1 && isOutputEntry(arguments[0])) { | ||
var options = arguments[0]; | ||
if (this.styles[options.style]) { | ||
@@ -345,6 +330,5 @@ this.styles[options.style].apply(this, options.args); | ||
return this; | ||
} else if (args.length === 1) { | ||
return this.write({ style: 'text', args: args }); | ||
} else { | ||
return this.write({ style: args[0], args: args.slice(1) }); | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
return this.write({ style: arguments[0], args: args }); | ||
} | ||
@@ -392,2 +376,7 @@ }; | ||
MagicPen.prototype.text = function () { | ||
var args = Array.prototype.slice.call(arguments); | ||
return this.write({ style: 'text', args: args }); | ||
}; | ||
MagicPen.prototype.block = function (pen) { | ||
@@ -394,0 +383,0 @@ this.ensurePenWithSameMode(pen); |
{ | ||
"name": "magicpen", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Styled output in both consoles and browsers", | ||
@@ -5,0 +5,0 @@ "main": "magicpen.js", |
@@ -66,3 +66,3 @@ # MagicPen | ||
function. The function takes one parameter, the output mode. By | ||
default the `plain` mode is console output without colors. You can | ||
default the `text` mode is console output without colors. You can | ||
also choose the `ansi` mode or the `html` mode. The `ansi` mode will | ||
@@ -69,0 +69,0 @@ format the output for the console with colors and basic styling. The |
@@ -16,3 +16,17 @@ /*global describe, it, beforeEach, before*/ | ||
describe('in plain mode', function () { | ||
it('throws if an unknown style is used', function () { | ||
expect(function () { | ||
magicpen().write('test', 'text').toString(); | ||
}, 'to throw', 'Unknown style: "test"'); | ||
}); | ||
it('throws when creating a custom style with a name that already exists', function () { | ||
forEach(['red', 'write', 'addStyle'], function (name) { | ||
expect(function () { | ||
magicpen().addStyle(name, function () {}); | ||
}, 'to throw', '"' + name + '" style is already defined'); | ||
}); | ||
}); | ||
describe('in text mode', function () { | ||
beforeEach(function () { | ||
@@ -295,3 +309,3 @@ pen = magicpen(); | ||
it('in plain mode', function () { | ||
it('in text mode', function () { | ||
var pen = magicpen(); | ||
@@ -379,3 +393,3 @@ writeRainbowWithPen(pen); | ||
it('in plain mode', function () { | ||
it('in text mode', function () { | ||
var pen = magicpen(); | ||
@@ -411,3 +425,3 @@ writeObjectWithPen(pen); | ||
it('in plain mode', function () { | ||
it('in text mode', function () { | ||
var pen = magicpen(); | ||
@@ -414,0 +428,0 @@ pen.addStyle('keyword', function (text) { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
65407
827
0