Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / utile / lib / format.js
1 /*
2  * format.js: `util.format` enhancement to allow custom formatting parameters.
3  *
4  * (C) 2012, Nodejitsu Inc.
5  * MIT LICENSE
6  *
7  */
8
9 var util = require('util');
10
11 exports = module.exports = function(str) {
12   var formats = [].slice.call(arguments, 1, 3);
13
14   if (!(formats[0] instanceof Array && formats[1] instanceof Array) || arguments.length > 3)
15     return util.format.apply(null, arguments);
16
17   var replacements = formats.pop(),
18       formats = formats.shift();
19
20   formats.forEach(function(format, id) {
21     str = str.replace(new RegExp(format), replacements[id]);
22   });
23
24   return str;
25 };