Created
December 17, 2016 14:17
-
-
Save u01jmg3/a1dce236baad439e73082646b7fc4ee6 to your computer and use it in GitHub Desktop.
sprintf - simple function for formatting strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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