export class NumberFormatter {
    constructor(locale) {
        this.locale = locale;
    }
    format(value, format) {
        var _a, _b;
        const formatter = new Intl.NumberFormat(this.locale, format.options);
        const parts = formatter.formatToParts(value);
        let prefix = '';
        let number = '';
        let suffix = '';
        for (const part of parts) {
            if ((_a = format.prefix) === null || _a === void 0 ? void 0 : _a.includes(part.type)) {
                prefix += part.value;
            }
            else if ((_b = format.suffix) === null || _b === void 0 ? void 0 : _b.includes(part.type)) {
                suffix += part.value;
            }
            else {
                number += part.value;
            }
        }
        if (!number) {
            number = formatter.format(value);
            prefix = '';
            suffix = '';
        }
        return {
            prefix: prefix,
            value: number,
            suffix: suffix,
        };
    }
}
