@jvsoft/utils 0.0.13-alpha.4 → 0.0.13-alpha.6
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.
- package/classes/data-model.d.ts +25 -0
- package/fesm2022/jvsoft-utils-src-functions.mjs +1450 -0
- package/fesm2022/jvsoft-utils-src-functions.mjs.map +1 -0
- package/fesm2022/jvsoft-utils-src-interfaces.mjs +6 -0
- package/fesm2022/jvsoft-utils-src-interfaces.mjs.map +1 -0
- package/fesm2022/jvsoft-utils-src-pipes.mjs +290 -0
- package/fesm2022/jvsoft-utils-src-pipes.mjs.map +1 -0
- package/fesm2022/jvsoft-utils.mjs +1867 -0
- package/fesm2022/jvsoft-utils.mjs.map +1 -0
- package/functions/base64.d.ts +26 -0
- package/functions/browser.d.ts +1 -0
- package/functions/crypto-js.d.ts +2 -0
- package/functions/date.d.ts +3 -0
- package/functions/email.d.ts +2 -0
- package/functions/file.d.ts +10 -0
- package/functions/forms.d.ts +23 -0
- package/functions/http-client.d.ts +2 -0
- package/functions/index.d.ts +1 -0
- package/functions/local-storage.d.ts +29 -0
- package/functions/mat-form-controls/autocomplete.d.ts +51 -0
- package/functions/mat-form-controls/index.d.ts +2 -0
- package/functions/number.d.ts +2 -0
- package/functions/object-transformation.d.ts +2 -0
- package/functions/objects-arrays.d.ts +147 -0
- package/functions/public-api.d.ts +16 -0
- package/functions/string.d.ts +23 -0
- package/functions/sweetalert.d.ts +5 -0
- package/functions/utiles.d.ts +1 -0
- package/index.d.ts +5 -0
- package/{src/interfaces/datos.ts → interfaces/datos.d.ts} +1 -2
- package/interfaces/index.d.ts +1 -0
- package/interfaces/public-api.d.ts +1 -0
- package/package.json +28 -12
- package/pipes/data-en-lista.pipe.d.ts +8 -0
- package/pipes/date-diff-string.pipe.d.ts +17 -0
- package/pipes/filtro.pipe.d.ts +18 -0
- package/pipes/form-control-is-required.pipe.d.ts +9 -0
- package/pipes/index.d.ts +1 -0
- package/pipes/json-parse.pipe.d.ts +7 -0
- package/pipes/no-sanitize.pipe.d.ts +10 -0
- package/pipes/public-api.d.ts +8 -0
- package/pipes/tipo-valor-funcion.pipe.d.ts +9 -0
- package/pipes/zero-fill.pipe.d.ts +8 -0
- package/public-api.d.ts +4 -0
- package/src/functions/base64.d.ts +26 -0
- package/src/functions/browser.d.ts +1 -0
- package/src/functions/crypto-js.d.ts +2 -0
- package/src/functions/date.d.ts +3 -0
- package/src/functions/email.d.ts +2 -0
- package/src/functions/file.d.ts +10 -0
- package/src/functions/forms.d.ts +23 -0
- package/src/functions/http-client.d.ts +2 -0
- package/src/functions/index.d.ts +5 -0
- package/src/functions/local-storage.d.ts +29 -0
- package/src/functions/mat-form-controls/autocomplete.d.ts +51 -0
- package/src/functions/mat-form-controls/index.d.ts +2 -0
- package/src/functions/number.d.ts +2 -0
- package/src/functions/object-transformation.d.ts +2 -0
- package/src/functions/objects-arrays.d.ts +147 -0
- package/src/functions/public-api.d.ts +16 -0
- package/src/functions/string.d.ts +23 -0
- package/src/functions/sweetalert.d.ts +5 -0
- package/src/functions/utiles.d.ts +1 -0
- package/src/interfaces/datos.d.ts +4 -0
- package/src/interfaces/index.d.ts +5 -0
- package/src/interfaces/public-api.d.ts +1 -0
- package/src/pipes/data-en-lista.pipe.d.ts +8 -0
- package/src/pipes/date-diff-string.pipe.d.ts +17 -0
- package/src/pipes/filtro.pipe.d.ts +18 -0
- package/src/pipes/form-control-is-required.pipe.d.ts +9 -0
- package/src/pipes/index.d.ts +5 -0
- package/src/pipes/json-parse.pipe.d.ts +7 -0
- package/src/pipes/no-sanitize.pipe.d.ts +10 -0
- package/src/pipes/public-api.d.ts +8 -0
- package/src/pipes/tipo-valor-funcion.pipe.d.ts +9 -0
- package/src/pipes/zero-fill.pipe.d.ts +8 -0
- package/CHANGELOG.md +0 -25
- package/ng-package.json +0 -7
- package/src/classes/data-model.ts +0 -150
- package/src/functions/base64.ts +0 -8
- package/src/functions/browser.ts +0 -20
- package/src/functions/crypto-js.ts +0 -29
- package/src/functions/date.ts +0 -23
- package/src/functions/email.ts +0 -17
- package/src/functions/file.ts +0 -138
- package/src/functions/forms.ts +0 -251
- package/src/functions/http-client.ts +0 -110
- package/src/functions/index.ts +0 -1
- package/src/functions/local-storage.ts +0 -102
- package/src/functions/mat-form-controls/autocomplete.ts +0 -205
- package/src/functions/mat-form-controls/index.ts +0 -6
- package/src/functions/ng-package.json +0 -5
- package/src/functions/number.ts +0 -85
- package/src/functions/object-transformation.ts +0 -37
- package/src/functions/objects-arrays.ts +0 -321
- package/src/functions/public-api.ts +0 -19
- package/src/functions/string.ts +0 -68
- package/src/functions/sweetalert.ts +0 -95
- package/src/functions/utiles.ts +0 -20
- package/src/interfaces/index.ts +0 -1
- package/src/interfaces/ng-package.json +0 -5
- package/src/interfaces/otros.ts +0 -0
- package/src/interfaces/public-api.ts +0 -3
- package/src/interfaces/routes.ts +0 -42
- package/src/pipes/data-en-lista.pipe.ts +0 -40
- package/src/pipes/date-diff-string.pipe.ts +0 -117
- package/src/pipes/filtro.pipe.ts +0 -64
- package/src/pipes/form-control-is-required.pipe.ts +0 -17
- package/src/pipes/index.ts +0 -1
- package/src/pipes/json-parse.pipe.ts +0 -18
- package/src/pipes/ng-package.json +0 -5
- package/src/pipes/no-sanitize.pipe.ts +0 -12
- package/src/pipes/public-api.ts +0 -10
- package/src/pipes/tipo-valor-funcion.pipe.ts +0 -23
- package/src/pipes/zero-fill.pipe.ts +0 -19
- package/src/public-api.ts +0 -12
- package/tsconfig.lib.json +0 -18
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -15
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
import {esNumero} from '../objects-arrays';
|
|
2
|
-
import {AbstractControl} from '@angular/forms';
|
|
3
|
-
import {untilDestroyed} from '@ngneat/until-destroy';
|
|
4
|
-
import {debounceTime, finalize, isObservable, of, startWith, switchMap, tap} from 'rxjs';
|
|
5
|
-
import {map} from 'rxjs/operators';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Devuelve un valor de visualización para un elemento buscado.
|
|
9
|
-
* Compatible con listas simples, objetos y campos múltiples.
|
|
10
|
-
*/
|
|
11
|
-
export function mostrarValorEnBusqueda(campos: any, idxSel: any) {
|
|
12
|
-
const buscarEnLista = (lista: any[]) => {
|
|
13
|
-
if (!lista) return null;
|
|
14
|
-
if (campos.campoId === '*object*' || campos.campoId === '*objeto*') {
|
|
15
|
-
return lista.find((x: any) => JSON.stringify(x).trim() === JSON.stringify(idxSel).trim());
|
|
16
|
-
}
|
|
17
|
-
return lista.find((x: any) => x[campos.campoId] === idxSel);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const impDataMostrar = () => {
|
|
21
|
-
let vD = buscarEnLista(campos.lista) || (campos.opcExtra && buscarEnLista(campos.opcExtra));
|
|
22
|
-
if (!vD) return '';
|
|
23
|
-
|
|
24
|
-
if (Array.isArray(campos.campoValue)) {
|
|
25
|
-
return campos.campoValue.map((vCampo: any) => vD[vCampo] ?? '').join(' - ').trim();
|
|
26
|
-
}
|
|
27
|
-
return (vD[campos.campoValue] ?? '').trim();
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
if (esNumero(idxSel)) {
|
|
31
|
-
if ((idxSel > 0 && campos.lista?.length) || (idxSel && typeof idxSel === 'object')) {
|
|
32
|
-
return impDataMostrar();
|
|
33
|
-
}
|
|
34
|
-
} else if (campos.lista?.length) {
|
|
35
|
-
return impDataMostrar();
|
|
36
|
-
}
|
|
37
|
-
return '';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Filtra datos locales de un array basado en un valor de búsqueda.
|
|
42
|
-
*/
|
|
43
|
-
function filtrarDatosLocal(data: any[], value: any, campoBuscar: string | string[]) {
|
|
44
|
-
if (!value) return data;
|
|
45
|
-
|
|
46
|
-
const normalizar = (val: any) => val?.toString()?.toLowerCase() ?? '';
|
|
47
|
-
const esNum = !isNaN(Number(value));
|
|
48
|
-
|
|
49
|
-
return data.filter(item => {
|
|
50
|
-
const campos = Array.isArray(campoBuscar) ? campoBuscar : [campoBuscar];
|
|
51
|
-
return campos.some(campo => {
|
|
52
|
-
const campoVal = item[campo];
|
|
53
|
-
if (campoVal == null) return false;
|
|
54
|
-
return esNum
|
|
55
|
-
? campoVal.toString().includes(value.toString())
|
|
56
|
-
: normalizar(campoVal).includes(normalizar(value));
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Vincula un FormControl a datos locales para autocompletado.
|
|
63
|
-
*/
|
|
64
|
-
export function changeSelectData(objThis: any, { formControl, data, campoBuscar, variableResultado }: {
|
|
65
|
-
formControl: AbstractControl;
|
|
66
|
-
data: any[];
|
|
67
|
-
campoBuscar: string | string[];
|
|
68
|
-
variableResultado: string;
|
|
69
|
-
}) {
|
|
70
|
-
objThis.filtrados[variableResultado] = formControl.valueChanges.pipe(untilDestroyed(objThis)).pipe(
|
|
71
|
-
startWith(''),
|
|
72
|
-
map(value => data ? filtrarDatosLocal(data, value, campoBuscar) : [])
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Vincula un FormControl a datos locales obtenidos de dataServidor o dataServidorSuscripcion.
|
|
78
|
-
*/
|
|
79
|
-
export function changeSelect(control: any, formControl: AbstractControl, tipo: string, campoBuscar: string | string[], campoFiltro: string | null = null) {
|
|
80
|
-
const filtro = campoFiltro ?? tipo;
|
|
81
|
-
control.filtrados[filtro] = formControl.valueChanges.pipe(untilDestroyed(control)).pipe(
|
|
82
|
-
startWith(''),
|
|
83
|
-
map(value => {
|
|
84
|
-
const partes = tipo.split('.');
|
|
85
|
-
const varN =
|
|
86
|
-
control.dataServidor?.[partes[0]]?.[partes[1]] ??
|
|
87
|
-
control.dataServidor?.[tipo] ??
|
|
88
|
-
control.dataServidorSuscripcion?.[tipo]?.getValue();
|
|
89
|
-
|
|
90
|
-
return varN ? filtrarDatosLocal(varN, value, campoBuscar) : [];
|
|
91
|
-
})
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Configuración para changeSelectReformateado.
|
|
97
|
-
*/
|
|
98
|
-
interface ChangeSelectConfig {
|
|
99
|
-
objThis: any;
|
|
100
|
-
tipoReq: string;
|
|
101
|
-
formControl: AbstractControl;
|
|
102
|
-
queryService: any;
|
|
103
|
-
campoId?: string;
|
|
104
|
-
minLength?: number;
|
|
105
|
-
dataExtra?: any;
|
|
106
|
-
dataExtraVariable?: { campo: string; ctrlValue: AbstractControl }[];
|
|
107
|
-
anonimo?: boolean;
|
|
108
|
-
variableResultado?: string;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Función genérica para vincular un FormControl con datos desde API o Promise.
|
|
113
|
-
* Preparada para migrar a signals en el futuro.
|
|
114
|
-
*/
|
|
115
|
-
export function changeSelectReformateado(config: ChangeSelectConfig) {
|
|
116
|
-
const {
|
|
117
|
-
objThis,
|
|
118
|
-
tipoReq,
|
|
119
|
-
formControl,
|
|
120
|
-
queryService,
|
|
121
|
-
campoId,
|
|
122
|
-
minLength = 3,
|
|
123
|
-
dataExtra = {},
|
|
124
|
-
dataExtraVariable = [],
|
|
125
|
-
anonimo = false,
|
|
126
|
-
variableResultado = tipoReq,
|
|
127
|
-
} = config;
|
|
128
|
-
|
|
129
|
-
formControl.valueChanges.pipe(
|
|
130
|
-
debounceTime(500),
|
|
131
|
-
tap(() => {
|
|
132
|
-
objThis.filtrados[variableResultado + 'tmp'] = isObservable(objThis.filtrados[variableResultado])
|
|
133
|
-
? []
|
|
134
|
-
: objThis.filtrados[variableResultado] || [];
|
|
135
|
-
if (objThis.filtrados[variableResultado] !== objThis.filtrados[variableResultado + 'tmp']) {
|
|
136
|
-
objThis.filtrados[variableResultado] = [];
|
|
137
|
-
}
|
|
138
|
-
objThis.isLoading = true;
|
|
139
|
-
}),
|
|
140
|
-
switchMap(value => {
|
|
141
|
-
if (campoId) {
|
|
142
|
-
const existe = objThis.filtrados[variableResultado + 'tmp']
|
|
143
|
-
.findIndex((item: any) => item[campoId] === value);
|
|
144
|
-
if (existe >= 0) {
|
|
145
|
-
return of({ [tipoReq]: objThis.filtrados[variableResultado + 'tmp'] });
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
if (!value || value.length < minLength) {
|
|
149
|
-
objThis.isLoading = false;
|
|
150
|
-
return of({ [tipoReq]: [] });
|
|
151
|
-
}
|
|
152
|
-
const extraVars = Object.fromEntries(dataExtraVariable.map(v => [v.campo, v.ctrlValue.value]));
|
|
153
|
-
const query = queryService.getDataMethod('GET', tipoReq, { ...dataExtra, ...extraVars, txtBuscar: value }, anonimo);
|
|
154
|
-
|
|
155
|
-
if (esPromise(query)) {
|
|
156
|
-
return query.then((data: any) => ({ [tipoReq]: data[tipoReq] ?? [] }))
|
|
157
|
-
.finally(() => { objThis.isLoading = false; });
|
|
158
|
-
}
|
|
159
|
-
return query.pipe(finalize(() => { objThis.isLoading = false; }));
|
|
160
|
-
})
|
|
161
|
-
).subscribe((data: any) => {
|
|
162
|
-
objThis.filtrados[variableResultado] = data[tipoReq] ?? [];
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Alias para compatibilidad.
|
|
168
|
-
*/
|
|
169
|
-
export function changeSelectDataApi(objThis: any, dataFiltro: any) {
|
|
170
|
-
return changeSelectReformateado({
|
|
171
|
-
objThis,
|
|
172
|
-
tipoReq: dataFiltro.tipoReq,
|
|
173
|
-
formControl: dataFiltro.formControl,
|
|
174
|
-
queryService: dataFiltro.queryService,
|
|
175
|
-
campoId: dataFiltro.campoId,
|
|
176
|
-
minLength: dataFiltro.minLength,
|
|
177
|
-
dataExtra: dataFiltro.dataExtra,
|
|
178
|
-
dataExtraVariable: dataFiltro.dataExtraVariable,
|
|
179
|
-
anonimo: dataFiltro.anonimo,
|
|
180
|
-
variableResultado: dataFiltro.variableResultado,
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Alias para compatibilidad.
|
|
186
|
-
*/
|
|
187
|
-
export function changeSelectApi(control: any, queryService: any, formControl: AbstractControl, tipo: any, dataExtra = {}, dataExtraVariable: any[] | null = null, minLength = 1, anonimo = false) {
|
|
188
|
-
return changeSelectReformateado({
|
|
189
|
-
objThis: control,
|
|
190
|
-
tipoReq: tipo,
|
|
191
|
-
formControl,
|
|
192
|
-
queryService,
|
|
193
|
-
minLength,
|
|
194
|
-
dataExtra,
|
|
195
|
-
dataExtraVariable: dataExtraVariable ?? [],
|
|
196
|
-
anonimo,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Comprueba si un valor es una Promesa.
|
|
202
|
-
*/
|
|
203
|
-
function esPromise(valor: any): valor is Promise<any> {
|
|
204
|
-
return !!valor && typeof valor.then === 'function';
|
|
205
|
-
}
|
package/src/functions/number.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
export function roundToDecimal(number: number, decimal: number): number {
|
|
2
|
-
return parseFloat(number.toFixed(decimal));
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function numberToWords(num: number): string {
|
|
6
|
-
if (num === 0) return 'cero';
|
|
7
|
-
if (num < 0) return 'menos ' + numberToWords(Math.abs(num));
|
|
8
|
-
if (num > 999999999999) return 'número demasiado grande';
|
|
9
|
-
|
|
10
|
-
const ones = ['', 'un', 'dos', 'tres', 'cuatro', 'cinco', 'seis', 'siete', 'ocho', 'nueve'];
|
|
11
|
-
const onesFinal = ['', 'uno', 'dos', 'tres', 'cuatro', 'cinco', 'seis', 'siete', 'ocho', 'nueve'];
|
|
12
|
-
const tens = ['', 'diez', 'veinte', 'treinta', 'cuarenta', 'cincuenta', 'sesenta', 'setenta', 'ochenta', 'noventa'];
|
|
13
|
-
const teens = ['diez', 'once', 'doce', 'trece', 'catorce', 'quince', 'dieciséis', 'diecisiete', 'dieciocho', 'diecinueve'];
|
|
14
|
-
const hundreds = ['', 'ciento', 'doscientos', 'trescientos', 'cuatrocientos', 'quinientos', 'seiscientos', 'setecientos', 'ochocientos', 'novecientos'];
|
|
15
|
-
|
|
16
|
-
// Función auxiliar para "un"/"uno"
|
|
17
|
-
const getOneForm = (n: number, isFinal: boolean): string =>
|
|
18
|
-
n === 1 ? (isFinal ? 'uno':'un'):onesFinal[n];
|
|
19
|
-
|
|
20
|
-
let words = '';
|
|
21
|
-
|
|
22
|
-
// Miles de millones (ahora sí se ejecuta)
|
|
23
|
-
if (num >= 1000000000) {
|
|
24
|
-
const billions = Math.floor(num / 1000000000);
|
|
25
|
-
words += (billions === 1 ? 'mil':numberToWords(billions) + ' mil') + ' millones ';
|
|
26
|
-
num %= 1000000000;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Millones
|
|
30
|
-
if (num >= 1000000) {
|
|
31
|
-
const millions = Math.floor(num / 1000000);
|
|
32
|
-
words += millions === 1 ? 'un millón ':numberToWords(millions) + ' millones ';
|
|
33
|
-
num %= 1000000;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Miles
|
|
37
|
-
if (num >= 1000) {
|
|
38
|
-
const thousands = Math.floor(num / 1000);
|
|
39
|
-
words += thousands === 1 ? 'mil ':numberToWords(thousands) + ' mil ';
|
|
40
|
-
num %= 1000;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Centenas (con tratamiento especial para "ciento uno")
|
|
44
|
-
if (num >= 100) {
|
|
45
|
-
if (num === 100) {
|
|
46
|
-
words += 'cien';
|
|
47
|
-
num = 0;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
words += hundreds[Math.floor(num / 100)];
|
|
51
|
-
num %= 100;
|
|
52
|
-
if (num > 0) {
|
|
53
|
-
words += ' ' + getOneForm(num, true); // Siempre "uno" después de ciento
|
|
54
|
-
num = 0;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Decenas y unidades
|
|
60
|
-
if (num > 0) {
|
|
61
|
-
const isFinalWord = words === '';
|
|
62
|
-
|
|
63
|
-
if (num < 10) {
|
|
64
|
-
words += getOneForm(num, isFinalWord);
|
|
65
|
-
}
|
|
66
|
-
else if (num < 20) {
|
|
67
|
-
words += teens[num - 10];
|
|
68
|
-
}
|
|
69
|
-
else if (num < 30) {
|
|
70
|
-
if (num === 21) words += 'veintiuno';
|
|
71
|
-
else if (num === 22) words += 'veintidós';
|
|
72
|
-
else if (num === 23) words += 'veintitrés';
|
|
73
|
-
else if (num === 26) words += 'veintiséis';
|
|
74
|
-
else words += `veinti${onesFinal[num % 10]}`;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
words += tens[Math.floor(num / 10)];
|
|
78
|
-
if (num % 10 > 0) {
|
|
79
|
-
words += ' y ' + getOneForm(num % 10, isFinalWord);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return words.trim().replace(/\s+/g, ' ');
|
|
85
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {formatDate} from '@angular/common';
|
|
2
|
-
import {formatearFecha} from './date';
|
|
3
|
-
|
|
4
|
-
export function objectPropertiesToType(formFields: Record<string, any>) {
|
|
5
|
-
Object.keys(formFields).filter(control => !!formFields[control]).forEach(control => {
|
|
6
|
-
if (/^dt[a-zA-Z]+/.test(control)) {
|
|
7
|
-
formFields[control] = formatDate(formFields[control], 'yyyy-MM-dd HH:mm', 'es-PE');
|
|
8
|
-
}
|
|
9
|
-
else if (control.startsWith('d')) {
|
|
10
|
-
formFields[control] = formatearFecha(formFields[control]);
|
|
11
|
-
}
|
|
12
|
-
else if (control.startsWith('n')) {
|
|
13
|
-
formFields[control] = Number(formFields[control]);
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
return formFields;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function objectPropertiesBoolean(formFields: Record<string, any>, retorno: 'boolean' | 'bit' = 'boolean') {
|
|
21
|
-
Object.keys(formFields).forEach(control => {
|
|
22
|
-
const valRetorno = (ctrl: any) => {
|
|
23
|
-
switch (retorno) {
|
|
24
|
-
case 'boolean':
|
|
25
|
-
formFields[ctrl] = formFields[ctrl] == 1;
|
|
26
|
-
break;
|
|
27
|
-
case 'bit':
|
|
28
|
-
formFields[ctrl] = formFields[ctrl] ? 1:0;
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
if (control.charAt(0) == 'b' || (control.charAt(0) == 'i' && control.indexOf('Estado') !== -1)) {
|
|
33
|
-
valRetorno(control);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return formFields;
|
|
37
|
-
}
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
export function deepMerge(source: any, target: any): any {
|
|
2
|
-
// Crea un clon profundo sin usar JSON.parse(JSON.stringify)
|
|
3
|
-
let cloneSource = deepClone(source);
|
|
4
|
-
|
|
5
|
-
if (typeof target !== 'object' || target === null) {
|
|
6
|
-
return target;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
if (typeof cloneSource !== 'object' || cloneSource === null) {
|
|
10
|
-
cloneSource = Array.isArray(target) ? [] : {};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
for (const key of Object.keys(target)) {
|
|
14
|
-
const targetValue = target[key];
|
|
15
|
-
const sourceValue = cloneSource[key];
|
|
16
|
-
|
|
17
|
-
if (typeof targetValue === 'object' && targetValue !== null && !Array.isArray(targetValue)) {
|
|
18
|
-
cloneSource[key] = deepMerge(sourceValue, targetValue);
|
|
19
|
-
} else {
|
|
20
|
-
cloneSource[key] = targetValue;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return cloneSource; // Retorna el clon y no modifica el original
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Función de clonación profunda que maneja funciones, fechas y otros tipos especiales
|
|
27
|
-
export function deepClone(obj: any): any {
|
|
28
|
-
if (obj === null || typeof obj !== 'object') {
|
|
29
|
-
return obj; // Devuelve el valor si no es un objeto
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Manejar instancias de Date
|
|
33
|
-
if (obj instanceof Date) {
|
|
34
|
-
return new Date(obj.getTime());
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Manejar funciones devolviendo una copia directa
|
|
38
|
-
if (typeof obj === 'function') {
|
|
39
|
-
return obj.bind({}); // Devuelve una copia de la función enlazada a un contexto vacío
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Crear un nuevo objeto o array
|
|
43
|
-
const clonedObj: Record<string, any> = Array.isArray(obj) ? [] : {};
|
|
44
|
-
|
|
45
|
-
// Clonar recursivamente las propiedades del objeto
|
|
46
|
-
for (const key in obj) {
|
|
47
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
48
|
-
clonedObj[key] = deepClone(obj[key]);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return clonedObj;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Busca un elemento en un array o jerarquía de objetos según un campo y valor especificado.
|
|
57
|
-
*
|
|
58
|
-
* @returns El elemento encontrado o undefined si no existe.
|
|
59
|
-
*/
|
|
60
|
-
export function buscarPorCampo<T>(datosFn: {
|
|
61
|
-
items: T[];
|
|
62
|
-
campo: keyof T;
|
|
63
|
-
valor: any;
|
|
64
|
-
campoHijo?: string; // Campo opcional para búsqueda recursiva
|
|
65
|
-
}): T | undefined {
|
|
66
|
-
for (const item of datosFn.items) {
|
|
67
|
-
// Verifica si el campo coincide con el valor
|
|
68
|
-
if (item[datosFn.campo] === datosFn.valor) {
|
|
69
|
-
return item;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Verifica si hay un campo hijo y si es un array
|
|
73
|
-
if (datosFn.campoHijo && item[datosFn.campoHijo as keyof T] && Array.isArray(item[datosFn.campoHijo as keyof T])) {
|
|
74
|
-
// Realiza la búsqueda recursiva en el campo hijo
|
|
75
|
-
const encontrado = buscarPorCampo({
|
|
76
|
-
items: item[datosFn.campoHijo as keyof T] as T[], // Asegura el tipo correcto
|
|
77
|
-
campo: datosFn.campo,
|
|
78
|
-
valor: datosFn.valor,
|
|
79
|
-
campoHijo: datosFn.campoHijo,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
// Si se encuentra el valor en el campo hijo, retorna el resultado
|
|
83
|
-
if (encontrado) {
|
|
84
|
-
return encontrado;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Si no se encuentra nada, retorna undefined
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function sumarPropiedades(item: Record<string, any>, campos: string[]) {
|
|
94
|
-
const datosSumar = campos.map(campo => (item[campo] * 1));
|
|
95
|
-
return datosSumar.reduce((a, b) => a + b, 0);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function esNumero(value: any): boolean {
|
|
99
|
-
return !isNaN(Number(value));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function sumarObjetos(arrayObjetos: any[], campos: string[]): Record<string, number> {
|
|
103
|
-
return arrayObjetos.reduce((accumulator: Record<string, number>, item: any) => {
|
|
104
|
-
campos.forEach(campo => {
|
|
105
|
-
const valor = Number(item[campo]);
|
|
106
|
-
if (!isNaN(valor)) {
|
|
107
|
-
accumulator[campo] = (accumulator[campo] ?? 0) + valor;
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
return accumulator;
|
|
111
|
-
}, {});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export function getUniqueValues(array: any[]) {
|
|
115
|
-
return array.filter((currentValue, index, arr) => (
|
|
116
|
-
arr.indexOf(currentValue) === index
|
|
117
|
-
));
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export function getUniqueValuesByProperty<T>(objetos: T[], campo: string): T[] {
|
|
121
|
-
const objetosUnicos: {[key: string]: T} = {};
|
|
122
|
-
|
|
123
|
-
objetos.forEach(objeto => {
|
|
124
|
-
// Verificar si el objeto tiene el campo especificado
|
|
125
|
-
// @ts-ignore
|
|
126
|
-
if (objeto.hasOwnProperty(campo)) {
|
|
127
|
-
// @ts-ignore
|
|
128
|
-
const valorCampo = objeto[campo];
|
|
129
|
-
|
|
130
|
-
// Utilizar el valor del campo como clave en un objeto para asegurar que no haya duplicados
|
|
131
|
-
objetosUnicos[valorCampo] = objeto;
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
// Convertir el objeto de claves únicas de vuelta a una lista de objetos
|
|
136
|
-
return Object.values(objetosUnicos);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
export function ordenarArray(array: any[], numeros = false, sentido: 'ASC' | 'DESC' = 'ASC'): any[] {
|
|
141
|
-
if (numeros) {
|
|
142
|
-
if (sentido != 'ASC') {
|
|
143
|
-
return array.sort((a: any, b: any) => b - a);
|
|
144
|
-
}
|
|
145
|
-
return array.sort((a: any, b: any) => a - b);
|
|
146
|
-
}
|
|
147
|
-
return array.sort((a, b) => (a > b) ? 1:((b > a) ? -1:0));
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export function ordenarPorPropiedad(objData: any, propiedad: string, /**@deprecated*/ numeros = false) {
|
|
152
|
-
return ordenarPorPropiedades(objData, {propiedades: [propiedad], direcciones:['asc']});
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
export function ordenarPorPropiedades<T>(arr: T[], options: {
|
|
156
|
-
propiedades: (keyof T)[],
|
|
157
|
-
direcciones?: ('asc' | 'desc' | '')[],
|
|
158
|
-
}): T[] {
|
|
159
|
-
const {propiedades, direcciones = []} = options;
|
|
160
|
-
const orden = direcciones.map(d => d === 'desc' ? -1:1);
|
|
161
|
-
|
|
162
|
-
return [...arr].sort((a, b) => {
|
|
163
|
-
return propiedades.reduce((acc, propiedad, index) => {
|
|
164
|
-
if (acc !== 0) return acc; // Si ya hay diferencia, no seguir comparando
|
|
165
|
-
|
|
166
|
-
const aValue = a[propiedad];
|
|
167
|
-
const bValue = b[propiedad];
|
|
168
|
-
|
|
169
|
-
if (typeof aValue === 'string' && typeof bValue === 'string') {
|
|
170
|
-
return aValue.localeCompare(bValue) * orden[index]; // 🔹 Comparación alfabética
|
|
171
|
-
}
|
|
172
|
-
if (typeof aValue === 'number' && typeof bValue === 'number') {
|
|
173
|
-
return (aValue - bValue) * orden[index]; // 🔹 Comparación numérica
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return 0; // En caso de valores no comparables
|
|
177
|
-
}, 0);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export function groupBy<T extends Record<string, any>, K extends keyof T>(
|
|
182
|
-
array: T[],
|
|
183
|
-
key: K | ((obj: T) => string)
|
|
184
|
-
): Record<string, T[]> {
|
|
185
|
-
const keyFn = key instanceof Function ? key:(obj: T) => obj[key];
|
|
186
|
-
return array.reduce((objectsByKeyValue, obj) => {
|
|
187
|
-
const value = keyFn(obj);
|
|
188
|
-
objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
|
|
189
|
-
return objectsByKeyValue;
|
|
190
|
-
}, {} as Record<string, T[]>);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export function nestGroupsBy(arr: any, properties: any) {
|
|
194
|
-
const fnGroupBy = (conversions: any, property2: any) => {
|
|
195
|
-
return conversions.reduce((acc: any, obj: any) => {
|
|
196
|
-
const key = obj[property2];
|
|
197
|
-
if (!acc[key]) {
|
|
198
|
-
acc[key] = [];
|
|
199
|
-
}
|
|
200
|
-
acc[key].push(obj);
|
|
201
|
-
return acc;
|
|
202
|
-
}, {});
|
|
203
|
-
};
|
|
204
|
-
properties = Array.from(properties);
|
|
205
|
-
if (properties.length === 1) {
|
|
206
|
-
return fnGroupBy(arr, properties[0]);
|
|
207
|
-
}
|
|
208
|
-
const property = properties.shift();
|
|
209
|
-
const grouped = fnGroupBy(arr, property);
|
|
210
|
-
Object.keys(grouped).forEach(key => {
|
|
211
|
-
grouped[key] = nestGroupsBy(grouped[key], Array.from(properties));
|
|
212
|
-
});
|
|
213
|
-
return grouped;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Obtiene un valor de un objeto usando una ruta de propiedad anidada.
|
|
219
|
-
*
|
|
220
|
-
* @param obj - Objeto de entrada.
|
|
221
|
-
* @param path - Ruta en formato punto (ej: "cliente.orden").
|
|
222
|
-
* @returns El valor encontrado o undefined si no existe.
|
|
223
|
-
*/
|
|
224
|
-
function getValueByPath(obj: any, path: string): any {
|
|
225
|
-
return path.split('.').reduce((acc, key) => acc?.[key], obj);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Retorna el valor máximo del campo especificado (incluso anidado) en un arreglo de objetos.
|
|
230
|
-
*
|
|
231
|
-
* @param data - Lista de objetos a procesar.
|
|
232
|
-
* @param campo - Nombre del campo a evaluar, puede ser anidado (ej. "campo.orden").
|
|
233
|
-
* @param incrementar - Si es true, retorna el valor máximo + 1. Por defecto es true.
|
|
234
|
-
* @returns El valor máximo encontrado, posiblemente incrementado.
|
|
235
|
-
*/
|
|
236
|
-
export function obtenerUltimoOrden(data: any[], campo: string, incrementar: boolean = true): number {
|
|
237
|
-
const max = data.reduce((mayor, item) => {
|
|
238
|
-
const valor = Number(getValueByPath(item, campo)) || 0;
|
|
239
|
-
return valor > mayor ? valor:mayor;
|
|
240
|
-
}, 0);
|
|
241
|
-
|
|
242
|
-
return incrementar ? max + 1:max;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Elimina una o varias columnas específicas (por índice) de una tabla representada como array de arrays.
|
|
248
|
-
*
|
|
249
|
-
* @param data - Array de filas (cada fila debe ser un array).
|
|
250
|
-
* @param columnIndex - Índice o lista de índices de las columnas a eliminar.
|
|
251
|
-
* @returns Nuevo array con las columnas eliminadas.
|
|
252
|
-
*/
|
|
253
|
-
export function eliminarColumnaPorIndex<T extends unknown[][]>(
|
|
254
|
-
data: T,
|
|
255
|
-
columnIndex: number | number[]
|
|
256
|
-
): T {
|
|
257
|
-
if (!Array.isArray(data)) return [] as unknown as T;
|
|
258
|
-
|
|
259
|
-
// Normalizar a array único y ordenado (descendente para evitar reindexación al splicing)
|
|
260
|
-
const indices: number[] = Array.isArray(columnIndex)
|
|
261
|
-
? [...new Set(columnIndex)].filter((i) => (typeof i === 'number' && i >= 0)).sort((a, b) => b - a)
|
|
262
|
-
:[columnIndex];
|
|
263
|
-
|
|
264
|
-
return data.map((row) => {
|
|
265
|
-
if (!Array.isArray(row)) return row;
|
|
266
|
-
|
|
267
|
-
const newRow = [...row];
|
|
268
|
-
|
|
269
|
-
for (const index of indices) {
|
|
270
|
-
if (index >= 0 && index < newRow.length) {
|
|
271
|
-
newRow.splice(index, 1);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return newRow as typeof row;
|
|
276
|
-
}) as T;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
export function eliminarDuplicados<T extends object>(
|
|
282
|
-
array: T[],
|
|
283
|
-
claves?: (keyof T)[]
|
|
284
|
-
): T[] {
|
|
285
|
-
const unicos = new Map<string, T>();
|
|
286
|
-
|
|
287
|
-
for (const item of array) {
|
|
288
|
-
const claveUnica = claves && claves.length > 0
|
|
289
|
-
? claves.map(k => item[k]).join('|')
|
|
290
|
-
: JSON.stringify(item);
|
|
291
|
-
|
|
292
|
-
if (!unicos.has(claveUnica)) {
|
|
293
|
-
unicos.set(claveUnica, item);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return Array.from(unicos.values());
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
export function eliminarElementos<T extends object>(
|
|
301
|
-
origen: T[],
|
|
302
|
-
elementosAEliminar: T[],
|
|
303
|
-
claves?: (keyof T)[]
|
|
304
|
-
): T[] {
|
|
305
|
-
const clavesSet = new Set<string>();
|
|
306
|
-
|
|
307
|
-
for (const item of elementosAEliminar) {
|
|
308
|
-
const key = claves && claves.length > 0
|
|
309
|
-
? claves.map(k => item[k]).join('|')
|
|
310
|
-
: JSON.stringify(item);
|
|
311
|
-
clavesSet.add(key);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return origen.filter(item => {
|
|
315
|
-
const key = claves && claves.length > 0
|
|
316
|
-
? claves.map(k => item[k]).join('|')
|
|
317
|
-
: JSON.stringify(item);
|
|
318
|
-
return !clavesSet.has(key);
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from './mat-form-controls';
|
|
2
|
-
|
|
3
|
-
export * from './base64'
|
|
4
|
-
export * from './browser'
|
|
5
|
-
export * from './crypto-js';
|
|
6
|
-
export * from './date';
|
|
7
|
-
export * from './email';
|
|
8
|
-
export * from './file'
|
|
9
|
-
export * from './forms'
|
|
10
|
-
export * from './http-client'
|
|
11
|
-
export * from './local-storage';
|
|
12
|
-
export * from './number';
|
|
13
|
-
export * from './object-transformation'
|
|
14
|
-
export * from './objects-arrays'
|
|
15
|
-
export * from './string'
|
|
16
|
-
export * from './sweetalert'
|
|
17
|
-
export * from './utiles'
|
|
18
|
-
|
|
19
|
-
|