Last active
October 14, 2018 11:32
-
-
Save blackmambahk/c3a64160a2139efb745a to your computer and use it in GitHub Desktop.
Example of a template 'fmt' directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{fmt:'The %1 job is done. What %2 to do next?', @field1, @field2}} | |
//assumes we have added the Array Generics polyfill | |
//replacement elements start at 1 not 0 | |
//this code actually goes in the main format utility function | |
var reFmt1 = /%(\d+)/g; | |
function formatReplace(str) { | |
var args = Array.slice(arguments); | |
return str.replace(reFmt1, function($0, $1) { | |
return args[$1]; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment