Upload

Format upload progress, speed, and estimated time.

formatETA

Formats time remaining in seconds to a human-readable string with hours, minutes, and seconds.

import { formatETA } from "@tilt-legal/cubitt-components/utilities/formatters";

formatETA(30); // "30s"
formatETA(90); // "1m 30s"
formatETA(330); // "5m 30s"
formatETA(3660); // "1h 1m"
formatETA(7200); // "2h"
ParameterTypeDescription
secondsnumberTime remaining in seconds

formatSpeed

Formats upload/download speed in bytes per second to a human-readable string with appropriate unit.

import { formatSpeed } from "@tilt-legal/cubitt-components/utilities/formatters";

formatSpeed(1024); // "1 KB/s"
formatSpeed(1572864); // "1.50 MB/s"
formatSpeed(10485760); // "10 MB/s"
formatSpeed(0); // "0 B/s"
ParameterTypeDescription
bytesPerSecondnumberUpload/download speed in B/s

formatUploadProgress

Calculates and formats upload progress as both a percentage and a descriptive text string.

import { formatUploadProgress } from "@tilt-legal/cubitt-components/utilities/formatters";

formatUploadProgress(512000, 1024000);
// { percentage: 50, text: "50% (500 KB / 1 MB)" }

formatUploadProgress(1024000, 1024000);
// { percentage: 100, text: "100% (1 MB / 1 MB)" }

formatUploadProgress(0, 5242880);
// { percentage: 0, text: "0% (0 B / 5 MB)" }
ParameterTypeDescription
loadednumberBytes uploaded so far
totalnumberTotal bytes to upload

On this page