e85090d49626156d4e2fdb913781762448bdcc8a
1 const {v4
: uuid
} = require('uuid');
4 static generateGUID() {
9 return new Promise((resolve
) => setTimeout(resolve
, ms
));
12 static secondstoHHMMSS(seconds
) {
13 const date
= new Date(null);
14 date
.setSeconds(seconds
);
15 return date
.toISOString().substr(11, 8);
18 static convertToDate(date
) {
24 if (!(date
instanceof Date
)) {
25 return new Date(date
);
30 static isIterable(obj
) {
32 return typeof obj
[Symbol
.iterator
] === 'function';
37 static isEmptyJSon(document
) {
43 if (typeof document
!== 'object') {
47 return Object
.keys(document
).length
=== 0;
50 static removeExtraEmptyLines(tab
) {
52 for (let i
= tab
.length
- 1; i
> 0; i
--) {
53 // Two consecutive empty lines?
54 if (tab
[i
].length
=== 0 && tab
[i
- 1].length
=== 0) {
55 // Remove the last one
59 if (i
=== 1 && tab
[i
- 1].length
=== 0) {
60 // Remove the first one
66 static convertToObjectID(id
) {
69 if (typeof id
=== 'string') {
71 // eslint-disable-next-line no-undef
72 changedID
= new ObjectID(id
);
77 static convertToInt(id
) {
83 if (typeof id
=== 'string') {
85 changedID
= parseInt(id
);
90 static convertToFloat(id
) {
96 if (typeof id
=== 'string') {
98 changedID
= parseFloat(id
);
103 static convertToBoolean(value
) {
108 if (typeof value
=== 'boolean') {
113 result
= (value
=== 'true');
119 static getRandomInt(max
, min
) {
121 return Math
.floor((Math
.random() * (max
- min
)) + min
);
123 return Math
.floor((Math
.random() * max
));
126 static basicFormatLog(prefixString
= '') {
127 const date
= new Date();
128 return date
.toISOString().substr(0, 19) + prefixString
;
132 module
.exports
= Utils
;