Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

asolis
Copy link

@asolis asolis commented Jul 23, 2016

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

sprintf("${1} ${2} ${0}", [ 7, 9, 11])

will return

"9 11 7"

It's also possible to concatenate index access, e.g., ${3.0.1} will take the value at elem[3][0][1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant