UNPKG

1.21 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", { value: true });
4function ifElse(condition, then, otherwise) {
5 return condition ? then : otherwise;
6}
7exports.ifElse = ifElse;
8function flatten(array) {
9 return array.reduce((all, item) => {
10 if (!item) {
11 return all;
12 }
13 return Array.isArray(item) ? [...all, ...flatten(item)] : [...all, item];
14 }, []);
15}
16exports.flatten = flatten;
17function removeEmptyValues(obj) {
18 return Object.keys(obj).reduce((all, key) => {
19 const value = obj[key];
20 if (value == null || Array.isArray(value) && value.length === 0) {
21 return all;
22 }
23 return Object.assign({}, all, { [key]: value });
24 }, {});
25}
26exports.removeEmptyValues = removeEmptyValues;
27function msToMinutesAndSeconds(ms) {
28 let minutes = Math.floor(ms / 1000 / 60);
29 let seconds = Math.round(ms / 1000 % 60);
30 if (seconds === 60) {
31 minutes += 1;
32 seconds = 0;
33 }
34 if (minutes === 0) {
35 return `${seconds}s`;
36 }
37 if (seconds < 10) {
38 return `${minutes}m0${seconds}s`;
39 }
40 return `${minutes}m${seconds}s`;
41}
42exports.msToMinutesAndSeconds = msToMinutesAndSeconds;
\No newline at end of file