Advertisement
MaxiBarometer

format

Jul 27th, 2021
1,156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String.prototype.format = function(){
  2.   let ret = this + ""
  3.   let matches = this.matchAll(/{([^}]*)}/g);
  4.     let i = 0;
  5.   for (let match of matches) {
  6.         let tag = match[1];
  7.     let index = Number(tag)
  8.         if (!tag || isNaN(index)) {index = i;++i}
  9.         ret = ret.replace(/{[^}]*}/, arguments[index]);
  10.     }
  11.     return ret;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement