import * as i0 from '@angular/core';
import { Pipe, NgModule } from '@angular/core';

class NumberTransPipe {
    getFlowStr(value, fixedNum) {
        if (value / (1024 * 1024 * 1024 * 1024) > 10) {
            value = value / (1024 * 1024 * 1024 * 1024);
            return value.toFixed(fixedNum) + 'Tb';
        }
        else if (value / (1024 * 1024 * 1024) > 10) {
            value = value / (1024 * 1024 * 1024);
            return value.toFixed(fixedNum) + 'Gb';
        }
        else if (value / (1024 * 1024) > 10) {
            value = value / (1024 * 1024);
            return value.toFixed(fixedNum) + 'Mb';
        }
        else if (value / 1024 > 10) {
            value = value / 1024;
            return value.toFixed(fixedNum) + 'Kb';
        }
        else {
            return value + 'Byte';
        }
    }
    getUnitStr(value, fixedNum) {
        if (value / (1000 * 1000 * 1000 * 1000) > 1) {
            value = value / (1000 * 1000 * 1000 * 1000);
            return value.toFixed(fixedNum) + 'T';
        }
        else if (value / (1000 * 1000 * 1000) > 1) {
            value = value / (1000 * 1000 * 1000);
            return value.toFixed(fixedNum) + 'G';
        }
        else if (value / (1000 * 1000) > 1) {
            value = value / (1000 * 1000);
            return value.toFixed(fixedNum) + 'M';
        }
        else if (value / (1000) > 1) {
            value = value / (1000);
            return value.toFixed(fixedNum) + 'k';
        }
        else {
            return String(value);
        }
    }
    transform(value, type = 'comma', fixedNum = 2) {
        let number = Number(value);
        let numberStr = '';
        if (!number && number !== 0) {
            return numberStr;
        }
        if (Number(fixedNum) || fixedNum === 0) {
            number = Math.floor(number * Number(`1e${fixedNum}`)) / Number(`1e${fixedNum}`);
        }
        switch (type) {
            case 'comma':
                numberStr = number.toLocaleString();
                break;
            case 'flow':
                numberStr = this.getFlowStr(number, fixedNum);
                break;
            case 'unit':
                numberStr = this.getUnitStr(number, fixedNum);
                break;
            case 'exponent':
                numberStr = number.toExponential(fixedNum);
                break;
        }
        return numberStr;
    }
}
NumberTransPipe.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: NumberTransPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
NumberTransPipe.ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "14.2.0", ngImport: i0, type: NumberTransPipe, name: "dNumberTrans" });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: NumberTransPipe, decorators: [{
            type: Pipe,
            args: [{
                    name: 'dNumberTrans'
                }]
        }] });

class NumberTransModule {
}
NumberTransModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: NumberTransModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
NumberTransModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.0", ngImport: i0, type: NumberTransModule, declarations: [NumberTransPipe], exports: [NumberTransPipe] });
NumberTransModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: NumberTransModule });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.0", ngImport: i0, type: NumberTransModule, decorators: [{
            type: NgModule,
            args: [{
                    declarations: [
                        NumberTransPipe
                    ],
                    exports: [
                        NumberTransPipe
                    ]
                }]
        }] });

/**
 * Generated bundle index. Do not edit.
 */

export { NumberTransModule, NumberTransPipe };
//# sourceMappingURL=ng-devui-number-translation.mjs.map
