eight blocks

This commit is contained in:
Mononaut
2023-09-28 15:48:37 +01:00
parent 108d1762d6
commit ec8fc53dcb
9 changed files with 370 additions and 28 deletions

View File

@@ -17,7 +17,7 @@ export class BytesPipe implements PipeTransform {
'TB': {max: Number.MAX_SAFE_INTEGER, prev: 'GB'}
};
transform(input: any, decimal: number = 0, from: ByteUnit = 'B', to?: ByteUnit, sigfigs?: number): any {
transform(input: any, decimal: number = 0, from: ByteUnit = 'B', to?: ByteUnit, plaintext = false, sigfigs?: number): any {
if (!(isNumberFinite(input) &&
isNumberFinite(decimal) &&
@@ -42,7 +42,7 @@ export class BytesPipe implements PipeTransform {
const result = numberFormat(BytesPipe.calculateResult(format, bytes));
return BytesPipe.formatResult(result, to);
return BytesPipe.formatResult(result, to, plaintext);
}
for (const key in BytesPipe.formats) {
@@ -51,13 +51,17 @@ export class BytesPipe implements PipeTransform {
const result = numberFormat(BytesPipe.calculateResult(format, bytes));
return BytesPipe.formatResult(result, key);
return BytesPipe.formatResult(result, key, plaintext);
}
}
}
static formatResult(result: string, unit: string): string {
return `${result} <span class="symbol">${unit}</span>`;
static formatResult(result: string, unit: string, plaintext): string {
if (plaintext) {
return `${result} ${unit}`;
} else {
return `${result} <span class="symbol">${unit}</span>`;
}
}
static calculateResult(format: { max: number, prev?: ByteUnit }, bytes: number) {