UNPKG

1.5 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7function ifElse(condition, then, otherwise) {
8 return condition ? then : otherwise;
9}
10
11exports.ifElse = ifElse;
12
13function flatten(array) {
14 return array.reduce((all, item) => {
15 if (!item) {
16 return all;
17 }
18
19 return Array.isArray(item) ? [...all, ...flatten(item)] : [...all, item];
20 }, []);
21}
22
23exports.flatten = flatten;
24
25function removeEmptyValues(obj) {
26 return Object.keys(obj).reduce((all, key) => {
27 const value = obj[key];
28
29 if (value == null || Array.isArray(value) && value.length === 0) {
30 return all;
31 }
32
33 return Object.assign({}, all, {
34 [key]: value
35 });
36 }, {});
37}
38
39exports.removeEmptyValues = removeEmptyValues;
40
41function removeEmptyStringValues(obj) {
42 return Object.keys(obj).reduce((all, key) => {
43 const value = obj[key];
44
45 if (value == null || Array.isArray(value) && value.length === 0) {
46 return all;
47 }
48
49 return Object.assign({}, all, {
50 [key]: value
51 });
52 }, {});
53}
54
55exports.removeEmptyStringValues = removeEmptyStringValues;
56
57function msToMinutesAndSeconds(ms) {
58 let minutes = Math.floor(ms / 1000 / 60);
59 let seconds = Math.round(ms / 1000 % 60);
60
61 if (seconds === 60) {
62 minutes += 1;
63 seconds = 0;
64 }
65
66 if (minutes === 0) {
67 return `${seconds}s`;
68 }
69
70 if (seconds < 10) {
71 return `${minutes}m0${seconds}s`;
72 }
73
74 return `${minutes}m${seconds}s`;
75}
76
77exports.msToMinutesAndSeconds = msToMinutesAndSeconds;
\No newline at end of file