sprintf.js
sprintf.js copied to clipboard
Preserve unmatched placeholders
As mentioned here https://github.com/alexei/sprintf.js/issues/8#issuecomment-152675119, it would be nice to have option to return unmatched placeholders as they are.
For example, when we have this:
sprintf('Test number %s')
instead of 'Test number undefined' return 'Test number %s'
And same for named placeholders:
sprintf('%(name)s number 1')
instead of error about non-existing placeholder return '%(name)s number 1'
This will make possible complex chaining, when you need to process strings by few modules.
So far can't tell for sure how should it be done.
I have few options:
-
Global option during
sprintfinvocation:sprintf = require('sprintf-js').sprintf({ preservePlaceholders: true }) sprintf('%(name)s number 1')` -> `'%(name)s number 1'` -
Live switch in and switch off:
sprintf.preservePlaceholders(true) sprintf('%(name)s number 1')` -> `'%(name)s number 1'` sprintf.preservePlaceholders(false) -
Special
sprintfpfunction:sprintfp('%(name)s number 1')` -> `'%(name)s number 1'`
+1