Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create string formatter #44

Open
AndreOneti opened this issue Dec 14, 2021 · 0 comments
Open

Create string formatter #44

AndreOneti opened this issue Dec 14, 2021 · 0 comments
Labels
feature New implementation

Comments

@AndreOneti
Copy link
Owner

Jus formatter like

// First, checks if it isn't implemented yet.
if (!String.prototype.format) {
  String.prototype.format = function() {
    var args = arguments;
    return this.replace(/{(\d+)}/g, function(match, number) { 
      return typeof args[number] != 'undefined'
        ? args[number]
        : match
      ;
    });
  };
}

console.log("{0} is dead, but {1} is alive! {0} {2}".format("ASP", "ASP.NET"));
// ASP is dead, but ASP.NET is alive! ASP {2}
@AndreOneti AndreOneti added the feature New implementation label Dec 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New implementation
Projects
None yet
Development

No branches or pull requests

1 participant