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

Already on GitHub? Sign in to your account

Improved String.fmt handling of missing named arguments. #842

wants to merge 3 commits into


None yet
2 participants

dcporter commented Sep 30, 2012

Currently, if you format a string with named arguments, and don't submit all arguments, the missing named arguments will be replaced with 'undefined'. For example, the following call:

"%{first}, %{last}%{punctuation}".fmt({ first: 'Hello', punctuation: '!' });

will result in:

"Hello, undefined!"

Along with being useless, this also prevents the use case where you have a string that you want to format over several calls, for example:

var hiWorld = "%{first}, %{last}%{punctuation}"
hiWorld = hiWorld.fmt({ first: 'Hello', last: 'World' });
hiWorld = hiWorld.fmt({ punctuation: '!' });

I've updated the fmt code so that if the formatter submethod returns undefined, it leaves the argument in the string. So the original example:

"%{first}, %{last}%{punctuation}".fmt({ first: 'Hello', punctuation: '!' });

will result in:

"Hello, %{last}!"

...allowing you to a) know what's going on and b) do another round of formatting later on.


publickeating commented Jan 16, 2013

This seems like a welcome improvement. Rebased onto master.


@dcporter dcporter deleted the team/dcporter/string-fmt branch Mar 13, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment