@jvsoft/utils 0.0.3 → 0.0.4

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.
Files changed (49) hide show
  1. package/fesm2022/jvsoft-utils-src-functions.mjs +1039 -0
  2. package/fesm2022/jvsoft-utils-src-functions.mjs.map +1 -0
  3. package/fesm2022/jvsoft-utils-src-interfaces.mjs +14 -0
  4. package/fesm2022/jvsoft-utils-src-interfaces.mjs.map +1 -0
  5. package/fesm2022/jvsoft-utils-src-pipes.mjs +266 -0
  6. package/fesm2022/jvsoft-utils-src-pipes.mjs.map +1 -0
  7. package/fesm2022/jvsoft-utils.mjs +15 -269
  8. package/fesm2022/jvsoft-utils.mjs.map +1 -1
  9. package/functions/file.d.ts +1 -1
  10. package/functions/index.d.ts +1 -16
  11. package/functions/mat-form-controls/index.d.ts +1 -0
  12. package/functions/public-api.d.ts +15 -0
  13. package/interfaces/index.d.ts +1 -2
  14. package/interfaces/public-api.d.ts +2 -0
  15. package/package.json +14 -2
  16. package/pipes/index.d.ts +1 -7
  17. package/pipes/public-api.d.ts +7 -0
  18. package/src/functions/base64.d.ts +2 -0
  19. package/src/functions/browser.d.ts +1 -0
  20. package/src/functions/crypto-js.d.ts +2 -0
  21. package/src/functions/date.d.ts +3 -0
  22. package/src/functions/file.d.ts +10 -0
  23. package/src/functions/forms.d.ts +10 -0
  24. package/src/functions/http-client.d.ts +2 -0
  25. package/src/functions/index.d.ts +5 -0
  26. package/src/functions/local-storage.d.ts +29 -0
  27. package/src/functions/mat-form-controls/autocomplete.d.ts +21 -0
  28. package/src/functions/mat-form-controls/index.d.ts +2 -0
  29. package/src/functions/number.d.ts +1 -0
  30. package/src/functions/object-transformation.d.ts +2 -0
  31. package/src/functions/objects-arrays.d.ts +26 -0
  32. package/src/functions/public-api.d.ts +15 -0
  33. package/src/functions/string.d.ts +1 -0
  34. package/src/functions/sweetalert.d.ts +5 -0
  35. package/src/functions/utiles.d.ts +1 -0
  36. package/src/interfaces/datos.d.ts +4 -0
  37. package/src/interfaces/index.d.ts +5 -0
  38. package/src/interfaces/otros.d.ts +2 -0
  39. package/src/interfaces/public-api.d.ts +2 -0
  40. package/src/pipes/data-en-lista.pipe.d.ts +8 -0
  41. package/src/pipes/date-diff-string.pipe.d.ts +17 -0
  42. package/src/pipes/filtro.pipe.d.ts +18 -0
  43. package/src/pipes/form-control-is-required.pipe.d.ts +9 -0
  44. package/src/pipes/index.d.ts +5 -0
  45. package/src/pipes/json-parse.pipe.d.ts +7 -0
  46. package/src/pipes/no-sanitize.pipe.d.ts +10 -0
  47. package/src/pipes/public-api.d.ts +7 -0
  48. package/src/pipes/zero-fill.pipe.d.ts +8 -0
  49. package/functions/formatear-pdfmake.d.ts +0 -39
@@ -4,7 +4,7 @@ import { startWith, debounceTime, tap, isObservable, switchMap, of, finalize } f
4
4
  import { map } from 'rxjs/operators';
5
5
  import { Buffer } from 'buffer';
6
6
  import CryptoJS from 'crypto-js';
7
- import { formatDate, formatNumber } from '@angular/common';
7
+ import { formatDate } from '@angular/common';
8
8
  import { saveAs } from 'file-saver';
9
9
  import { ReactiveFormConfig } from '@rxweb/reactive-form-validators';
10
10
  import swal from 'sweetalert2';
@@ -376,6 +376,10 @@ function changeSelectApi(control, queryService, formControl, tipo, dataExtra = {
376
376
  });
377
377
  }
378
378
 
379
+ function seleccionarTextoInput(event) {
380
+ event.target.select();
381
+ }
382
+
379
383
  function b64Encode(val) {
380
384
  return Buffer.from(val, 'binary').toString('base64');
381
385
  }
