poe-i18n
Version:
i18n utility for Path of Exile
110 lines (109 loc) • 3.75 kB
JavaScript
;
var __assign = (this && this.__assign) || Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
var __values = (this && this.__values) || function (o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
};
Object.defineProperty(exports, "__esModule", { value: true });
var stats_1 = require("./stats");
/**
* tries to find a string that describes the given mods
*
* given a list of mods where a mod consists of at least one stat
* get a translation t of that mod and consider it a row
* split t into words and consider every word as a column
* collapse the table into a single row
* columns with different words get resolved by a given strategy
*
*
*
* Adds # to Fire Gems
* Adds # to Cold Gems
* ----
* Adds # to * Gems
*
* @param mods
* @param options
*/
function groupMod(mods, options) {
if (options === void 0) { options = {}; }
var e_1, _a;
// default options
var _b = options.resolveWordConflict, resolveWordConflict = _b === void 0 ? function () { return '*'; } : _b, format_stats_options = __rest(options, ["resolveWordConflict"]);
// reduce mods to array
var translations = [];
try {
for (var mods_1 = __values(mods), mods_1_1 = mods_1.next(); !mods_1_1.done; mods_1_1 = mods_1.next()) {
var mod = mods_1_1.value;
translations.push(groupStats(mod, format_stats_options).split(' '));
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (mods_1_1 && !mods_1_1.done && (_a = mods_1.return)) _a.call(mods_1);
}
finally { if (e_1) throw e_1.error; }
}
return collapseTable(translations, resolveWordConflict)
.join(' ')
.replace(/\*( \*)*/, '*');
}
exports.default = groupMod;
function groupStats(stats, options) {
if (options === void 0) { options = {}; }
var lines = stats_1.default(stats, __assign({}, options, { getFormatters: function (t, s, n) {
return Array.from({ length: n }, function (_, i) { return ({
arg: i + 1,
id: 'placeholder'
}); });
} }));
// collapes value ranges into single placeholder
return lines.map(function (line) { return line.replace(/\(# - #\)/g, '#'); }).join(' / ');
}
function collapseTable(table, resolveColumnConflict) {
if (table.length < 1) {
return [];
}
var column_count = table[0].length;
// rows to columns
var columns = new Array(column_count);
var _loop_1 = function (j) {
columns[j] = table.reduce(function (column, row) {
return column.add(row[j]);
}, new Set());
};
for (var j = 0; j < column_count; ++j) {
_loop_1(j);
}
return columns.map(function (column) {
if (column.size > 1) {
return resolveColumnConflict(Array.from(column));
}
else {
return column.values().next().value;
}
});
}