UNPKG

poe-i18n

Version:

i18n utility for Path of Exile

24 lines (20 loc) 643 B
import { formatValues } from '../localize/formatValues'; import { Formatter } from '../types/StatDescription'; export type Params = Array<number | [number, number]>; export default function printf( text: string, params: Params, formatters: Formatter[] = [], range_message = '({min}–{max})' ): string { const prepared = formatValues(params, { formatters, message: range_message }); return prepared .reduce( (formatted, param, i) => formatted .replace(new RegExp(`%${i + 1}%`, 'g'), String(param)) .replace(`%${i + 1}$+d`, `+${String(param)}`), text ) .replace(/%%/g, '%'); }