From 20204baf1807825af4798ad03bfb329e4da05bc5 Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 21 Dec 2021 16:50:49 +0100 Subject: Commit --- node_modules/utile/lib/format.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 node_modules/utile/lib/format.js (limited to 'node_modules/utile/lib/format.js') diff --git a/node_modules/utile/lib/format.js b/node_modules/utile/lib/format.js new file mode 100644 index 0000000..dfa25e8 --- /dev/null +++ b/node_modules/utile/lib/format.js @@ -0,0 +1,25 @@ +/* + * format.js: `util.format` enhancement to allow custom formatting parameters. + * + * (C) 2011, Charlie Robbins & the Contributors + * 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; +}; -- cgit