[{"title":"$:/plugins/sq/filters/filters/printf.js","text":"/*\\\ntitle: $:/plugins/sq/filters/filters/printf.js\ntype: application/javascript\nmodule-type: filteroperator\n\n<$vars name=Saq age=140>\n<$text text={{{ [[My name is $(name)$ and $0$ my age is $(age)$.]printf[I think]] }}}/>\n</$vars>\n\n<$text text={{{ [[My name is $0$ and my age is $1$.]printf[Saq],[100]] }}}/>\n\n\\*/\n(function(){\n\n/*jslint node: true, browser: true */\n/*global $tw: false */\n\"use strict\";\n\n/*\nExport our filter function\n*/\nexports.printf = function(source,operator,options) {\n\tvar results = [];\t\n\tfunction substitute(str) {\t\t\n\t\tvar output = str.replace(/\\$\\((\\w+)\\)\\$/g, function(match,varname) {\n\t\t\treturn options.widget.getVariable(varname,{defaultValue: \"\"})\n\t\t});\n\t\toutput = output.replace(/\\$(\\d)\\$/g, function(match,operandIndex) {\n\t\t\tif(operator.operands[operandIndex]) {\n\t\t\t\treturn operator.operands[operandIndex];\n\t\t\t} else {\n\t\t\t\treturn \"$\" + operandIndex + \"$\";\n\t\t\t}\n\t\t});\n\t\treturn(output);\n\t}\n\t\n\tsource(function(tiddler,title) {\n\t\tif(title) {\n\t\t\tresults.push(substitute(title));\n\t\t}\n\t});\n\treturn results;\n};\n\n})();","type":"application/javascript","module-type":"filteroperator"}]