You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
594 B
26 lines
594 B
|
7 months ago
|
/*
|
||
|
|
* format.js: `util.format` enhancement to allow custom formatting parameters.
|
||
|
|
*
|
||
|
|
* (C) 2012, Nodejitsu Inc.
|
||
|
|
* MIT LICENSE
|
||
|
|
*
|
||
|
|
*/
|
||
|
|
|
||
|
|
var util = require('util');
|
||
|
|
|
||
|
|
exports = module.exports = function(str) {
|
||
|
|
var formats = [].slice.call(arguments, 1, 3);
|
||
|
|
|
||
|
|
if (!(formats[0] instanceof Array && formats[1] instanceof Array) || arguments.length > 3)
|
||
|
|
return util.format.apply(null, arguments);
|
||
|
|
|
||
|
|
var replacements = formats.pop(),
|
||
|
|
formats = formats.shift();
|
||
|
|
|
||
|
|
formats.forEach(function(format, id) {
|
||
|
|
str = str.replace(new RegExp(format), replacements[id]);
|
||
|
|
});
|
||
|
|
|
||
|
|
return str;
|
||
|
|
};
|