RED-6830: Refactor size format pipe
This commit is contained in:
parent
aa4516286e
commit
2d6ee6655c
@ -1,4 +1,5 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { size } from '../utils';
|
||||
|
||||
@Pipe({
|
||||
name: 'size',
|
||||
@ -6,9 +7,6 @@ import { Pipe, PipeTransform } from '@angular/core';
|
||||
})
|
||||
export class SizePipe implements PipeTransform {
|
||||
transform(value: number): string {
|
||||
if (value >= 1000 ** 3) {
|
||||
return `${(value / 1000 ** 3).toFixed(2)} GB`;
|
||||
}
|
||||
return `${(value / 1000 ** 2).toFixed(2)} MB`;
|
||||
return size(value);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,18 @@ export function humanizeCamelCase(value: string): string {
|
||||
return value.replace(/([a-z])([A-Z])/g, '$1 $2').toLowerCase();
|
||||
}
|
||||
|
||||
export function size(value: number): string {
|
||||
if (value >= 1000 ** 3) {
|
||||
return `${(value / 1000 ** 3).toFixed(2)} GB`;
|
||||
}
|
||||
|
||||
if (value >= 1000 ** 2) {
|
||||
return `${(value / 1000 ** 2).toFixed(2)} MB`;
|
||||
}
|
||||
|
||||
return `${(value / 1000).toFixed(2)} KB`;
|
||||
}
|
||||
|
||||
export function escapeHtml<T extends unknown | string>(unsafe: T, options?: { ignoreTags: string[] }) {
|
||||
if (typeof unsafe !== 'string') {
|
||||
return unsafe;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user