ng-bundle-analyzer
Version:
Generate and display treemaps of Angular bundle.
38 lines (30 loc) • 721 B
JavaScript
const ONE_MB = 1000000;
const ONE_KB = 1000;
export function fromBytes(bytes) {
if (bytes >= ONE_MB) {
return `${Number((bytes / ONE_MB).toFixed(2))} MB`;
}
return `${Number((bytes / ONE_KB).toFixed(1))} KB`;
}
export function fromPath(path) {
if (path.includes('/')) {
return path.split('/').slice(-1)[0];
}
return path;
}
export function fromDate(date) {
return date.toLocaleString('de', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
});
}
export function fromMs(ms) {
if (ms < 1000) {
return `${ms} ms`;
}
return `${Number((ms / 1000).toFixed(2))} s`;
}