@@ -558,7 +562,7 @@ function convertirBytes(valor, unidadSalida = null, incluirUnidad = true) {
558
562
  }
559
563
  return resultado;
560
564
  }
561
- function downLoadFileStream(data, type, nombreArchivo = undefined) {
565
+ function downLoadFileStream(data, type, nombreArchivo) {
562
566
  const blob = new Blob([data], { type });
563
567
  saveAs(blob, nombreArchivo);
564
568
  }
@@ -1030,272 +1034,6 @@ function verificarRUC(ruc) {
1030
1034
  return false;
1031
1035
  }
1032
1036
 
1033
- // @ts-ignore
1034
- function tipoValorFuncion(datoParam, ...param) {
1035
- if (typeof datoParam === 'function') {
1036
- return datoParam(...param);
1037
- }
1038
- return datoParam;
1039
- }
1040
-
1041
- function imprimirCelda(data, tipo = null, opcAdicionales = {}) {
1042
- let texto = data;
1043
- // if (typeof data)
1044
- switch (tipo) {
1045
- case 'money':
1046
- case 'number':
1047
- case 'integer':
1048
- let formatoNumero = (tipo == 'money' ? '1.2-2' : (tipo == 'number' ? '1.0-2' : '1.0-0'));
1049
- texto = data * 1;
1050
- if (opcAdicionales?.format) {
1051
- formatoNumero = opcAdicionales.format;
1052
- }
1053
- texto = formatNumber(texto, 'es-PE', formatoNumero);
1054
- break;
1055
- case 'date':
1056
- case 'datetime':
1057
- case 'time':
1058
- let formatoFecha = (tipo == 'date' ? 'dd/MM/yyyy' : (tipo == 'time' ? 'HH:mm:ss' : 'dd/MM/yyyy HH:mm'));
1059
- if (!opcAdicionales?.alignment) {
1060
- opcAdicionales.alignment = 'center';
1061
- }
1062
- if (opcAdicionales?.format) {
1063
- formatoFecha = opcAdicionales.format;
1064
- }
1065
- texto = texto ? formatDate(data, formatoFecha, 'es-PE') : null;
1066
- break;
1067
- default:
1068
- break;
1069
- }
1070
- opcAdicionales['text'] = texto ?? ' ';
1071
- return opcAdicionales;
1072
- }
1073
- function generarDesdeMantenimiento(tabla) {
1074
- const celdasHeaderDetalle = [];
1075
- const tHead = [];
1076
- const titUsar = columnasValidas(tabla.titulos);
1077
- const camposTotales = titUsar.filter(titulo => titulo.reporte && titulo.reporte.totalizar).map(titulo => titulo.property);
1078
- const sumaObj = sumarObjetos(tabla.contenido, camposTotales);
1079
- if (tabla.numeracion) {
1080
- tHead.push(imprimirCelda('Nº', null, { style: 'thSmall', ...tabla.opcionesPdfmake?.titulo }));
1081
- }
1082
- titUsar.forEach(dT => {
1083
- if (tabla.titulosMayusculas) {
1084
- dT.label = dT.label.toUpperCase();
1085
- }
1086
- const opcionesPdfMakeTitulo = {
1087
- ...tabla.opcionesPdfmake?.titulo,
1088
- ...dT.reporte?.opcionesPdfmake?.titulo
1089
- };
1090
- tHead.push(imprimirCelda(dT.label.replace('<br>', ' '), null, { style: 'thSmall', ...opcionesPdfMakeTitulo }));
1091
- });
1092
- if (!tabla.sinTitulos) {
1093
- if (tabla.prependTitle) {
1094
- tabla.prependTitle.forEach((filaAdic) => {
1095
- celdasHeaderDetalle.push(filaAdic);
1096
- });
1097
- // celdasHeaderDetalle.concat(tabla.prependTitle);
1098
- }
1099
- celdasHeaderDetalle.push(tHead);
1100
- if (tabla.appendTitle) {
1101
- tabla.appendTitle.forEach((filaAdic) => {
1102
- celdasHeaderDetalle.push(filaAdic);
1103
- });
1104
- // celdasHeaderDetalle.concat(tabla.appendTitle);
1105
- }
1106
- }
1107
- let celdasBodyDetalle = [];
1108
- tabla.contenido.forEach((dataProd, idxProd) => {
1109
- const tBody = [];
1110
- if (tabla.numeracion) {
1111
- tBody.push(imprimirCelda(idxProd + 1, 'number', {
1112
- style: tabla.resaltarNumeracion == false ? 'tdSmall' : 'thSmall',
1113
- alignment: 'center',
1114
- rowSpan: tabla.detalle?.length > 0 ? 2 : 1,
1115
- ...tabla.opcionesPdfmake?.cuerpo
1116
- }));
1117
- }
1118
- titUsar.forEach(dT => {
1119
- let add;
1120
- if (dT.transformarDirecto) {
1121
- add = dT.transformarDirecto(dataProd);
1122
- }
1123
- else {
1124
- let txtImprimir = dataProd[dT.property];
1125
- if (dT.transformar)
1126
- txtImprimir = dT.transformar(dataProd);
1127
- const opcionesPdfMakeCuerpo = {
1128
- ...{
1129
- format: dT.format,
1130
- },
1131
- ...tabla.opcionesPdfmake?.cuerpo,
1132
- ...dT.reporte?.opcionesPdfmake?.cuerpo,
1133
- };
1134
- switch (dT.type) {
1135
- case 'date':
1136
- add = imprimirCelda(txtImprimir, 'date', {
1137
- style: 'tdSmall',
1138
- ...opcionesPdfMakeCuerpo
1139
- });
1140
- break;
1141
- case 'number':
1142
- add = imprimirCelda(txtImprimir, 'number', {
1143
- style: 'tdSmall',
1144
- ...opcionesPdfMakeCuerpo
1145
- });
1146
- break;
1147
- case 'money':
1148
- add = imprimirCelda(txtImprimir, 'money', {
1149
- style: 'tdSmall',
1150
- alignment: 'right',
1151
- ...opcionesPdfMakeCuerpo
1152
- });
1153
- break;
1154
- default:
1155
- add = imprimirCelda(txtImprimir, null, { style: 'tdSmall', ...opcionesPdfMakeCuerpo });
1156
- }
1157
- if (dT.cssClasses) {
1158
- dT.cssClasses.forEach((clase) => {
1159
- // @ts-ignore
1160
- add = { ...add, alignment: clase.replace('text-', '') };
1161
- });
1162
- }
1163
- }
1164
- tBody.push(add);
1165
- });
1166
- celdasBodyDetalle.push(tBody);
1167
- if (tabla.detalle?.length > 0) {
1168
- const tBody2 = [];
1169
- const lineasBody2 = [];
1170
- if (tabla.numeracion)
1171
- tBody2.push({});
1172
- titUsar.forEach(dT => tBody2.push({ text: dT.property }));
1173
- tabla.detalle.forEach((campoDet) => {
1174
- if (campoDet.label)
1175
- lineasBody2.push(JSON.parse(JSON.stringify(campoDet.label)));
1176
- if (dataProd[campoDet.campo]) {
1177
- lineasBody2.push(generarDesdeMantenimiento({
1178
- ...campoDet, contenido: dataProd[campoDet.campo]
1179
- }));
1180
- }
1181
- });
1182
- tBody2[tabla.numeracion ? 1 : 0] = {
1183
- colSpan: titUsar.length,
1184
- style: 'tdSmall',
1185
- stack: lineasBody2,
1186
- };
1187
- celdasBodyDetalle.push(tBody2);
1188
- }
1189
- });
1190
- const filaTotales = [];
1191
- if (tabla.numeracion) {
1192
- filaTotales.push(imprimirCelda('', null, { border: [false, false, false, false] }));
1193
- }
1194
- titUsar.forEach(titulo => {
1195
- if (titulo.reporte && titulo.reporte.totalizar) {
1196
- camposTotales.push(titulo.property);
1197
- let txtImprimirTotal = sumaObj[titulo.property] ?? 0;
1198
- if (titulo.reporte?.opcionesPdfmake?.total) {
1199
- txtImprimirTotal = tipoValorFuncion(titulo.reporte?.opcionesPdfmake?.total, titulo);
1200
- console.warn(txtImprimirTotal);
1201
- }
1202
- else if (typeof titulo.reporte.totalizar === 'object') {
1203
- if (typeof titulo.reporte.totalizar.transformar === 'function') {
1204
- txtImprimirTotal = titulo.reporte.totalizar.transformar(titulo);
1205
- }
1206
- else if (titulo.reporte.totalizar?.campoTotal) {
1207
- txtImprimirTotal = tabla.contenido[0] ? tabla.contenido[0][titulo.reporte.totalizar?.campoTotal] : '';
1208
- }
1209
- // txtImprimirTotal = titulo.reporte.transformar(titulo)
1210
- }
1211
- // @ts-ignore
1212
- const tipoCol = titulo.type;
1213
- filaTotales.push(imprimirCelda(txtImprimirTotal, tipoCol, {
1214
- bold: true, style: 'thSmall', alignment: 'right',
1215
- }));
1216
- }
1217
- else {
1218
- filaTotales.push(imprimirCelda('', null, { border: [false, false, false, false] }));
1219
- }
1220
- });
1221
- if (camposTotales && camposTotales.length > 0) {
1222
- celdasBodyDetalle = celdasBodyDetalle.concat([filaTotales]);
1223
- }
1224
- let filaTabla = celdasHeaderDetalle.concat(celdasBodyDetalle);
1225
- const tablaHeaderPedido = {
1226
- margin: tabla.margin ?? [0, 5, 0, 10],
1227
- table: {
1228
- dontBreakRows: true,
1229
- headerRows: tabla.filasTitulos ?? 1,
1230
- widths: anchoCols(celdasBodyDetalle.length > 0 ? celdasBodyDetalle : celdasHeaderDetalle, tabla.idxResto ?? [], tabla.idxAnchoValor ?? []),
1231
- body: filaTabla,
1232
- },
1233
- layout: tabla.sinBordes ? 'noBorders' : tabla.customLayout ?? undefined
1234
- };
1235
- if (tabla.separado) {
1236
- return {
1237
- titulos: celdasHeaderDetalle,
1238
- cuerpo: celdasBodyDetalle,
1239
- completo: tablaHeaderPedido,
1240
- };
1241
- }
1242
- // console.log(JSON.stringify(tablaHeaderPedido))
1243
- return tablaHeaderPedido;
1244
- }
1245
- function anchoCols(dataCant, idxResto = [], idxAnchoValor = []) {
1246
- const retorno = [];
1247
- if (Array.isArray(dataCant)) {
1248
- if (dataCant.length === 0)
1249
- return [];
1250
- dataCant[0].forEach((_, idx) => {
1251
- retorno.push(Array.isArray(idxResto) && idxResto.includes(idx) ? '*' : 'auto');
1252
- });
1253
- }
1254
- else {
1255
- for (let idx = 0; idx < dataCant; idx++) {
1256
- if (Array.isArray(idxResto)) {
1257
- retorno.push(idxResto.includes(idx) ? '*' : 'auto');
1258
- }
1259
- else {
1260
- retorno.push('*');
1261
- }
1262
- }
1263
- }
1264
- idxAnchoValor.forEach(({ idx, valor }) => {
1265
- if (idx == 'todos') {
1266
- retorno.fill(valor);
1267
- }
1268
- else {
1269
- retorno[idx] = valor;
1270
- }
1271
- });
1272
- return retorno;
1273
- }
1274
- /**
1275
- * Funciones PRIVADAS
1276
- */
1277
- function verificarColumnaTablaMantenimiento(titulo) {
1278
- return titulo.visible !== false && !titulo.ocultarReporte && (!titulo.reporte || !titulo.reporte.ocultar);
1279
- }
1280
- function columnasValidas(titulos) {
1281
- // Filtrar títulos visibles y válidos para el reporte
1282
- return titulos.map(titulo => ({
1283
- ...titulo,
1284
- visible: titulo.visible ?? true, // Asignar `true` si `visible` es `undefined`
1285
- })).filter(titulo => {
1286
- return (titulo.visible &&
1287
- !titulo.ocultarReporte &&
1288
- (!titulo.reporte || !titulo.reporte.ocultar));
1289
- });
1290
- }
1291
-
1292
- var formatearPdfmake = /*#__PURE__*/Object.freeze({
1293
- __proto__: null,
1294
- anchoCols: anchoCols,
1295
- generarDesdeMantenimiento: generarDesdeMantenimiento,
1296
- imprimirCelda: imprimirCelda
1297
- });
1298
-
1299
1037
  class DataModel {
1300
1038
  modelosChk = {}; // Usar any para valores dinámicos
1301
1039
  checkbox;
@@ -1677,6 +1415,14 @@ function zeroFill(value, digitos, ...args) {
1677
1415
  return new ZeroFillPipe().transform(value, digitos, args);
1678
1416
  }
1679
1417
 
1418
+ // @ts-ignore
1419
+ function tipoValorFuncion(datoParam, ...param) {
1420
+ if (typeof datoParam === 'function') {
1421
+ return datoParam(...param);
1422
+ }
1423
+ return datoParam;
1424
+ }
1425
+
1680
1426
  /*
1681
1427
  * Public API Surface of utils
1682
1428
  */
@@ -1688,5 +1434,5 @@ function zeroFill(value, digitos, ...args) {
1688
1434
  * Generated bundle index. Do not edit.
1689
1435
  */
1690
1436
 
1691
- export { DataEnListaPipe, DataModel, DateDiffStringPipe, FiltroPipe, FormControlIsRequiredPipe, JsonParsePipe, NoSanitizePipe, formatearPdfmake as PdfMake, ZeroFillPipe, b64Decode, b64Encode, buscarPorCampo, changeSelect, changeSelectApi, changeSelectData, changeSelectDataApi, convertirBytes, dataEnLista, dateDiffString, deepClone, deepMerge, delLocalStorage, desencriptar, downLoadFileStream, encriptar, esNumero, establecerQuitarRequired, formControlIsRequired, formatearFecha, formatearFechaCadena, formatearFechaFormato, generateRandomString, getBrowserName, getCambiarPwd, getDataArchivoFromPath, getFormValidationErrors, getLocalStorage, getUniqueValues, getUniqueValuesByProperty, inicializarVariablesSessionStorage, jwtToken, jwtTokenData, jwtTokenExpiracion, jwtTokenExpiracionFaltante, localStorageKeys, markAsTouchedWithoutEmitEvent, mensajeAlerta, mensajeConfirmacion, mensajeTimer, mensajeToast, mensajesDeError, mensajesErrorFormControl, mostrarValorEnBusqueda, objectPropertiesBoolean, objectPropertiesToType, obtenerMimeType, ordenarArray, ordenarPorPropiedad, ordenarPorPropiedades, roundToDecimal, sanitizarNombreArchivo, setCambiarPwd, setJwtTokenData, setLocalStorage, sumarObjetos, sumarPropiedades, tipoValorFuncion, toFormData, verificarRUC, zeroFill };
1437
+ export { DataEnListaPipe, DataModel, DateDiffStringPipe, FiltroPipe, FormControlIsRequiredPipe, JsonParsePipe, NoSanitizePipe, ZeroFillPipe, b64Decode, b64Encode, buscarPorCampo, changeSelect, changeSelectApi, changeSelectData, changeSelectDataApi, convertirBytes, dataEnLista, dateDiffString, deepClone, deepMerge, delLocalStorage, desencriptar, downLoadFileStream, encriptar, esNumero, establecerQuitarRequired, formControlIsRequired, formatearFecha, formatearFechaCadena, formatearFechaFormato, generateRandomString, getBrowserName, getCambiarPwd, getDataArchivoFromPath, getFormValidationErrors, getLocalStorage, getUniqueValues, getUniqueValuesByProperty, inicializarVariablesSessionStorage, jwtToken, jwtTokenData, jwtTokenExpiracion, jwtTokenExpiracionFaltante, localStorageKeys, markAsTouchedWithoutEmitEvent, mensajeAlerta, mensajeConfirmacion, mensajeTimer, mensajeToast, mensajesDeError, mensajesErrorFormControl, mostrarValorEnBusqueda, objectPropertiesBoolean, objectPropertiesToType, obtenerMimeType, ordenarArray, ordenarPorPropiedad, ordenarPorPropiedades, roundToDecimal, sanitizarNombreArchivo, seleccionarTextoInput, setCambiarPwd, setJwtTokenData, setLocalStorage, sumarObjetos, sumarPropiedades, tipoValorFuncion, toFormData, verificarRUC, zeroFill };
1692
1438
  //# sourceMappingURL=jvsoft-utils.mjs.map