/** Simple helpers for numeric formatting. */
export default class Numbers
{
    private constructor() {}

    static format(value: number, exponent?: number): string;
    static format<T>(value: T, exponent?: number): T;

    /**
     * Format a numeric value while preserving unknown inputs.
     * @param value
     * @param exponent
     */
    static format(value: unknown, exponent = 2): unknown
    {
        if (typeof value !== 'number' || Number.isNaN(value))
        {
            return value;
        }
        if (value === 0)
        {
            return '0';
        }

        return value.toFixed(exponent);
    }

    /**
     * Returns infinity glyph instead of negative numbers for display purposes.
     * @param value
     */
    static getInfinityInsteadOfNegative<T extends number | string>(value: T): T | '∞'
    {
        if (typeof value === 'number' && value < 0)
        {
            return '∞';
        }

        return value;
    }
}
