Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for string interpolation. Fixes #20 #23

Merged
merged 17 commits into from
Jun 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion signale.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ class Signale {
return meta;
}

_prefixSufixNestedTernary(prefix, suffix, args) {
Copy link
Owner

@klaudiosinani klaudiosinani Jun 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! A couple of minor tweaks and it is ready to be merged! 🎉

  _hasAdditional({suffix, prefix}, args) { // Rename to something simpler, for example: _hasAdditional() 
    // Use destructuring directly on function definition
    return (suffix || prefix) ? '' : util.format(...args); // Add simple parentheses around the condition to make it clearer
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better than previous

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

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

Expand All @@ -163,7 +167,7 @@ class Signale {
[msg] = args;
} else {
const [{prefix, message, suffix}] = args;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here message is needed for destructuring args

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed message because now it became death code.
Here is the senerior which i am testing and getting { prefix: undefined, message: undefined, suffix: undefined }

signale.success({a: 2});
signale.success([1, 2]);

Can you give some use cases so tat i can check that.

Copy link
Owner

@klaudiosinani klaudiosinani Jun 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice! The only thing left is to bring back message for destructuring args :

const [{prefix, message, suffix}] = args;

and directly apply interpolation on it:

msg = util.format(...message);

Thank you a lot for taking the time to help out : )

Copy link
Contributor Author

@rjoydip-zz rjoydip-zz Jun 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that I have to do. I am getting {prefix, message, suffix} as undefined all the times

Copy link
Owner

@klaudiosinani klaudiosinani Jun 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it is only applicable when using the prefix and suffix attributes, for example:

const signale = require('signale');

signale.complete({prefix: '[task]', message: ['Fix issue #%s', 59], suffix: '(@santa)'});
//=> [task] ☒  complete  Fix issue #59 (@santa)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now I have to check undefined case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. message for destructuring args

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original comment: #23 (comment)

msg = message ? util.format(...message) : util.format(...args);
msg = message ? util.format(...message) : this._prefixSufixNestedTernary(prefix, suffix, ...args);
additional = Object.assign({}, {suffix, prefix});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor reordering of the assignments:

const [{prefix, message, suffix}] = args;
additional = Object.assign({}, {suffix, prefix});
msg = message ? util.format(...message) : this._hasAdditional(additional, args);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better than my previous method

}
} else {
Expand Down