https://github.com/borgar/string.format
A full implementation of Python string formatting in JavaScript.
https://github.com/borgar/string.format
Last synced: 8 months ago
JSON representation
A full implementation of Python string formatting in JavaScript.
- Host: GitHub
- URL: https://github.com/borgar/string.format
- Owner: borgar
- License: mit
- Created: 2010-03-07T21:28:20.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2010-04-03T01:34:27.000Z (about 16 years ago)
- Last Synced: 2023-03-11T00:18:59.496Z (over 3 years ago)
- Language: JavaScript
- Homepage:
- Size: 86.9 KB
- Stars: 5
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE.txt
Awesome Lists containing this project
README
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();