@zauru-sdk/common 1.0.117 → 1.0.119

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,603 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.calculateTimeDifference = exports.parsedObject = exports.createPostgresUrl = exports.handlePossibleAxiosErrors = exports.sortByProperty = exports.capitalLetter = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.reduceAdd = exports.ZAURU_REGEX = exports.convertToFormData = exports.arrayToObject = exports.getParsedIdFromString = exports.incrementString = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.formatDateToUTC = exports.extractIdFromForm = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.getDatePickerCurrentDate = exports.isToday = exports.todayLongString = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.truncateText = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.isJsonArray = exports.extractValueBetweenTags = exports.generateClientUUID = exports.getBasketsSchema = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
7
- const moment_1 = __importDefault(require("moment"));
8
- require("moment-timezone");
9
- const types_1 = require("@zauru-sdk/types");
10
- exports.DESTINOS_MUESTRA_OPTIONS = [
11
- { label: "Microbiología", value: "microbiologa" },
12
- { label: "Residuos de plaguicidas", value: "residuos_de_plaguicidas" },
13
- ];
14
- moment_1.default.locale("es");
15
- /**
16
- * Obtener el objeto de canastas en base al string de canastas
17
- * @param basketsString
18
- * @returns
19
- */
20
- const getBasketsSchema = (basketsString) => {
21
- //Sacar conteo de canastas y su descripción de colores
22
- //ejemplo: vienen en un campo así: 8-53311-VERDE,3-53315-ROSADA,4-53313-ROJA
23
- const splitedText = basketsString.split(",");
24
- const baskets = splitedText.map((splited) => {
25
- const values = splited.split("-");
26
- return {
27
- total: Number(values[0]) ?? 0,
28
- id: Number(values[1]) ?? 0,
29
- color: values[2] ?? "Sin Canasta",
30
- };
31
- });
32
- return baskets;
33
- };
34
- exports.getBasketsSchema = getBasketsSchema;
35
- function generateClientUUID() {
36
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
37
- const r = (Math.random() * 16) | 0, v = c == "x" ? r : (r & 0x3) | 0x8;
38
- return v.toString(16);
39
- });
40
- }
41
- exports.generateClientUUID = generateClientUUID;
42
- /**
43
- * extractValueBetweenTags
44
- * @param input
45
- * @param tagName
46
- * @returns
47
- */
48
- function extractValueBetweenTags(input, tagName) {
49
- const regex = new RegExp(`<${tagName}[^>]*>(.*?)<\\/${tagName}>`, "i");
50
- const match = input.match(regex);
51
- return match ? match[1] : "";
52
- }
53
- exports.extractValueBetweenTags = extractValueBetweenTags;
54
- /**
55
- * isJsonArray
56
- * @param value
57
- * @returns
58
- */
59
- function isJsonArray(value) {
60
- try {
61
- const parsed = JSON.parse(value);
62
- return Array.isArray(parsed);
63
- }
64
- catch (e) {
65
- return false;
66
- }
67
- }
68
- exports.isJsonArray = isJsonArray;
69
- /**
70
- *
71
- * @param date Recibe el date en formato UTC
72
- */
73
- const getFechaJuliana = (date) => {
74
- function getDaysInMonth(month) {
75
- return new Date(new Date().getFullYear(), month, 0).getDate();
76
- }
77
- const getNumberOfDays = (month, day) => {
78
- let numberOfDays = day;
79
- while (month > 0) {
80
- const temp = getDaysInMonth(month);
81
- numberOfDays += temp;
82
- month--;
83
- }
84
- return numberOfDays;
85
- };
86
- const dt = (0, moment_1.default)(date).toDate();
87
- const month = dt.getMonth();
88
- const day = getNumberOfDays(month, dt.getDate());
89
- return `${dt.getFullYear()}-${day}`;
90
- };
91
- exports.getFechaJuliana = getFechaJuliana;
92
- /**
93
- * Convierte una fecha de tipo 25 de jul de 2022 a Date
94
- * @param date
95
- * @returns
96
- */
97
- const getNewDateByFormat = (date) => {
98
- if (!date) {
99
- return new Date();
100
- }
101
- const date_parts = date.split(" ");
102
- const new_date = new Date(parseInt(date_parts[4]), types_1.MONTHS[date_parts[2]], parseInt(date_parts[0]));
103
- return new_date;
104
- };
105
- exports.getNewDateByFormat = getNewDateByFormat;
106
- /**
107
- * Convierte una fecha de tipo 25 de jul de 2022 a YYYY-MM-DD
108
- * @param date
109
- * @returns
110
- */
111
- const getZauruDateByText = (date) => {
112
- const newDate = (0, exports.getNewDateByFormat)(date);
113
- return (0, exports.getStringDate)(newDate);
114
- };
115
- exports.getZauruDateByText = getZauruDateByText;
116
- /**
117
- * Convierte una fecha de tipo Date a YYYY-MM-DD
118
- * @param date
119
- * @returns
120
- */
121
- const getStringDate = (date) => {
122
- const year = date.getFullYear();
123
- const month = date.getMonth() + 1;
124
- const day = date.getDay();
125
- return `${year}-${month <= 9 ? `0${month}` : month}-${day <= 9 ? `0${day}` : day}`;
126
- };
127
- exports.getStringDate = getStringDate;
128
- function truncateText(text, maxLength) {
129
- if (!text || !maxLength) {
130
- return "";
131
- }
132
- // Verificar si el texto es más largo que maxLength
133
- if (text.length > maxLength) {
134
- // Si es así, truncar el texto y agregar "..."
135
- return text.substring(0, maxLength - 3) + "...";
136
- }
137
- else {
138
- // Si no, devolver el texto completo
139
- return text;
140
- }
141
- }
142
- exports.truncateText = truncateText;
143
- const getTodayDaysDifference = (date) => {
144
- // Crear el objeto de Moment para la fecha de creación
145
- const fechaCreacion = (0, moment_1.default)(date);
146
- // Crear el objeto de Moment para la fecha actual
147
- const ahora = (0, moment_1.default)();
148
- // Calcular la diferencia en días
149
- const diferencia = ahora.diff(fechaCreacion, "days");
150
- return diferencia;
151
- };
152
- exports.getTodayDaysDifference = getTodayDaysDifference;
153
- const getTodayMinutesDifference = (date) => {
154
- // Crear el objeto de Moment para la fecha de creación
155
- const fechaCreacion = (0, moment_1.default)(date);
156
- // Crear el objeto de Moment para la fecha actual
157
- const ahora = (0, moment_1.default)();
158
- // Calcular la diferencia en minutos
159
- const diferencia = ahora.diff(fechaCreacion, "minutes");
160
- return diferencia;
161
- };
162
- exports.getTodayMinutesDifference = getTodayMinutesDifference;
163
- /**
164
- * Convierte una fecha de tipo Date a DD-MM-YYY HH:mm:ss
165
- * @param date
166
- * @returns
167
- */
168
- const getStringFullDate = (date) => {
169
- const hour = date.getHours();
170
- const minutes = date.getMinutes();
171
- const seconds = date.getSeconds();
172
- const year = date.getFullYear();
173
- const month = date.getMonth() + 1;
174
- const day = date.getDay();
175
- return `${day <= 9 ? `0${day}` : day}-${month <= 9 ? `0${month}` : month}-${year} ${hour}:${minutes}:${seconds}`;
176
- };
177
- exports.getStringFullDate = getStringFullDate;
178
- /**
179
- * Convierte una fecha de tipo DD/MM/YYYY a YYYY/MM/DD
180
- * @param dateStr
181
- * @returns
182
- */
183
- const localDateToUSDate = (dateStr) => {
184
- const date = (0, moment_1.default)(dateStr, "DD/MM/YYYY");
185
- const newDateStr = date.format("YYYY/MM/DD");
186
- return newDateStr;
187
- };
188
- exports.localDateToUSDate = localDateToUSDate;
189
- const stringDateToParsedUTCDate = (date) => {
190
- const issueDate = new Date(date);
191
- issueDate.setMinutes(issueDate.getMinutes() - 360);
192
- return issueDate;
193
- };
194
- exports.stringDateToParsedUTCDate = stringDateToParsedUTCDate;
195
- /**
196
- * todayLongString
197
- * @param date
198
- * @returns
199
- */
200
- function todayLongString(hours = false) {
201
- // Analiza la fecha y hora sin ajustes de zona horaria
202
- const issueDate = (0, moment_1.default)(new Date().toISOString());
203
- let formatString = "dddd, D [de] MMMM [de] YYYY";
204
- if (hours) {
205
- formatString += ", HH:mm a"; // Añade la hora en formato de 12 horas con AM/PM
206
- }
207
- // Formatea la fecha en el locale español
208
- return issueDate.locale("es").format(formatString);
209
- }
210
- exports.todayLongString = todayLongString;
211
- function isToday(dateStr) {
212
- // Parsea la fecha dada y la fecha actual a inicio del día (00:00:00)
213
- const givenDate = (0, moment_1.default)(dateStr).startOf("day");
214
- const today = (0, moment_1.default)().startOf("day");
215
- // Compara si son iguales
216
- return givenDate.isSame(today);
217
- }
218
- exports.isToday = isToday;
219
- const getDatePickerCurrentDate = () => {
220
- const date = new Date();
221
- const year = date.getFullYear();
222
- const month = String(date.getMonth() + 1).padStart(2, "0"); // Los meses van de 0 a 11, por eso sumamos 1.
223
- const day = String(date.getDate()).padStart(2, "0");
224
- return `${year}-${month}-${day}`;
225
- };
226
- exports.getDatePickerCurrentDate = getDatePickerCurrentDate;
227
- const getTimePickerCurrentTime = () => {
228
- const date = new Date();
229
- const hours = String(date.getHours()).padStart(2, "0");
230
- const minutes = String(date.getMinutes()).padStart(2, "0");
231
- return `${hours}:${minutes}`;
232
- };
233
- exports.getTimePickerCurrentTime = getTimePickerCurrentTime;
234
- const getDateAfterDays = (daysAfterToday) => {
235
- const date = new Date();
236
- date.setDate(date.getDate() + daysAfterToday); // Agregamos el número de días a la fecha actual.
237
- const year = date.getFullYear();
238
- const month = String(date.getMonth() + 1).padStart(2, "0");
239
- const day = String(date.getDate()).padStart(2, "0");
240
- return `${year}-${month}-${day}`;
241
- };
242
- exports.getDateAfterDays = getDateAfterDays;
243
- const getPayeeFormated = (payee) => {
244
- if (!payee)
245
- return "-";
246
- return `${payee.id_number ? `<${payee.id_number}> ` : ""}${payee.tin ? `${payee.tin} | ` : ""}${payee.name}`.trim();
247
- };
248
- exports.getPayeeFormated = getPayeeFormated;
249
- const getPayeeInfoIdOptions = (payees) => {
250
- return payees.map((x) => {
251
- return {
252
- label: `${x.id_number ? `<${x.id_number}> ` : ""}${x.tin ? `${x.tin} | ` : ""}${x.name}`.trim(),
253
- value: x.id,
254
- id: x.id,
255
- };
256
- });
257
- };
258
- exports.getPayeeInfoIdOptions = getPayeeInfoIdOptions;
259
- const getPayeeInfoOptions = (payees) => {
260
- return payees.map((x) => {
261
- return {
262
- label: `${x.id_number ? `<${x.id_number}> ` : ""}${x.tin ? `${x.tin} | ` : ""}${x.name}`.trim(),
263
- value: `${x.id_number ? `<${x.id_number}> ` : ""}${x.tin ? `${x.tin} | ` : ""}${x.name}`.trim(),
264
- id: x.id,
265
- };
266
- });
267
- };
268
- exports.getPayeeInfoOptions = getPayeeInfoOptions;
269
- const parsedBaculoFormValue = (value, config = {
270
- falseValue: "No",
271
- trueValue: "Si",
272
- }) => {
273
- if (value === "false") {
274
- return config.falseValue;
275
- }
276
- else if (value === "true") {
277
- return config.trueValue;
278
- }
279
- else if (exports.DESTINOS_MUESTRA_OPTIONS.some((x) => x.value === value)) {
280
- return exports.DESTINOS_MUESTRA_OPTIONS.find((x) => x.value === value)?.label;
281
- }
282
- else if ((0, moment_1.default)(value, "YYYY-MM-DD", true).isValid()) {
283
- // Valida y convierte la fecha
284
- return (0, moment_1.default)(value).format("DD/MM/YYYY");
285
- }
286
- return capitalLetter(value);
287
- };
288
- exports.parsedBaculoFormValue = parsedBaculoFormValue;
289
- function extractIdFromForm(s) {
290
- const match = s.match(/LAB_FORM_(\d+);/);
291
- if (match && match[1]) {
292
- return parseInt(match[1], 10);
293
- }
294
- return null;
295
- }
296
- exports.extractIdFromForm = extractIdFromForm;
297
- /**
298
- * Formatea una fecha de tipo YYYY-MM-DD a 2023-08-07T20:56:00.540245
299
- * @param dateString
300
- * @returns
301
- */
302
- function formatDateToUTC(dateString) {
303
- const date = new Date(dateString);
304
- const year = date.getUTCFullYear();
305
- const month = String(date.getUTCMonth() + 1).padStart(2, "0");
306
- const day = String(date.getUTCDate()).padStart(2, "0");
307
- const hours = String(date.getUTCHours()).padStart(2, "0");
308
- const minutes = String(date.getUTCMinutes()).padStart(2, "0");
309
- const seconds = String(date.getUTCSeconds()).padStart(2, "0");
310
- const milliseconds = String(date.getUTCMilliseconds()).padStart(3, "0");
311
- return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`;
312
- }
313
- exports.formatDateToUTC = formatDateToUTC;
314
- /**
315
- * IMPORTANTE: Esta función está diseñada para funcionar solo en el lado del cliente.
316
- * Para renderizado del lado del servidor, utilice una función alternativa.
317
- *
318
- * Función para obtener la fecha formateada en español
319
- * @param dateString - Cadena de fecha opcional
320
- * @param withHours - Indica si se debe incluir la hora en el formato
321
- * @returns Fecha formateada en español
322
- */
323
- const getFormattedDate = (dateString, withHours = true) => {
324
- let date;
325
- if (dateString) {
326
- // Detectar el formato de la fecha
327
- if (/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/.test(dateString)) {
328
- // Formato ISO (UTC)
329
- date = new Date(dateString);
330
- // Ajustar a la hora local
331
- date = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
332
- }
333
- else if (/^\d{4}-\d{2}-\d{2}$/.test(dateString)) {
334
- // Formato YYYY-MM-DD
335
- date = new Date(`${dateString}T00:00:00`); // Hora local
336
- }
337
- else if (/^\d{2}-\d{2}-\d{4}$/.test(dateString)) {
338
- // Formato DD-MM-YYYY
339
- const [day, month, year] = dateString.split("-");
340
- date = new Date(`${year}-${month}-${day}T00:00:00`); // Hora local
341
- }
342
- else if (/^\d{2}\/\d{2}\/\d{4}$/.test(dateString)) {
343
- // Formato DD/MM/YYYY
344
- const [day, month, year] = dateString.split("/");
345
- date = new Date(`${year}-${month}-${day}T00:00:00`); // Hora local
346
- }
347
- else {
348
- throw new Error("Formato de fecha no reconocido");
349
- }
350
- }
351
- else {
352
- date = new Date(); // Fecha actual en hora local
353
- }
354
- const options = {
355
- weekday: "long",
356
- day: "numeric",
357
- month: "long",
358
- year: "numeric",
359
- timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone, // Obtiene la zona horaria del usuario
360
- };
361
- if (withHours) {
362
- options.hour = "numeric";
363
- options.minute = "numeric";
364
- options.second = "numeric";
365
- options.hour12 = false;
366
- }
367
- return new Intl.DateTimeFormat("es-ES", options).format(date);
368
- };
369
- exports.getFormattedDate = getFormattedDate;
370
- const formatDateToDatePicker = (date) => {
371
- const year = date.getFullYear();
372
- const month = `0${date.getMonth() + 1}`.slice(-2); // Los meses van de 0 a 11, así que le sumamos 1
373
- const day = `0${date.getDate()}`.slice(-2);
374
- return `${year}-${month}-${day}`;
375
- };
376
- exports.formatDateToDatePicker = formatDateToDatePicker;
377
- const formatTimeToTimePicker = (timeString) => {
378
- const [hours, minutes] = timeString.split(":").map(Number);
379
- const date = new Date();
380
- date.setHours(hours, minutes, 0, 0); // Establecemos las horas y minutos, y reseteamos segundos y milisegundos
381
- return date;
382
- };
383
- exports.formatTimeToTimePicker = formatTimeToTimePicker;
384
- const toFixedIfNeeded = (value) => {
385
- if (!value) {
386
- return value;
387
- }
388
- if (Number.isInteger(value)) {
389
- return value.toString().replace(".00", "");
390
- }
391
- const decimals = (value.toString().split(".")[1] || []).length;
392
- const decimal = decimals > 2 ? value.toFixed(2) : value.toString();
393
- return decimal.replace(".00", "");
394
- };
395
- exports.toFixedIfNeeded = toFixedIfNeeded;
396
- const isNumeric = (value) => {
397
- return !isNaN(value) && !isNaN(parseFloat(value));
398
- };
399
- exports.isNumeric = isNumeric;
400
- function incrementString(str) {
401
- // Encuentra la parte numérica de la cadena usando una expresión regular
402
- const match = str.match(/(\D*)(\d+)$/);
403
- if (!match) {
404
- throw new Error("Formato de cadena no válido");
405
- }
406
- const prefix = match[1];
407
- const numberPart = match[2];
408
- // Incrementa el número
409
- const incrementedNumber = parseInt(numberPart, 10) + 1;
410
- // Convierte el número incrementado de nuevo en una cadena y rellena con ceros
411
- const incrementedString = incrementedNumber
412
- .toString()
413
- .padStart(numberPart.length, "0");
414
- return prefix + incrementedString;
415
- }
416
- exports.incrementString = incrementString;
417
- function getParsedIdFromString(inputString) {
418
- const regex = /<(\d+)>/; // Expresión regular para encontrar el número entre los corchetes
419
- const match = inputString.match(regex); // Buscar la coincidencia en el string
420
- let number = 0;
421
- if (match && match[1]) {
422
- number = parseInt(match[1]); // Convertir el número de string a entero
423
- //console.log(number); // Mostrar el número en la consola
424
- }
425
- else {
426
- console.log("No se encontró ningún número entre corchetes.");
427
- }
428
- return number;
429
- }
430
- exports.getParsedIdFromString = getParsedIdFromString;
431
- const arrayToObject = (arr = [], options) => {
432
- return arr.reduce((acc, cur, idx) => {
433
- const tempVal = cur;
434
- if (options?.withOutId) {
435
- delete tempVal.id;
436
- }
437
- acc[idx.toString()] = tempVal;
438
- return acc;
439
- }, {});
440
- };
441
- exports.arrayToObject = arrayToObject;
442
- function convertToFormData(obj) {
443
- const formData = new FormData();
444
- function appendFormData(data, root = "") {
445
- if (data && typeof data === "object" && !(data instanceof File)) {
446
- for (const key in data) {
447
- if (data.hasOwnProperty(key)) {
448
- if (root === "") {
449
- // Append nested objects
450
- if (data[key] != undefined && data[key] != null)
451
- appendFormData(data[key], key);
452
- }
453
- else {
454
- // Append data with namespaced keys for nested objects
455
- if (data[key] != undefined && data[key] != null)
456
- appendFormData(data[key], `${root}[${key}]`);
457
- }
458
- }
459
- }
460
- }
461
- else {
462
- if (data instanceof File) {
463
- formData.append(root, data, data.name);
464
- }
465
- else {
466
- formData.append(root, data);
467
- }
468
- }
469
- }
470
- appendFormData(obj);
471
- return formData;
472
- }
473
- exports.convertToFormData = convertToFormData;
474
- exports.ZAURU_REGEX = {
475
- porcentaje: /^\d{1,2}(\.\d{1,2})?$/,
476
- };
477
- /**
478
- * Para hacer sumas en los reduce de arreglos enteros
479
- * @param accumulator
480
- * @param a
481
- * @returns
482
- */
483
- function reduceAdd(accumulator, a) {
484
- return accumulator + a;
485
- }
486
- exports.reduceAdd = reduceAdd;
487
- /**
488
- * Truncar decimales, ejemplo: truncateDecimals(43.434340934, 2) => 43.43
489
- * @param number
490
- * @param digits
491
- * @returns
492
- */
493
- const truncateDecimals = function (number, digits) {
494
- const multiplier = Math.pow(10, digits), adjustedNum = number * multiplier, truncatedNum = Math[adjustedNum < 0 ? "ceil" : "floor"](adjustedNum);
495
- return truncatedNum / multiplier;
496
- };
497
- exports.truncateDecimals = truncateDecimals;
498
- /**
499
- * PREFIX - QUEMADOS POR INDICACIONES DE SARTIP
500
- */
501
- //TODO: Falta agregar los demás currencies
502
- exports.CURRENCY_PREFIX = [
503
- { id: 1, code: "GTQ", prefix: "Q" },
504
- { id: 2, code: "USD", prefix: "$" },
505
- { id: 3, code: "LHN", prefix: "L" },
506
- { id: 12, code: "MXN", prefix: "$" },
507
- ];
508
- const getRandomNum = () => {
509
- const randomNum = Math.random() * 10 + 1;
510
- return parseFloat(randomNum.toFixed(2));
511
- };
512
- exports.getRandomNum = getRandomNum;
513
- //COMMONS DE LABORATORIO
514
- exports.labServicePattern = /LAB_SERVICE_\d+;/g;
515
- exports.labFormPatter = /LAB_FORM_\d+;/;
516
- function capitalLetter(str = "") {
517
- if (str.length > 0) {
518
- return str.charAt(0).toUpperCase() + str.slice(1);
519
- }
520
- return str;
521
- }
522
- exports.capitalLetter = capitalLetter;
523
- const sortByProperty = (array, property) => {
524
- // Crear una copia del array
525
- const arrayCopy = [...array];
526
- return arrayCopy.sort((a, b) => {
527
- if (a[property] > b[property]) {
528
- return 1;
529
- }
530
- if (a[property] < b[property]) {
531
- return -1;
532
- }
533
- return 0;
534
- });
535
- };
536
- exports.sortByProperty = sortByProperty;
537
- /**
538
- * Handle web app table actions and return a response with a consistent format.
539
- * @param action A function that returns a Promise of type T.
540
- * @returns A Promise of AxiosUtilsResponse<T>.
541
- */
542
- async function handlePossibleAxiosErrors(action) {
543
- try {
544
- const result = await action();
545
- return { error: false, data: result };
546
- }
547
- catch (error) {
548
- return { error: true, userMsg: error?.toString() };
549
- }
550
- }
551
- exports.handlePossibleAxiosErrors = handlePossibleAxiosErrors;
552
- /**
553
- * createPostgresUrl
554
- * @param host
555
- * @param port
556
- * @param dbName
557
- * @param user
558
- * @param password
559
- * @param schema
560
- * @returns
561
- */
562
- function createPostgresUrl(host = "localhost", port = "5432", dbName = "postgres", user = "postgres", password = "", schema = "public") {
563
- let authPart = user;
564
- if (password) {
565
- authPart += `:${password}`;
566
- }
567
- return `postgresql://${authPart}@${host}:${port}/${dbName}?schema=${schema}`;
568
- }
569
- exports.createPostgresUrl = createPostgresUrl;
570
- const parsedObject = (obj) => {
571
- if (typeof obj === "bigint") {
572
- return obj.toString();
573
- }
574
- else if (obj instanceof Date) {
575
- return obj.toISOString();
576
- }
577
- else if (Array.isArray(obj)) {
578
- return obj.map(exports.parsedObject);
579
- }
580
- else if (obj !== null && typeof obj === "object") {
581
- return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, (0, exports.parsedObject)(value)]));
582
- }
583
- else {
584
- return obj;
585
- }
586
- };
587
- exports.parsedObject = parsedObject;
588
- function calculateTimeDifference(timestamp) {
589
- const currentTime = (0, moment_1.default)();
590
- const inputTime = (0, moment_1.default)(timestamp, "YYYY-MM-DD HH:mm:ss");
591
- if (!inputTime.isValid()) {
592
- return { hours: 0, minutes: 0, label: `---` };
593
- }
594
- const duration = moment_1.default.duration(currentTime.diff(inputTime));
595
- const hours = Math.floor(duration.asHours());
596
- const minutes = Math.floor(duration.asMinutes()) % 60;
597
- return {
598
- hours: hours,
599
- minutes: minutes,
600
- label: `${hours > 0 ? `${hours} ${hours > 1 ? "horas" : "hora"}` : ""}${hours > 0 && minutes > 0 ? " y " : ""}${minutes > 0 ? `${minutes} ${minutes > 1 ? "minutos" : "minuto"}` : ""}.`,
601
- };
602
- }
603
- exports.calculateTimeDifference = calculateTimeDifference;