Skip to content

Instantly share code, notes, and snippets.

@u01jmg3
Created December 17, 2016 14:17
Show Gist options
  • Save u01jmg3/a1dce236baad439e73082646b7fc4ee6 to your computer and use it in GitHub Desktop.
Save u01jmg3/a1dce236baad439e73082646b7fc4ee6 to your computer and use it in GitHub Desktop.
sprintf - simple function for formatting strings
/**
* Simple function for formatting strings.
*
* Replaces placeholders with values passed as extra arguments
*
* @param {string} format the base string
* @param ...args the values to insert
* @return {string} the replaced string
*/
function sprintf(format, ...args) {
let index = 0;
return format.replace(/%s/g, match => args[index++]);
}
export { sprintf };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment