public
Last active

Just string templating.

  • Download Gist
string-proto.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11
String.prototype.format = function( params, opts){
var opts = opts || new Object();
opts.head = opts.head || '${';
opts.tail = opts.tail || '}';
var r = this;
for(param in params)
r = r.split( new Array(opts.head, param, opts.tail).join('') ).join(params[param]);
return r;
};
// var template = 'awe${neat}'.format({'neat':'some'});
// console.log(template);

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.