Skip to content

Instantly share code, notes, and snippets.

@hotchpotch
Created February 20, 2009 08:49
Show Gist options
  • Save hotchpotch/67381 to your computer and use it in GitHub Desktop.
Save hotchpotch/67381 to your computer and use it in GitHub Desktop.
/*
* %s, %d, %f only
*/
const _SPRINTF_HASH = {
'%s': String,
'%d': parseInt,
'%f': parseFloat,
};
var sprintf = function (str) {
let args = Array.slice(arguments, 1);
return str.replace(/%[sdf]/g, function(m) _SPRINTF_HASH[m](args.shift()));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment