Skip to content

Instantly share code, notes, and snippets.

View aggieben's full-sized avatar
🏠
Working from home

Ben Collins aggieben

🏠
Working from home
View GitHub Profile
@tbranyen
tbranyen / string.format.js
Created June 27, 2011 18:22
safer string formatting
// Inspired by http://bit.ly/juSAWl
// Augment String.prototype to allow for easier formatting. This implementation
// doesn't completely destroy any existing String.prototype.format functions,
// and will stringify objects/arrays.
String.prototype.format = function(i, safe, arg) {
function format() {
var str = this, len = arguments.length+1;
// For each {0} {1} {n...} replace with the argument in that position. If