Comparing version 0.3.9 to 0.3.10
@@ -14,14 +14,2 @@ #!/usr/bin/nodejs | ||
/** | ||
* @private | ||
* Private helper function that makes sure any received prefix is formatted properly | ||
* | ||
* @param {String} prefix A prefix that will appear before the emission | ||
* @param {Boolean} [includeSeparator] Whether to include the separator between | ||
* the postfix and the prefix | ||
* | ||
* @return {String} The new prefix | ||
*/ | ||
let fixPrefix; | ||
/** | ||
* The Echo class exposes an API for echoing out to stdoutin a clean and concise | ||
@@ -40,6 +28,6 @@ * manner. | ||
let beVerbose = false; | ||
let separator = ' '; | ||
let messageSeparator = ' '; | ||
let postfixSeparator = ':'; | ||
let emitStrategy = null; | ||
let separatePostfix = true; | ||
prefix = prefix || null; | ||
prefix = prefix || ''; | ||
@@ -80,3 +68,3 @@ /** | ||
get() { return prefix; }, | ||
set(val) { prefix = !val ? null : val.toString(); } | ||
set(val) { prefix = !val ? '' : val.toString(); } | ||
}); | ||
@@ -96,20 +84,20 @@ | ||
/** | ||
* @property {Boolean} separatePostfix | ||
* @property {String} messageSeparator | ||
* | ||
* Indicates that the script should include the separator between the | ||
* prefix body and the postfix. | ||
* The value that will be printed between the prefix and the postfix/message | ||
*/ | ||
Object.defineProperty(this, 'separatePostfix', { | ||
get() { return separatePostfix; }, | ||
set(val) { separatePostfix = !!val; } | ||
Object.defineProperty(this, 'messageSeparator', { | ||
get() { return messageSeparator; }, | ||
set(val) { messageSeparator = !val ? '' : val.toString(); } | ||
}); | ||
/** | ||
* @property {String} separator | ||
* @property {String} postfixSeparator | ||
* | ||
* The value that will be printed between the prefix and the message | ||
* The value that will be printed between the postfix and the message. If | ||
* there is no prefix, this will return an empty string. | ||
*/ | ||
Object.defineProperty(this, 'separator', { | ||
get() { return separator; }, | ||
set(val) { separator = !val ? '' : val.toString(); } | ||
Object.defineProperty(this, 'postfixSeparator', { | ||
get() { return !!this.prefix ? postfixSeparator : ''; }, | ||
set(val) { postfixSeparator = !val ? '' : val.toString(); } | ||
}); | ||
@@ -196,8 +184,2 @@ | ||
this.withPostfix.ok = lambdaFactory('OK', 'formatAsSuccess'); | ||
fixPrefix = (prefix, includeSeparator) => | ||
{ | ||
prefix = (!!prefix ? prefix : (!!this.prefix ? this.prefix : '')).toString(); | ||
return prefix.length && includeSeparator ? prefix + this.separator : prefix; | ||
}; | ||
} | ||
@@ -215,6 +197,5 @@ | ||
let message = msg.join(' '); | ||
let prefix = fixPrefix(this.prefix); | ||
let separator = prefix.length ? this.separator : ''; | ||
let separator = this.prefix.length ? this.messageSeparator : ''; | ||
return this.emitStrategy.emit(`${prefix}${separator}${message}`); | ||
return this.emitStrategy.emit(`${this.prefix}${separator}${message}`); | ||
} | ||
@@ -295,3 +276,3 @@ | ||
return this.withPrefix( | ||
fixPrefix(this.prefix, this.separatePostfix) + 'DEBUG', | ||
this.prefix + this.postfixSeparator + 'DEBUG', | ||
() => this.if(...msg) | ||
@@ -351,3 +332,3 @@ ); | ||
return this.withPrefix( | ||
fixPrefix(this.prefix, this.separatePostfix) + postfix, | ||
this.prefix + this.postfixSeparator + postfix, | ||
() => this.now(...msg) | ||
@@ -354,0 +335,0 @@ ); |
{ | ||
"name": "rejoinder", | ||
"version": "0.3.9", | ||
"version": "0.3.10", | ||
"description": "A generator of smart, pretty, and organized output for Node/JS scripts in the terminal", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -36,35 +36,44 @@ [![npm version](https://badge.fury.io/js/rejoinder.svg)](https://badge.fury.io/js/rejoinder) | ||
```javascript | ||
var rejoinder = require('rejoinder'); | ||
var echo = rejoinder.echo; | ||
var execute = rejoinder.execute; | ||
const rejoinder = require('rejoinder'); | ||
let echo = rejoinder.echo; | ||
let execute = rejoinder.execute; | ||
echo.now('output this very important warning to the console with pretty colors'.formatAsWarning()); | ||
echo.now('output this very important warning to the console with pretty colors'.formatAsWarning()); // colorful output | ||
echo.withPostfix.warn('output this very important warning to the console with pretty colors'); // colorful output prefixed with the string "WARN " | ||
echo.beVerbose = true; | ||
echo.ifVerbose('Some debug message will appear'); | ||
echo.beVerbose = false; | ||
echo.ifVerbose('Some debug message will not appear!'); | ||
echo.beVerbose = true; // beVerbose fka "debugMode" | ||
echo.ifVerbose('Some message will appear if beVerbose is true'); | ||
echo.ifDebug('Some debug message will appear if beVerbose is true prefixed with the string "DEBUG "'); | ||
echo.beVerbose = false; // it is false by default | ||
echo.ifVerbose('Some message will NOT appear if beVerbose is false!'); | ||
echo.ifDebug('Some debug message will NOT appear if beVerbose is false!'); | ||
echo.if(somethingistrue, 'I spit only the truth!'.formatAsSuccess()); | ||
echo.if(somethingistrue, 'I spit only the truth!'.formatAsSuccess()); // also returns false if somethingistrue is false | ||
echo.now('all', 'my', 'methods', 'are', 'also', 'variadic!'); | ||
echo.if(true, 'even', 'this', 'one :)'); | ||
echo.now('all', 'my', 'methods', 'are', 'also', 'variadic!'); // prints "all my methods are also variadic!" | ||
echo.if(true, 'even', 'this', 'one :)'); // prints "even this one :)" | ||
echo.separator = '-'; | ||
echo.now('changed', 'the', 'game!'); | ||
echo.prefix = '>>'; // this will be printed directly before the message every time | ||
echo.now('changed', 'the', 'game!'); // prints ">> changed the game!" | ||
echo.separator = ' '; | ||
echo.prefix = 'Big:Boy:Time:'; | ||
echo.usingPredicate(function(str){ return `"${str}"`; }, 'the', 'time', 'for', 'fun and games is', 'over!'); | ||
echo.messageSeparator = '||'; // this is the thing between the prefix and the message | ||
echo.usingPredicate((str) => `"${str}"`, 'the', 'time', 'for', 'fun and games is', 'over!'); | ||
// the above prints `Big:Boy:Time:||"the" "time" "for" "fun and games is" "over!"` | ||
echo.withPrefix('~>', function() | ||
echo.withPostfix('postfix', 'this is', 'pretty cool'); // prints "Big:Boy:Time::postfix||this is pretty cool" | ||
echo.postfixSeparator = '<>'; // this is the thing between the prefix and the postfix. It goes `prefix + postfixsep + postfix + msgsep + message` | ||
echo.withPostfix('postfix', 'this too'); // prints "Big:Boy:Time:<>postfix||this too" | ||
echo.withPostfix.ok('GOT IT!'); // prints colorful output that says "Big:Boy:Time:<>OK||GOT IT!" | ||
echo.withPrefix('~>', () => // ONLY the echo statements that appear inside of this function will have the aforesaid prefix | ||
{ | ||
echo.now('or'); | ||
echo.now('is', 'it? I wonder.'); | ||
echo.withPostfix('NO', 'Wait!'); | ||
echo.withPostfix.action("Don't make me bring Execute into this..."); | ||
echo.now('or'); // prints "~>||or" | ||
echo.now('is', 'it? I wonder.'); // prints "~>||is it? I wonder." | ||
echo.withPostfix('NO', 'Wait!'); // prints "~><>NO||Wait!" | ||
echo.withPostfix.action("Don't make me bring Execute into this..."); // prints colorful output "~><>ACTION||Don't make me bring Execute into this..." | ||
}); | ||
echo.beVerbose = true; | ||
execute.now('return 0'); // prints the command and the result thanks to echo.beVerbose! | ||
execute.now('return 0'); // prints the command and the result of executing it thanks to echo.beVerbose! See API.md for more information on how this works | ||
``` | ||
@@ -71,0 +80,0 @@ |
@@ -48,14 +48,27 @@ #!/usr/bin/nodejs | ||
it('should have separator property = " "', function() | ||
it('should have messageSeparator property = " "', function() | ||
{ | ||
let echo = new Echo(); | ||
expects(echo).to.have.property('separator', ' '); | ||
expects(echo).to.have.property('messageSeparator', ' '); | ||
}); | ||
it('should have separatePostfix property = true', function() | ||
it('should have postfixSeparator property = "" when prefix is falsey', function() | ||
{ | ||
let echo = new Echo(); | ||
expects(echo).to.have.property('separatePostfix', true); | ||
expects(echo).to.have.property('postfixSeparator', ''); | ||
echo.prefix = ''; | ||
expects(echo).to.have.property('postfixSeparator', ''); | ||
echo.prefix = false; | ||
expects(echo).to.have.property('postfixSeparator', ''); | ||
}); | ||
it('should have postfixSeparator property = ":" when prefix is truthy', function() | ||
{ | ||
let echo = new Echo(); | ||
echo.prefix = 'yes'; | ||
expects(echo).to.have.property('postfixSeparator', ':'); | ||
echo.prefix = true; | ||
expects(echo).to.have.property('postfixSeparator', ':'); | ||
}); | ||
it('should have emitStrategy property = null', function() | ||
@@ -69,6 +82,6 @@ { | ||
{ | ||
it('should have prefix property = null', function() | ||
it('should have prefix property = ""', function() | ||
{ | ||
let echo = new Echo(); | ||
expects(echo).to.have.property('prefix', null); | ||
expects(echo).to.have.property('prefix', ''); | ||
}); | ||
@@ -106,3 +119,3 @@ }); | ||
the('prefix property should only be of type null or string', function() | ||
the('prefix property should only be of type string', function() | ||
{ | ||
@@ -114,3 +127,3 @@ let echo = new Echo(); | ||
echo.prefix = ''; | ||
expects(echo.prefix).to.be.null; | ||
expects(echo.prefix).to.be.a('string'); | ||
echo.prefix = { obj: 1 }; | ||
@@ -121,7 +134,7 @@ expects(echo.prefix).to.be.a('string'); | ||
echo.prefix = 0; | ||
expects(echo.prefix).to.be.null; | ||
expects(echo.prefix).to.be.a('string'); | ||
echo.prefix = true; | ||
expects(echo.prefix).to.be.a('string'); | ||
echo.prefix = false; | ||
expects(echo.prefix).to.be.null; | ||
expects(echo.prefix).to.be.a('string'); | ||
}); | ||
@@ -149,40 +162,40 @@ | ||
the('separatePostfix property should only be of type boolean', function() | ||
the('messageSeparator property should only be of type string', function() | ||
{ | ||
let echo = new Echo(); | ||
echo.separatePostfix = 'string'; | ||
expects(echo.separatePostfix).to.be.true; | ||
echo.separatePostfix = ''; | ||
expects(echo.separatePostfix).to.be.false; | ||
echo.separatePostfix = { obj: 1 }; | ||
expects(echo.separatePostfix).to.be.true; | ||
echo.separatePostfix = 1; | ||
expects(echo.separatePostfix).to.be.true; | ||
echo.separatePostfix = 0; | ||
expects(echo.separatePostfix).to.be.false; | ||
echo.separatePostfix = true; | ||
expects(echo.separatePostfix).to.be.true; | ||
echo.separatePostfix = false; | ||
expects(echo.separatePostfix).to.be.false; | ||
echo.messageSeparator = 'string'; | ||
expects(echo.messageSeparator).to.be.a('string'); | ||
echo.messageSeparator = ''; | ||
expects(echo.messageSeparator).to.be.a('string'); | ||
echo.messageSeparator = { obj: 1 }; | ||
expects(echo.messageSeparator).to.be.a('string'); | ||
echo.messageSeparator = 1; | ||
expects(echo.messageSeparator).to.be.a('string'); | ||
echo.messageSeparator = 0; | ||
expects(echo.messageSeparator).to.be.a('string'); | ||
echo.messageSeparator = true; | ||
expects(echo.messageSeparator).to.be.a('string'); | ||
echo.messageSeparator = false; | ||
expects(echo.messageSeparator).to.be.a('string'); | ||
}); | ||
the('separator property should only be of type string', function() | ||
the('postfixSeparator property should only be of type string', function() | ||
{ | ||
let echo = new Echo(); | ||
echo.separator = 'string'; | ||
expects(echo.separator).to.be.a('string'); | ||
echo.separator = ''; | ||
expects(echo.separator).to.be.a('string'); | ||
echo.separator = { obj: 1 }; | ||
expects(echo.separator).to.be.a('string'); | ||
echo.separator = 1; | ||
expects(echo.separator).to.be.a('string'); | ||
echo.separator = 0; | ||
expects(echo.separator).to.be.a('string'); | ||
echo.separator = true; | ||
expects(echo.separator).to.be.a('string'); | ||
echo.separator = false; | ||
expects(echo.separator).to.be.a('string'); | ||
echo.postfixSeparator = 'string'; | ||
expects(echo.postfixSeparator).to.be.a('string'); | ||
echo.postfixSeparator = ''; | ||
expects(echo.postfixSeparator).to.be.a('string'); | ||
echo.postfixSeparator = { obj: 1 }; | ||
expects(echo.postfixSeparator).to.be.a('string'); | ||
echo.postfixSeparator = 1; | ||
expects(echo.postfixSeparator).to.be.a('string'); | ||
echo.postfixSeparator = 0; | ||
expects(echo.postfixSeparator).to.be.a('string'); | ||
echo.postfixSeparator = true; | ||
expects(echo.postfixSeparator).to.be.a('string'); | ||
echo.postfixSeparator = false; | ||
expects(echo.postfixSeparator).to.be.a('string'); | ||
}); | ||
@@ -258,13 +271,13 @@ | ||
it('should emit properly when a different separator is set', function() | ||
it('should emit properly when a different messageSeparator is set', function() | ||
{ | ||
echo.separator = ''; | ||
echo.messageSeparator = ''; | ||
echo.now('t', 'e', 's', 't'); | ||
expects(emission).to.equal('t e s t'); | ||
echo.separator = false; | ||
echo.messageSeparator = false; | ||
echo.now('t', 'e', 's', 't'); | ||
expects(emission).to.equal('t e s t'); | ||
echo.separator = '-'; | ||
echo.messageSeparator = '-'; | ||
echo.now('t', 'e', 's', 't'); | ||
@@ -274,15 +287,15 @@ expects(emission).to.equal('t e s t'); | ||
it('should emit properly with a set prefix when a different separator is set', function() | ||
it('should emit properly with a set prefix when a different messageSeparator is set', function() | ||
{ | ||
echo.prefix = '>>'; | ||
echo.separator = ''; | ||
echo.messageSeparator = ''; | ||
echo.now('t', 'e', 's', 't'); | ||
expects(emission).to.equal('>>t e s t'); | ||
echo.separator = false; | ||
echo.messageSeparator = false; | ||
echo.now('t', 'e', 's', 't'); | ||
expects(emission).to.equal('>>t e s t'); | ||
echo.separator = '-'; | ||
echo.messageSeparator = '-'; | ||
echo.now('t', 'e', 's', 't'); | ||
@@ -297,3 +310,3 @@ expects(emission).to.equal('>>-t e s t'); | ||
{ | ||
echo.separator = ''; | ||
echo.messageSeparator = ''; | ||
echo.usingPredicate(function(s){ return `-${s}-`; }, 't', 'e', 's', 't'); | ||
@@ -391,3 +404,3 @@ expects(emission).to.equal('-t- -e- -s- -t-'); | ||
echo.logFilePath = 'test.log'; | ||
echo.separator = '-'; | ||
echo.messageSeparator = '-'; | ||
echo.toLog(rand); | ||
@@ -413,8 +426,12 @@ | ||
echo.prefix = 'prefix'; | ||
echo.separator = '-'; | ||
echo.messageSeparator = '-'; | ||
echo.postfixSeparator = '-'; | ||
echo.withPostfix('postfix', 'test'); | ||
expects(emission).to.equal('prefix-postfix-test'); | ||
echo.separatePostfix = false; | ||
echo.postfixSeparator = ''; | ||
echo.withPostfix('postfix', 'test'); | ||
expects(emission).to.equal('prefixpostfix-test'); | ||
echo.messageSeparator = ''; | ||
echo.withPostfix('postfix', 'test'); | ||
expects(emission).to.equal('prefixpostfixtest'); | ||
}); | ||
@@ -421,0 +438,0 @@ |
52336
100
1060