UNPKG

@victorequena22/utiles

Version:

Utilidades para mi uso que pongo a dispocion

77 lines (76 loc) 2.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.actualizarLista = exports.indexOfCallback = exports.filtro = exports.ordenar = exports.busqueda = void 0; const Comparaciones_1 = require("./Comparaciones"); const Formatos_1 = require("./Formatos"); function busqueda(itens, encontar, bucarLabel, fechas = []) { if (encontar !== "") { return itens.filter(iten => { let en = encontar.toUpperCase().split(" "), pasa = false; bucarLabel.forEach(label => { let considencias = 0; en.forEach(e => { if (fechas.some(f => f === label)) { if ((0, Comparaciones_1.buscarTexto)((0, Formatos_1.formatoFecha)(iten[label]), e)) considencias++; } else if (isNaN(iten[label])) { if ((0, Comparaciones_1.buscarTexto)(iten[label], e)) considencias++; } else { if ((0, Comparaciones_1.buscarTexto)((0, Formatos_1.zfill)(parseFloat(iten[label])), e)) considencias++; } }); if (en.length === considencias) { pasa = true; } }); return pasa; }); } return itens; } exports.busqueda = busqueda; function ordenar(itens, by, orden, fechas = []) { return itens.sort((a, b) => { if (fechas.some(f => f === by)) return (0, Comparaciones_1.ordenFecha)(a[by], b[by], orden); else if (isNaN(b[by])) return (0, Comparaciones_1.ordenString)(a[by], b[by], orden); else return (0, Comparaciones_1.ordenNumero)(a[by], b[by], orden); }); } exports.ordenar = ordenar; function filtro(itens, value, Label) { if (value !== -1) return itens.filter(iten => { return iten[Label] === value; }); return itens; } exports.filtro = filtro; function indexOfCallback(arr, callback, startIndex = 0) { for (let i = startIndex; i < arr.length; i++) { if (callback(arr[i])) { return i; } } return -1; } exports.indexOfCallback = indexOfCallback; function actualizarLista(nuevo, lista, label) { const push = nuevo.filter((d => { const i = lista.findIndex(c => c[label] === d[label]); if (i > -1) { lista[i] = d; return false; } return true; })); const arr = [...lista, ...push]; return arr; } exports.actualizarLista = actualizarLista;