2016-11-02 15:37:26 -04:00
|
|
|
export default function(str, formats) {
|
|
|
|
let cachedFormats = formats;
|
|
|
|
|
2020-02-21 09:56:49 -05:00
|
|
|
if (!_.isArray(cachedFormats) || arguments.length > 2) {
|
2016-11-02 15:37:26 -04:00
|
|
|
cachedFormats = new Array(arguments.length - 1);
|
|
|
|
|
|
|
|
for (let i = 1, l = arguments.length; i < l; i++) {
|
|
|
|
cachedFormats[i - 1] = arguments[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// first, replace any ORDERED replacements.
|
|
|
|
let idx = 0; // the current index for non-numerical replacements
|
|
|
|
return str.replace(/%@([0-9]+)?/g, function(s, argIndex) {
|
|
|
|
argIndex = argIndex ? parseInt(argIndex, 10) - 1 : idx++;
|
|
|
|
s = cachedFormats[argIndex];
|
2019-01-10 05:06:01 -05:00
|
|
|
return typeof s === "string"
|
|
|
|
? s
|
|
|
|
: s === null
|
2019-01-17 13:05:39 -05:00
|
|
|
? "(null)"
|
|
|
|
: s === undefined
|
|
|
|
? ""
|
|
|
|
: "" + s;
|
2016-11-02 15:37:26 -04:00
|
|
|
});
|
|
|
|
}
|