mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 02:23:40 +08:00
3501533a2b
We had Prettier pinned because of https://github.com/prettier/prettier/issues/5529. Since that bug is fixed, unpinning. Prettier now supports YAML, so this applies Prettier to all .yml except for translations, which should not be edited directly anyway.
30 lines
760 B
JavaScript
30 lines
760 B
JavaScript
import Ember from "ember";
|
|
|
|
const isArray = Ember.isArray;
|
|
|
|
export default function(str, formats) {
|
|
let cachedFormats = formats;
|
|
|
|
if (!isArray(cachedFormats) || arguments.length > 2) {
|
|
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];
|
|
return typeof s === "string"
|
|
? s
|
|
: s === null
|
|
? "(null)"
|
|
: s === undefined
|
|
? ""
|
|
: "" + s;
|
|
});
|
|
}
|