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