Skip to content

borgar/String.format

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

Stringformat

Provides a full implementation of Python style string formatting for JavaScript as outlined in the Python documentation: http://docs.python.org/library/stdtypes.html#string-formatting-operations

The function comes attached to String, and you may use it like that:

String.format( "I have %d apples, and %d pears.", [ 13, 10 ] );

It supports a simple argument:

String.format( "I have %d apples.", 9 );

If you want to move the function to string prototype where, arguably, it may be more useful:

String.prototype.format = function () {
  return String.format( this, arguments );
};

"I have %d apples, and %d pears..".format( 9, 12 );

Additionally, the function support a noConflict method which allows you to unassign it from String and into whatever name you want.

$.format = String.format.noConflict();

About

A full implementation of Python string formatting in JavaScript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published