@sixbell-telco/sdk
Version:
A collection of reusable components designed for use in Sixbell Telco Angular projects
37 lines (33 loc) • 1.48 kB
JavaScript
import * as i0 from '@angular/core';
import { Pipe } from '@angular/core';
class ToBytesPipe {
transform(bytes, decimals = 0) {
return this.formatBytes(bytes, decimals);
}
formatBytes(bytes, decimals = 0) {
if (bytes === 0)
return '0 Bytes';
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
// Format with the required number of decimals
const formattedNumber = (bytes / Math.pow(k, i)).toFixed(dm);
// Remove space between the number and the unit
return formattedNumber + sizes[i];
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ToBytesPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "19.2.0", ngImport: i0, type: ToBytesPipe, isStandalone: true, name: "toBytes" });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.0", ngImport: i0, type: ToBytesPipe, decorators: [{
type: Pipe,
args: [{
name: 'toBytes',
standalone: true,
}]
}] });
/**
* Generated bundle index. Do not edit.
*/
export { ToBytesPipe };
//# sourceMappingURL=sixbell-telco-sdk-utils-pipes-to-bytes-extesion.mjs.map