-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.tsx
More file actions
77 lines (68 loc) · 2.13 KB
/
utils.tsx
File metadata and controls
77 lines (68 loc) · 2.13 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
export const getDuration = (durationString = "") => {
const duration = { hours: 0, minutes: 0, seconds: 0 };
const durationParts = durationString
.replace("PT", "")
.replace("H", ":")
.replace("M", ":")
.replace("S", "")
.split(":");
if (durationParts.length === 3) {
duration["hours"] = durationParts[0];
duration["minutes"] = durationParts[1];
duration["seconds"] = durationParts[2];
}
if (durationParts.length === 2) {
duration["minutes"] = durationParts[0];
duration["seconds"] = durationParts[1];
}
if (durationParts.length === 1) {
duration["seconds"] = durationParts[0];
}
return {
...duration,
string: `${duration.hours.toString().padStart(2, "0")}:${duration.minutes
.toString()
.padStart(2, "0")}:${duration.seconds.toString().padStart(2, "0")}`,
};
};
export const abbreviateNumber = (value: Number) => {
var newValue = value;
if (value >= 1000) {
var suffixes = ["", "K", "M", "B", "T"];
var suffixNum = Math.floor(("" + value).length / 3);
var shortValue = null;
for (var precision = 2; precision >= 1; precision--) {
shortValue = parseFloat(
(suffixNum != 0
? value / Math.pow(1000, suffixNum)
: value
).toPrecision(precision)
);
var dotLessShortValue = (shortValue + "").replace(/[^a-zA-Z 0-9]+/g, "");
if (dotLessShortValue.length <= 2) {
break;
}
}
if (shortValue % 1 != 0) shortValue = shortValue.toFixed(1);
newValue = shortValue + suffixes[suffixNum];
}
return newValue;
};
export const calculateSol = (vid: any) => {
console.log(vid.duration);
return (
vid.duration.seconds * 0.0001 +
vid.duration.minutes * 0.001 +
vid.duration.hours * 0.01
);
};
export const timeToSecs = (time: string) => {
var a = time.split(":"); // split it at the colons
// minutes are worth 60 seconds. Hours are worth 60 minutes.
var seconds = +a[0] * 60 * 60 + +a[1] * 60 + +a[2];
return seconds;
};
export const round = (num: number, places: number) => {
var multiplier = Math.pow(10, places);
return Math.round(num * multiplier) / multiplier;
};