Skip to content

Commit

Permalink
Merge pull request #29 from wearelucid/feature/padding-config-disable
Browse files Browse the repository at this point in the history
[Feature] Make padding and separator configurable
  • Loading branch information
Philip Roberts authored Jul 3, 2017
2 parents 3980667 + 4ee169c commit 334d8a6
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 7 deletions.
21 changes: 19 additions & 2 deletions bows.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
logger = require('andlog'),
bind = Function.prototype.bind,
hue = 0,
padding = true,
separator = '|',
padLength = 15,
noop = function() {},
// if ls.debugColors is set, use that, otherwise check for support
Expand All @@ -56,8 +58,13 @@

bows = function(str) {
var msg, colorString, logfn;
msg = (str.slice(0, padLength));
msg += Array(padLength + 3 - msg.length).join(' ') + '|';

if (padding) {
msg = (str.slice(0, padLength));
msg += Array(padLength + 3 - msg.length).join(' ') + separator;
} else {
msg = str + Array(3).join(' ') + separator;
}

if (debugRegex) {
var matches = str.match(debugRegex);
Expand Down Expand Up @@ -100,6 +107,16 @@
if (config.padLength) {
padLength = config.padLength;
}

if (typeof config.padding === 'boolean') {
padding = config.padding;
}

if (config.separator) {
separator = config.separator;
} else if (config.separator === false || config.separator === '') {
separator = ''
}
};

if (typeof module !== 'undefined') {
Expand Down
21 changes: 19 additions & 2 deletions dist/bows.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
logger = require('andlog'),
bind = Function.prototype.bind,
hue = 0,
padding = true,
separator = '|',
padLength = 15,
noop = function() {},
// if ls.debugColors is set, use that, otherwise check for support
Expand All @@ -58,8 +60,13 @@

bows = function(str) {
var msg, colorString, logfn;
msg = (str.slice(0, padLength));
msg += Array(padLength + 3 - msg.length).join(' ') + '|';

if (padding) {
msg = (str.slice(0, padLength));
msg += Array(padLength + 3 - msg.length).join(' ') + separator;
} else {
msg = str + Array(3).join(' ') + separator;
}

if (debugRegex) {
var matches = str.match(debugRegex);
Expand Down Expand Up @@ -102,6 +109,16 @@
if (config.padLength) {
padLength = config.padLength;
}

if (typeof config.padding === 'boolean') {
padding = config.padding;
}

if (config.separator) {
separator = config.separator;
} else if (config.separator === false || config.separator === '') {
separator = ''
}
};

if (typeof module !== 'undefined') {
Expand Down
2 changes: 1 addition & 1 deletion dist/bows.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ var scripts = [
'test/regex.html',
'test/not-regex.html',
'test/color-map.html',
'test/separator.html',
'test/no-separator.html',
'test/padLength.html',
'test/no-padding.html',
'test/args.html'
];

Expand Down
34 changes: 34 additions & 0 deletions test/no-padding.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<script type="text/javascript" src='./helpers/function.bind.js'></script>

<script>
localStorage.clear();
localStorage.debug = true;
</script>

<script src="../dist/bows.js"></script>

<script>
var mainLog, altLog;

bows.config({
padding: false
});

window.expectedLogs = [
'this-is-a-really-long-module-name-thats-more-than-50-chars | foo',
'this-is-a-really-long-module-name-thats-more-than-50-chars | bar',

'this-is-a-really-long-module-name | baz',
'this-is-a-really-long-module-name | buz'
];

window.onload = function() {
mainLog = window.bows('this-is-a-really-long-module-name-thats-more-than-50-chars')
mainLog('foo');
mainLog('bar');

altLog = window.bows('this-is-a-really-long-module-name')
altLog('baz');
altLog('buz');
}
</script>
37 changes: 37 additions & 0 deletions test/no-separator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

<script type="text/javascript" src='./helpers/function.bind.js'></script>

<script>
localStorage.clear();
localStorage.debug = true;
</script>

<script src="../dist/bows.js"></script>

<script>
var mainLog, altLog;

bows.config({
separator: false
});

window.expectedLogs = [
'mainLog foo',
'mainLog bar',
'mainLog bar',

'altLog baz',
'altLog buz'
];

window.onload = function() {
mainLog = window.bows('mainLog')
mainLog('foo');
mainLog('bar');
mainLog.log('bar');

altLog = window.bows('altLog')
altLog('baz');
altLog('buz');
}
</script>
36 changes: 36 additions & 0 deletions test/separator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<script type="text/javascript" src='./helpers/function.bind.js'></script>

<script>
localStorage.clear();
localStorage.debug = true;
</script>

<script src="../dist/bows.js"></script>

<script>
var mainLog, altLog;

bows.config({
separator: '//'
});

window.expectedLogs = [
'mainLog // foo',
'mainLog // bar',
'mainLog // bar',

'altLog // baz',
'altLog // buz'
];

window.onload = function() {
mainLog = window.bows('mainLog')
mainLog('foo');
mainLog('bar');
mainLog.log('bar');

altLog = window.bows('altLog')
altLog('baz');
altLog('buz');
}
</script>
2 changes: 0 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
window.localStorage = true;

var bows = require('bows');


0 comments on commit 334d8a6

Please sign in to comment.