Skip to content

Leave original placeholder if attribute is not present in passed object #165

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

Closed
wants to merge 5 commits into from

Conversation

vdiez
Copy link

@vdiez vdiez commented Feb 13, 2018

When using named arguments, value in output for the field is currently replaced to 'undefined'. This change leaves the original placeholder instead of changing its value.

@vdiez
Copy link
Author

vdiez commented Sep 30, 2020

any option to have this PR merged?

@alexei
Copy link
Owner

alexei commented Sep 30, 2020

Sorry - what is this about?

@vdiez
Copy link
Author

vdiez commented Sep 30, 2020

Imagine this use case where placeholders to replace are spread among different objects:

let command = 'cp %(source)s %(target)s' 
let params1 = {source: '/mnt/file1'} 
let params2 = {target: '/mnt/file2'}

With this change I can chain them like that:

let command = sprintf(command, params1)
let command = sprintf(command, params2)

With current version I cannot, because after the first call, the placeholder %(target)s will be replaced by undefined.

@alexei
Copy link
Owner

alexei commented Sep 30, 2020

This has been asked and discussed before, and I stand by my opinion that one should validate their data.

Besides, use cases such as this one could be implemented using Proxy objects where they e.g. return %(property)s for each missing property.

@vdiez
Copy link
Author

vdiez commented Sep 30, 2020

In my case data is validated, but there is a workflow where each parameter/-s is provided on a different step and by different modules. Of course, my example was way simpler than real use case.

My opinion is that this PR keeps the result more stateless and in any case i doubt having undefined in the final string is preferable and cleaner when the property is not found.

I understand the subjectivity of this. Feel free to close the PR

@alexei
Copy link
Owner

alexei commented Sep 30, 2020

Does it work if params1, params2 are Proxy objects?

@vdiez
Copy link
Author

vdiez commented Sep 30, 2020

ok, i was doing a long explanation of why not until I understood what you meant.

so yes, Proxy object should work. I'll do that then :)

cheers

@alexei alexei closed this Oct 1, 2020
@alexei alexei mentioned this pull request Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants