moappi / json2html

Json2html is a lightning fast client side javascript HTML templating library with wrappers for both jQuery and Node.js.
https://www.json2html.com
MIT License
626 stars 104 forks source link

Using sprintf like syntax to format the html output. #21

Open asolis opened 8 years ago

asolis commented 8 years ago

It adds the possibility of formatting the string in place using sprintf syntax. Otherwise, a function needs to be created or the json data have to be formatted before hand.

The sprintf function was modified to use the same syntax of json2html for back compatibility, e.g., ${name.0.subname.1}.

As a consecuence the tokenizer function has been removed, the sprintf function does the necessary steps for parsing the values.

example: var transform = {"<>":"i", "html":"${name} ${lastname} ${id}03d ${salary}.2f"}

John Smith 001 5000.50