Skip to content

Commit

Permalink
Added support for string interpolation. Fixes #20 & fixes #23
Browse files Browse the repository at this point in the history
* feat(): support printf-like formatting

* fix(test): removed one code comment

* fix(#24): Print stringified and colorized objects

* refactor: requested changes done but except message destructuring

* fix: message destructuring and changed const to let for assign args in message when message undefined

* fix: lint error

* refactor: simplify to a one-liner

* fix: tslint error and changed let to const

* fix: checked suffux and prefix exists or not by func

* refactor
  • Loading branch information
rjoydip authored and klaudiosinani committed Jun 9, 2018
1 parent b341834 commit 3d1b9c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ yarn.lock
.vscode
.idea
*.swp
*.swo
*.swo
9 changes: 7 additions & 2 deletions signale.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const util = require('util');
const path = require('path');
const chalk = require('chalk');
const figures = require('figures');
Expand Down Expand Up @@ -154,6 +155,10 @@ class Signale {
return meta;
}

_hasAdditional({suffix, prefix}, args) {
return (suffix || prefix) ? '' : util.format(...args);
}

_buildSignale(type, ...args) {
let [msg, additional] = [{}, {}];

Expand All @@ -162,11 +167,11 @@ class Signale {
[msg] = args;
} else {
const [{prefix, message, suffix}] = args;
msg = message;
additional = Object.assign({}, {suffix, prefix});
msg = message ? util.format(...message) : this._hasAdditional(additional, args);
}
} else {
msg = args.join(' ');
msg = util.format(...args);
}

const signale = this._meta();
Expand Down

0 comments on commit 3d1b9c7

Please sign in to comment.