1 const {v4
: uuid
} = require('uuid');
4 static generateUUID() {
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(value
) {
78 let changedValue
= value
;
82 if (Number
.isSafeInteger(value
)) {
86 if (typeof value
=== 'string') {
88 changedValue
= parseInt(value
);
93 static convertToFloat(value
) {
94 let changedValue
= value
;
99 if (typeof value
=== 'string') {
101 changedValue
= parseFloat(value
);
106 static convertToBoolean(value
) {
111 if (typeof value
=== 'boolean') {
116 result
= (value
=== 'true');
122 static getRandomInt(max
, min
) {
124 return Math
.floor((Math
.random() * (max
- min
+ 1)) + min
);
126 return Math
.floor((Math
.random() * max
+ 1));
129 static logPrefix(prefixString
= '') {
130 const date
= new Date();
131 return date
.toLocaleString() + prefixString
;
134 static objectHasOwnProperty(object
, property
) {
135 return Object
.prototype.hasOwnProperty
.call(object
, property
);
138 static cloneJSonDocument(jsonDocument
) {
139 return JSON
.parse(JSON
.stringify(jsonDocument
));
142 static isUndefined(value
) {
143 return typeof value
=== 'undefined';
146 static isNullOrUndefined(value
) {
147 // eslint-disable-next-line eqeqeq
154 static isEmptyArray(object
) {
155 if (Array
.isArray(object
) && object
.length
> 0) {
162 module
.exports
= Utils
;