Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
String util
* 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