-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelpers.js
49 lines (44 loc) · 1.69 KB
/
helpers.js
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
"use strict";
const moment = require('moment-timezone');
const filessystem = require('fs');
const ip = require('ip');
const timezone = "America/Bogota";
const striptags = require('striptags');
const sanitizer = require('sanitizer');
//Para crear Token's...
exports.guid = () => {
const s4 = () => Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
};
//Función para limpiar los valores que vengan por un objeto...
exports.clearDataObject = (objecto) => {
let newObject = {};
for(let i in objecto) {
newObject[i] = striptags(sanitizer.escape(objecto[i]));
}
return newObject;
};
//Para las fechas...
exports.dates = () => {
return {
current_date : moment(new Date()).tz(timezone).format("YYYY-MM-DD HH:mm:ss"),
date_string : moment().tz(timezone).format("DD/MM/YYYY"),
hour_string : moment().tz(timezone).format("hh:mm:ss a"),
unix : moment().tz(timezone).unix()
};
};
//Para crear un directorio de la prueba...
exports.crearDirectorio = (dir) => {
if (!filessystem.existsSync(dir)) {
filessystem.mkdirSync(dir);
}
};
//Saber si un valor es un número...
exports.isNumber = (n) => !isNaN(parseFloat(n)) && !isNaN(n - 0);
//Listado de comandos permitidos...
exports.commandsADB = (command) => ["tap", "text", "swipe", "keyevent"].includes(command);
//Listado de comandos válidos para el modo Monkey...
exports.commandsMonkey = (command) => ["keyevents","motion","navigation","touch","trackball"].includes(command);
//Para obtener la ip en donde se realiza la acción...
exports.getIP = () => ip.address();
module.exports.timezone = timezone;