@jvsoft/utils 0.0.13-alpha.1 → 0.0.13-alpha.2
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 +1109 -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 +1526 -0
- package/fesm2022/jvsoft-utils.mjs.map +1 -0
- package/functions/base64.d.ts +2 -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 +10 -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 +21 -0
- package/functions/mat-form-controls/index.d.ts +2 -0
- package/functions/number.d.ts +1 -0
- package/functions/object-transformation.d.ts +2 -0
- package/functions/objects-arrays.d.ts +37 -0
- package/functions/public-api.d.ts +16 -0
- package/functions/string.d.ts +1 -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 +25 -2
- 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 +2 -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 +10 -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 +21 -0
- package/src/functions/mat-form-controls/index.d.ts +2 -0
- package/src/functions/number.d.ts +1 -0
- package/src/functions/object-transformation.d.ts +2 -0
- package/src/functions/objects-arrays.d.ts +37 -0
- package/src/functions/public-api.d.ts +16 -0
- package/src/functions/string.d.ts +1 -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 -13
- 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 -145
- 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 -275
- package/src/functions/mat-form-controls/index.ts +0 -6
- package/src/functions/ng-package.json +0 -5
- package/src/functions/number.ts +0 -3
- package/src/functions/object-transformation.ts +0 -37
- package/src/functions/objects-arrays.ts +0 -243
- package/src/functions/public-api.ts +0 -19
- package/src/functions/string.ts +0 -9
- 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 -17
- package/tsconfig.lib.prod.json +0 -11
- package/tsconfig.spec.json +0 -15
|
@@ -1,275 +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
|
-
export function mostrarValorEnBusqueda(campos: any, idxSel: any) {
|
|
8
|
-
const impDataMostrar = () => {
|
|
9
|
-
let vD;
|
|
10
|
-
if (campos.campoId == '*object*' || campos.campoId == '*objeto*') {
|
|
11
|
-
console.log(campos);
|
|
12
|
-
vD = campos.lista.find((x: any) => JSON.stringify(x).trim() == JSON.stringify(idxSel).trim());
|
|
13
|
-
console.log(vD);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
vD = campos.lista.find((x: any) => x[campos.campoId] == idxSel);
|
|
17
|
-
}
|
|
18
|
-
if (!vD && campos.opcExtra) {
|
|
19
|
-
console.log('eval ', campos.opcExtra);
|
|
20
|
-
if (campos.campoId == '*object*' || campos.campoId == '*objeto*') {
|
|
21
|
-
console.log(campos);
|
|
22
|
-
vD = campos.opcExtra.find((x: any) => JSON.stringify(x).trim() == JSON.stringify(idxSel).trim());
|
|
23
|
-
console.log(vD);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
vD = campos.opcExtra.find((x: any) => x[campos.campoId] == idxSel);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (vD) {
|
|
30
|
-
let txtFinal = '';
|
|
31
|
-
if (Array.isArray(campos.campoValue)) {
|
|
32
|
-
campos.campoValue.forEach((vCampo: any, idx: any) => {
|
|
33
|
-
txtFinal += (vD[vCampo] ?? '');
|
|
34
|
-
if (idx < campos.campoValue.length - 1) {
|
|
35
|
-
txtFinal += ' - ';
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
txtFinal = vD[campos.campoValue] ?? '';
|
|
41
|
-
}
|
|
42
|
-
return txtFinal.trim();
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
console.log('ASSSSS ----- SSSS ');
|
|
46
|
-
}
|
|
47
|
-
return '';
|
|
48
|
-
};
|
|
49
|
-
if (esNumero(idxSel)) {
|
|
50
|
-
if (idxSel > 0 && campos.lista?.length > 0) {
|
|
51
|
-
return impDataMostrar();
|
|
52
|
-
}
|
|
53
|
-
else if (idxSel && typeof idxSel == 'object') {
|
|
54
|
-
return impDataMostrar();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
if (campos.lista?.length > 0) {
|
|
59
|
-
return impDataMostrar();
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return '';
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
export function changeSelectData(objThis: any, dataFiltro: {
|
|
67
|
-
formControl: AbstractControl,
|
|
68
|
-
data: any[],
|
|
69
|
-
campoBuscar: string | string[],
|
|
70
|
-
variableResultado: string,
|
|
71
|
-
}) {
|
|
72
|
-
objThis['filtrados'][dataFiltro.variableResultado] = dataFiltro.formControl.valueChanges.pipe(untilDestroyed(objThis)).pipe(
|
|
73
|
-
startWith(''),
|
|
74
|
-
map(value => {
|
|
75
|
-
|
|
76
|
-
const varN = dataFiltro.data;
|
|
77
|
-
if (varN) {
|
|
78
|
-
if (value) {
|
|
79
|
-
return varN.map(x => x).filter(dat => {
|
|
80
|
-
if (Array.isArray(dataFiltro.campoBuscar)) {
|
|
81
|
-
let encontrado = false;
|
|
82
|
-
|
|
83
|
-
for (const vCampo of dataFiltro.campoBuscar) {
|
|
84
|
-
// console.log(vCampo, value, dat[vCampo]);
|
|
85
|
-
if (isNaN(Number(value))) {
|
|
86
|
-
// NO ES NUMERO
|
|
87
|
-
if (value && dat[vCampo] && dat[vCampo].toLowerCase().includes(value?.toString().toLowerCase())) {
|
|
88
|
-
encontrado = true;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
if (value && dat[vCampo] && dat[vCampo].toString().includes(value?.toString())) {
|
|
94
|
-
encontrado = true;
|
|
95
|
-
break;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return encontrado;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
if (isNaN(Number(value))) {
|
|
103
|
-
return dat[dataFiltro.campoBuscar].toLowerCase().includes(value?.toString().toLowerCase());
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return dat[dataFiltro.campoBuscar].toString().includes(value?.toString());
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
return varN;
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
})
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export function changeSelect(control: any, formControl: AbstractControl, tipo: any, campoBuscar: any, campoFiltro = null) {
|
|
119
|
-
// console.log(formControl);
|
|
120
|
-
// const formGroup = formControl.parent.controls;
|
|
121
|
-
// console.warn( Object.keys(formGroup).find(name => formControl === formGroup[name]) || null );
|
|
122
|
-
if (!campoFiltro) {
|
|
123
|
-
campoFiltro = tipo;
|
|
124
|
-
}
|
|
125
|
-
control['filtrados'][campoFiltro ?? '__'] = formControl.valueChanges.pipe(untilDestroyed(control)).pipe(
|
|
126
|
-
startWith(''),
|
|
127
|
-
map(value => {
|
|
128
|
-
// console.warn(value);
|
|
129
|
-
|
|
130
|
-
const partes = tipo.split('.');
|
|
131
|
-
let varN;
|
|
132
|
-
if (control['dataServidor']) {
|
|
133
|
-
varN = (partes.length > 1) ? control['dataServidor'][partes[0]][partes[1]]:control['dataServidor'][tipo];
|
|
134
|
-
}
|
|
135
|
-
else if (control['dataServidorSuscripcion']) {
|
|
136
|
-
varN = control['dataServidorSuscripcion'][tipo].getValue();
|
|
137
|
-
}
|
|
138
|
-
if (varN) {
|
|
139
|
-
if (value) {
|
|
140
|
-
return varN.map((x: any) => x).filter((dat: any) => {
|
|
141
|
-
if (Array.isArray(campoBuscar)) {
|
|
142
|
-
let encontrado = false;
|
|
143
|
-
|
|
144
|
-
for (const vCampo of campoBuscar) {
|
|
145
|
-
// console.log(vCampo, value, dat[vCampo]);
|
|
146
|
-
if (isNaN(Number(value))) {
|
|
147
|
-
// NO ES NUMERO
|
|
148
|
-
if (value && dat[vCampo] && dat[vCampo].toLowerCase().includes(value?.toString().toLowerCase())) {
|
|
149
|
-
encontrado = true;
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
if (value && dat[vCampo] && dat[vCampo].toString().includes(value?.toString())) {
|
|
155
|
-
encontrado = true;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return encontrado;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
if (isNaN(Number(value))) {
|
|
164
|
-
return dat[campoBuscar].toLowerCase().includes(value?.toString().toLowerCase());
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
return dat[campoBuscar].toString().includes(value?.toString());
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
return varN;
|
|
173
|
-
}
|
|
174
|
-
return false;
|
|
175
|
-
})
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
export function changeSelectDataApi(objThis: any, dataFiltro: {
|
|
180
|
-
tipoReq: string,
|
|
181
|
-
campoId?: string,
|
|
182
|
-
minLength?: number,
|
|
183
|
-
dataExtra?: any,
|
|
184
|
-
dataExtraVariable?: any,
|
|
185
|
-
anonimo?: boolean,
|
|
186
|
-
queryService: any,
|
|
187
|
-
|
|
188
|
-
formControl: AbstractControl,
|
|
189
|
-
variableResultado?: string,
|
|
190
|
-
}) {
|
|
191
|
-
if (!dataFiltro.variableResultado) {
|
|
192
|
-
dataFiltro.variableResultado = dataFiltro.tipoReq;
|
|
193
|
-
}
|
|
194
|
-
const idFiltrado: string = dataFiltro.variableResultado;
|
|
195
|
-
dataFiltro.formControl.valueChanges.pipe(
|
|
196
|
-
debounceTime(500),
|
|
197
|
-
tap(() => {
|
|
198
|
-
objThis.filtrados[dataFiltro.variableResultado + 'tmp'] = isObservable(objThis.filtrados[idFiltrado]) ? []:objThis.filtrados[idFiltrado] || [];
|
|
199
|
-
if (objThis.filtrados[idFiltrado] !== objThis.filtrados[idFiltrado + 'tmp']) {
|
|
200
|
-
objThis.filtrados[idFiltrado] = [];
|
|
201
|
-
}
|
|
202
|
-
objThis.isLoading = true;
|
|
203
|
-
}),
|
|
204
|
-
switchMap(value => {
|
|
205
|
-
if (dataFiltro.campoId) {
|
|
206
|
-
const busquedaActual2 = objThis.filtrados[idFiltrado + 'tmp'].findIndex((item: any) => item[dataFiltro.campoId ?? '--'] === value);
|
|
207
|
-
if (busquedaActual2 >= 0) {
|
|
208
|
-
return of({[dataFiltro.tipoReq]: objThis.filtrados[idFiltrado + 'tmp']});
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
return !value || value.length < (dataFiltro.minLength ?? 3) ? []:(
|
|
212
|
-
dataFiltro.queryService.getDataMethod('GET', dataFiltro.tipoReq, {
|
|
213
|
-
...(dataFiltro.dataExtra ?? {}),
|
|
214
|
-
...(dataFiltro.dataExtraVariable ? Object.fromEntries(dataFiltro.dataExtraVariable.map((objData: any) => [objData.campo, objData.ctrlValue.value])):{}),
|
|
215
|
-
txtBuscar: value,
|
|
216
|
-
}, dataFiltro.anonimo).pipe(
|
|
217
|
-
finalize(() => objThis.isLoading = false),
|
|
218
|
-
)
|
|
219
|
-
);
|
|
220
|
-
})
|
|
221
|
-
).subscribe((data: any) => {
|
|
222
|
-
objThis.filtrados[idFiltrado] = data[dataFiltro.tipoReq] ?? [];
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export function changeSelectApi(control: any, queryService: any, formControl: AbstractControl, tipo: any, dataExtra = {}, dataExtraVariable: any[] | null = null, minLength = 1, anonimo = false) {
|
|
227
|
-
formControl.valueChanges.pipe(
|
|
228
|
-
debounceTime(500),
|
|
229
|
-
tap((value) => {
|
|
230
|
-
control['filtrados'][tipo + 'tmp'] = isObservable(control['filtrados'][tipo]) ? []:control['filtrados'][tipo];
|
|
231
|
-
if (control['filtrados'][tipo] != control['filtrados'][tipo + 'tmp']) {
|
|
232
|
-
control['filtrados'][tipo] = [];
|
|
233
|
-
}
|
|
234
|
-
control['isLoading'] = true;
|
|
235
|
-
}),
|
|
236
|
-
|
|
237
|
-
switchMap(value => {
|
|
238
|
-
const formGroup = <any>formControl.parent?.controls;
|
|
239
|
-
const nombreControl = Object.keys(formGroup).find(name => formControl === formGroup[name]) || null;
|
|
240
|
-
if (nombreControl && control['filtrados'][tipo + 'tmp'] && control['filtrados'][tipo + 'tmp'].length > 0) {
|
|
241
|
-
const busquedaActual = control['filtrados'][tipo + 'tmp'].findIndex((item: any) => item[nombreControl] == value);
|
|
242
|
-
if (busquedaActual >= 0) {
|
|
243
|
-
const vRet: any = {};
|
|
244
|
-
vRet[tipo] = control['filtrados'][tipo + 'tmp'];
|
|
245
|
-
control['isLoading'] = false;
|
|
246
|
-
return of(vRet);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
if (!value || value.length < minLength) {
|
|
250
|
-
return [];
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const dataExtraVariableData: any = {};
|
|
254
|
-
if (dataExtraVariable) {
|
|
255
|
-
// @ts-ignore
|
|
256
|
-
for (const objData of dataExtraVariable) {
|
|
257
|
-
dataExtraVariableData[objData.campo] = objData.ctrlValue.value;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return queryService.getDataMethod('GET', tipo, {...dataExtra, ...dataExtraVariableData, ...{txtBuscar: value}}, anonimo).pipe(
|
|
261
|
-
finalize(() => {
|
|
262
|
-
control['isLoading'] = false;
|
|
263
|
-
}),
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
})
|
|
267
|
-
).subscribe((data: any) => {
|
|
268
|
-
if (data[tipo] == undefined) {
|
|
269
|
-
control['filtrados'][tipo] = [];
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
control['filtrados'][tipo] = data[tipo];
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}
|
package/src/functions/number.ts
DELETED
|
@@ -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,243 +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
|
-
}
|
|
@@ -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
|
-
|
package/src/functions/string.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export function generateRandomString(length: number) {
|
|
2
|
-
let result = '';
|
|
3
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
4
|
-
const charactersLength = characters.length;
|
|
5
|
-
for (let i = 0; i < length; i++) {
|
|
6
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
7
|
-
}
|
|
8
|
-
return result;
|
|
9
|
-
}
|