I have Javascript APIs where users call them with URLs. I may need to replace some parts of the URL, for example they might call my ajax photo upload API with their upload URL:
http://www.example.com/photos/upload/${username};jsessionid=l2k34523
I then need to post to that URL when my code uploads a photo, replacing the ${username}. I can tell them how to format that username variable in the URL, but I have to allow them to insert variables like this.
Is there a good Javascript or jQuery library to easily replace variables like the above?
A simple
formatfunction can do the trick for you…So you can easily just use it as:
or with multiple variables: