-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.gs
More file actions
79 lines (74 loc) · 2.19 KB
/
Copy pathUtils.gs
File metadata and controls
79 lines (74 loc) · 2.19 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* @file Utils.gs
* @description Módulo responsável por funções utilitárias do sistema.
*
* Funcionalidade esperada:
* - Prover funções auxiliares reutilizáveis
* - Formatação de datas e strings
* - Validações genéricas
*/
const Utils = {
/**
* Inicializa o módulo Utils.
* @returns {boolean} Retorna true se a inicialização for bem-sucedida.
*/
init: function() {
try {
if (typeof Logger_System !== 'undefined') {
Logger_System.info('Utils.gs inicializado com sucesso.', 'Utils');
}
return true;
} catch (error) {
if (typeof Logger_System !== 'undefined') {
Logger_System.logError(error, 'Utils.init');
}
return false;
}
},
/**
* Formata uma data para o padrão ISO (YYYY-MM-DDTHH:mm:ss.sssZ).
* @param {Date|string|number} date - Objeto Data ou valor convertível.
* @returns {string|null} Data formatada ou null se inválida.
*/
formatDate: function(date) {
if (!date) return null;
const d = new Date(date);
return isNaN(d.getTime()) ? null : d.toISOString();
},
/**
* Formata data para exibição local (PT-BR).
* @param {Date|string} date
* @returns {string}
*/
formatDisplayDate: function(date) {
if (!date) return '-';
const d = new Date(date);
if (isNaN(d.getTime())) return '-';
return d.toLocaleDateString('pt-BR') + ' ' + d.toLocaleTimeString('pt-BR', { hour: '2-digit', minute: '2-digit' });
},
/**
* Valida se um objeto está vazio.
*/
isEmpty: function(obj) {
if (obj === null || obj === undefined) return true;
if (typeof obj === 'string') return obj.trim().length === 0;
if (Array.isArray(obj)) return obj.length === 0;
if (typeof obj === 'object') return Object.keys(obj).length === 0;
return false;
},
/**
* Sanitiza uma string para evitar XSS básico.
*/
sanitize: function(str) {
if (typeof str !== 'string') return str;
return str.replace(/[&<>"']/g, function(m) {
return {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
}[m];
});
}
};