All files / picobel/src/js/utils helpers.ts

94.44% Statements 17/18
66.66% Branches 2/3
75% Functions 3/4
94.44% Lines 17/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4310x 6x   6x       6x         6x   6x 1x     6x       10x 4x 4x 4x       10x 4x 4x 4x     10x              
export const parseTime = (seconds: number): string => {
    const hours = Math.floor(seconds / 3600);
 
    const mins = Math.floor((seconds % 3600) / 60)
        .toFixed(0)
        .toString();
 
    const secs = Math.floor((seconds % 3600) % 60)
        .toFixed(0)
        .toString()
        .padStart(2, "0");
 
    let parsedTime = `${mins}:${secs}`;
 
    if (hours > 0) {
        parsedTime = `${hours}:${mins.padStart(2, "0")}:${secs}`;
    }
 
    return parsedTime;
};
 
// Get File Type
export const getFileType = (string: string): string => {
    const fullFileName = string.replace(/^.*[\\/]/, "");
    const extension = fullFileName.split(".")[1];
    return extension;
};
 
// Get File Name
export const getFileName = (string: string): string => {
    const fullFileName = string.replace(/^.*[\\/]/, "");
    const withNoExtension = fullFileName.split(".")[0];
    return withNoExtension;
};
 
export const convertToPercentage = (
    value: number,
    total: number,
    precision = 2
) => {
    return Number(((value / total) * 100).toFixed(precision));
};