poe-i18n
Version:
i18n utility for Path of Exile
173 lines (172 loc) • 6.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var mod_value_to_item_class_1 = require("./mod_value_to_item_class");
var per_minute_to_per_second_1 = require("./per_minute_to_per_second");
var regexp_util_1 = require("./regexp_util");
/*
* rule of thumb: is the formatter self explanatory and only need
* arguments => declare in this file. Otherwise create additional
* files. `mod_value_to_item_class` needs auxiliary item_classes and
* per_minute_to_per_second has some extra documentation
*/
exports.formatters = {
deciseconds_to_seconds: {
format: function (n) { return "" + n * 10; },
inverse: function (s) { return +s / 10; },
regexp: regexp_util_1.NUMBER,
negates: false
},
divide_by_two_0dp: {
format: function (n) { return (n / 2).toFixed(0); },
inverse: function (s) { return +s * 2; },
regexp: regexp_util_1.NUMBER,
negates: false
},
divide_by_ten_0dp: {
format: function (n) { return (n / 10).toFixed(0); },
inverse: function (s) { return +s * 10; },
regexp: regexp_util_1.NUMBER,
negates: false
},
divide_by_fifteen_0dp: {
format: function (n) { return (n / 15).toFixed(0); },
inverse: function (s) { return +s * 15; },
regexp: regexp_util_1.NUMBER,
negates: false
},
divide_by_twenty_then_double_0dp: {
format: function (n) { return "" + Math.floor(n / 20) * 2; },
inverse: function (s) { return +s * 10; },
regexp: regexp_util_1.NUMBER,
negates: false
},
divide_by_one_hundred: {
format: function (n) { return "" + n / 100; },
inverse: function (s) { return +s * 100; },
regexp: regexp_util_1.NUMBER + "\\.?\\d{0,2}",
negates: false
},
divide_by_one_hundred_2dp: {
format: function (n) { return (n / 100).toFixed(2); },
inverse: function (s) { return +s * 100; },
regexp: regexp_util_1.NUMBER + "\\.\\d{2}",
negates: false
},
per_minute_to_per_second: per_minute_to_per_second_1.default,
milliseconds_to_seconds: {
format: function (n) { return "" + n / 1000; },
inverse: function (s) { return +s * 1000; },
regexp: regexp_util_1.NUMBER + "\\.?\\d{0,3}",
negates: false
},
negate: {
format: function (n) { return "" + -n; },
inverse: function (s) { return -s; },
regexp: regexp_util_1.NUMBER,
negates: true
},
divide_by_one_hundred_and_negate: {
format: function (n) { return "" + -n / 100; },
inverse: function (s) { return -s * 100; },
regexp: regexp_util_1.NUMBER + "\\.?\\d{0,2}",
negates: false
},
old_leech_percent: {
format: function (n) { return "" + n / 5; },
inverse: function (s) { return +s * 5; },
regexp: regexp_util_1.NUMBER + "\\.?\\d{0,2}",
negates: false
},
old_leech_permyriad: {
format: function (n) { return "" + n / 50; },
inverse: function (s) { return +s * 50; },
regexp: regexp_util_1.NUMBER + "\\.?\\d{0,2}",
negates: false
},
per_minute_to_per_second_0dp: {
format: function (n) { return (n / 60).toFixed(0); },
inverse: function (s) { return +s * 60; },
regexp: regexp_util_1.NUMBER,
negates: false
},
per_minute_to_per_second_2dp: {
format: function (n) { return (n / 60).toFixed(2); },
inverse: function (s) { return +s * 60; },
regexp: regexp_util_1.NUMBER + "\\.\\d{2}",
negates: false
},
per_minute_to_per_second_2dp_if_required: {
format: function (n) { return (n / 60).toFixed(2).replace(/\.?0*$/, ''); },
inverse: function (s) { return +s * 60; },
regexp: regexp_util_1.NUMBER + "\\.?\\d{0,2}",
negates: false
},
milliseconds_to_seconds_0dp: {
format: function (n) { return (n / 1000).toFixed(0); },
inverse: function (s) { return +s * 1000; },
regexp: regexp_util_1.NUMBER,
negates: false
},
milliseconds_to_seconds_2dp: {
format: function (n) { return (n / 1000).toFixed(2); },
inverse: function (s) { return +s * 1000; },
regexp: regexp_util_1.NUMBER + "\\.?\\d{2}",
negates: false
},
multiplicative_damage_modifier: {
format: function (n) { return "" + n; },
inverse: function (s) { return +s; },
regexp: regexp_util_1.NUMBER,
negates: false
},
'60%_of_value': {
format: function (n) { return "" + n * 0.6; },
inverse: function (s) { return +s / 0.6; },
regexp: regexp_util_1.NUMBER + "\\.?\\d*",
negates: false
},
id: {
format: function (n) { return "" + n; },
inverse: function (s) { return +s; },
regexp: regexp_util_1.NUMBER,
negates: false
},
mod_value_to_item_class: mod_value_to_item_class_1.default,
// TODO what is this
canonical_stat: {
format: function (n) { return "" + n; },
inverse: function (s) { return +s; },
regexp: regexp_util_1.NUMBER,
negates: false
},
placeholder: {
format: function () { return '#'; },
inverse: function () { return Number.NaN; },
regexp: '#',
negates: false
}
};
function inverseFactory(formatter_id) {
var inverse = buildFormatter(formatter_id).inverse;
// TODO add ranges
return inverse;
}
exports.inverseFactory = inverseFactory;
function regexpFactory(formatter_id) {
var regexp = buildFormatter(formatter_id).regexp;
// TODO add ranges
return regexp;
}
exports.regexpFactory = regexpFactory;
function buildFormatter(formatter_id) {
if (!exports.formatters.hasOwnProperty(formatter_id)) {
throw new Error("'" + formatter_id + "' not found");
}
return exports.formatters[formatter_id];
}
exports.buildFormatter = buildFormatter;
function factory(formatter_id) {
var format = buildFormatter(formatter_id).format;
return format;
}
exports.default = factory;