Created
January 3, 2018 23:03
-
-
Save redgoose-dev/e4ab20ad1d64c8a45ee7c2ab5a87213d to your computer and use it in GitHub Desktop.
String util
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
/** | |
* printf | |
* | |
* @param {String} str | |
* @param {String} values | |
* @return {String} | |
*/ | |
export function printf(str, ...values) | |
{ | |
for (let i = 0; i < values.length; i++) | |
{ | |
let pattern = `\\{${i}\\}`; | |
let replace = new RegExp(pattern, 'g'); | |
str = str.replace(replace, values[i]); | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment