UNPKG

poe-i18n

Version:

i18n utility for Path of Exile

167 lines (166 loc) 5.6 kB
import mod_value_to_item_class from './mod_value_to_item_class'; import per_minute_to_per_second from './per_minute_to_per_second'; import { NUMBER } from './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 */ export var formatters = { deciseconds_to_seconds: { format: function (n) { return "" + n * 10; }, inverse: function (s) { return +s / 10; }, regexp: NUMBER, negates: false }, divide_by_two_0dp: { format: function (n) { return (n / 2).toFixed(0); }, inverse: function (s) { return +s * 2; }, regexp: NUMBER, negates: false }, divide_by_ten_0dp: { format: function (n) { return (n / 10).toFixed(0); }, inverse: function (s) { return +s * 10; }, regexp: NUMBER, negates: false }, divide_by_fifteen_0dp: { format: function (n) { return (n / 15).toFixed(0); }, inverse: function (s) { return +s * 15; }, regexp: 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: NUMBER, negates: false }, divide_by_one_hundred: { format: function (n) { return "" + n / 100; }, inverse: function (s) { return +s * 100; }, regexp: 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: NUMBER + "\\.\\d{2}", negates: false }, per_minute_to_per_second: per_minute_to_per_second, milliseconds_to_seconds: { format: function (n) { return "" + n / 1000; }, inverse: function (s) { return +s * 1000; }, regexp: NUMBER + "\\.?\\d{0,3}", negates: false }, negate: { format: function (n) { return "" + -n; }, inverse: function (s) { return -s; }, regexp: NUMBER, negates: true }, divide_by_one_hundred_and_negate: { format: function (n) { return "" + -n / 100; }, inverse: function (s) { return -s * 100; }, regexp: NUMBER + "\\.?\\d{0,2}", negates: false }, old_leech_percent: { format: function (n) { return "" + n / 5; }, inverse: function (s) { return +s * 5; }, regexp: NUMBER + "\\.?\\d{0,2}", negates: false }, old_leech_permyriad: { format: function (n) { return "" + n / 50; }, inverse: function (s) { return +s * 50; }, regexp: 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: NUMBER, negates: false }, per_minute_to_per_second_2dp: { format: function (n) { return (n / 60).toFixed(2); }, inverse: function (s) { return +s * 60; }, regexp: 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: 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: NUMBER, negates: false }, milliseconds_to_seconds_2dp: { format: function (n) { return (n / 1000).toFixed(2); }, inverse: function (s) { return +s * 1000; }, regexp: NUMBER + "\\.?\\d{2}", negates: false }, multiplicative_damage_modifier: { format: function (n) { return "" + n; }, inverse: function (s) { return +s; }, regexp: NUMBER, negates: false }, '60%_of_value': { format: function (n) { return "" + n * 0.6; }, inverse: function (s) { return +s / 0.6; }, regexp: NUMBER + "\\.?\\d*", negates: false }, id: { format: function (n) { return "" + n; }, inverse: function (s) { return +s; }, regexp: NUMBER, negates: false }, mod_value_to_item_class: mod_value_to_item_class, // TODO what is this canonical_stat: { format: function (n) { return "" + n; }, inverse: function (s) { return +s; }, regexp: NUMBER, negates: false }, placeholder: { format: function () { return '#'; }, inverse: function () { return Number.NaN; }, regexp: '#', negates: false } }; export function inverseFactory(formatter_id) { var inverse = buildFormatter(formatter_id).inverse; // TODO add ranges return inverse; } export function regexpFactory(formatter_id) { var regexp = buildFormatter(formatter_id).regexp; // TODO add ranges return regexp; } export function buildFormatter(formatter_id) { if (!formatters.hasOwnProperty(formatter_id)) { throw new Error("'" + formatter_id + "' not found"); } return formatters[formatter_id]; } export default function factory(formatter_id) { var format = buildFormatter(formatter_id).format; return format; }