Last active
February 1, 2024 19:49
-
-
Save kockono/2c9c2d432fee60352ed18ec40f67d020 to your computer and use it in GitHub Desktop.
JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.charAt(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.slice(index, 10); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Busqueda de productos por nombre */ | |
buscarProductos(producto: string) { | |
if( producto === '' ) { return this.productos = this.originalStateProductos } | |
this.productos = this.productos.filter( ( p:any ) => this.eliminarAcentos( p.nombre.toLowerCase()).includes( producto.toLowerCase())); | |
} | |
eliminarAcentos(palabra:string) { | |
return palabra.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isImage(url) { | |
return /\.(jpg|jpeg|png|webp|avif|gif|svg)$/.test(url); | |
} | |
// 👇️ true | |
console.log(isImage('https://example.com/photo.jpg')); | |
// 👇️ true | |
console.log(isImage('https://example.com/photo.webp')); | |
// 👇️ false | |
console.log(isImage('https://example.com/index.html')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Chris Cobos | |
* @version 1.0.0 | |
* | |
* Evalua si las propiedades son: false, 0, null, undefined, NaN y "" (string vacio). | |
* --------------------------------------------- CASOS DE USO --------------------------------------------------------- | |
* 1. Forzar al usuario a insertar todos los datos requeridos | |
* 2. Valida que los datos no vayan a llegar vacios al backend | |
* | |
* ----------------------------------------- METODOS ----------------------------------------------------------------------------- | |
* @function {@link_validateFields(simpleForm)} - Validador de campos vacios que recibe como parametro un objeto | |
* @argument simpleForm - Objeto o formulario a validar | |
* | |
* ----------------------------------------- VARIABLES --------------------------------------------------------------------------- | |
* @var isEmptyProperty - Define si la propiedad no esta vacia | |
* @return {boolean} - Retorna true o false dependiendo si el valor esta vacio o no | |
*/ | |
export const validateFields = (simpleForm) => { | |
const isEmptyProperty = Object.values(simpleForm).every(value => { | |
if (!value) { | |
return true | |
} | |
return false | |
}) | |
return isEmptyProperty | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @openapi | |
* info: | |
* title: Sample API | |
* description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML. | |
* version: 0.1.9 | |
* | |
* paths: | |
* /users: | |
* post: | |
* tags: | |
* - Login | |
* summary: Returns a list of users. | |
* description: Optional extended description in CommonMark or HTML. | |
* responses: | |
* '200': # status code | |
* description: A JSON array of user names | |
* content: | |
* application/json: | |
* schema: | |
* type: array | |
* items: | |
* type: string | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let gruopProducts = productsToGroup.reduce((results:any, org:any) => { | |
(results[org.idPedido] = results[org.idPedido] || []).push(org); | |
return results; | |
}, {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Chris Cobos | |
* @version 1.0.0 | |
* -------------------------------- CASOS DE USO DE ANALISIS DE GRAFICAS --------------------------------------------------------- | |
* 1. El campo viene vacio | |
* | |
* ----------------------------------------- METODOS ----------------------------------------------------------------------------- | |
* @function {@link_name()} | |
* | |
* ----------------------------------------- VARIABLES --------------------------------------------------------------------------- | |
* @var loading - En el momento que reciba la información de analisisGraficasService.getValoraciones() se cambiara a true | |
* haciendo así que aparezcan las graficas con la directiva ng-If. | |
* ------------------------------------------- PARAMS --------------------------------------------------------------------------- | |
* @param {any} name | |
* | |
* ----------------------------------------- ARGUMENTOS --------------------------------------------------------------------------- | |
* @argument {number} name ↓ | |
* ---------- Objetos----- | |
* @var Schema.Types.ObjectId - Esto le dice a mongoose que hara una refererencia a una id de un schema | |
* @return {string} Return a string | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Chris Cobos | |
* @version 1.0.0 | |
* @description - Obtiene el elemento guardado en el local storage y lo parsea | |
* | |
* @param {string} itemName - Dato a buscar del local storage | |
* @var {string} item - Variable con los datos parseado | |
* @return {item} - El item ya parseado del dato buscado | |
* | |
* @function {@link_getItemsLocalStorage} - Metodo para obtención del dato parseado | |
*/ | |
export function getItemsLocalStorage(itemName:string) { | |
const item:string = localStorage.getItem(itemName) || ""; | |
return JSON.parse(item); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Permite obtener lo nombres de un objeto de objetos | |
for(let item in resp) { | |
console.log(item) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let promedio = this.numeros.map(r => promedio += r.numero )[this.numeros.length -1] / numeros.length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Dentro recibe un callback de donde se va ejecutar, contien un resolve y reject | |
* @param resolve - Cuando la promesa se haya resuelto | |
* @param reject - Cuando la promesa no se logro | |
*/ | |
new Promise( (resolve , reject) => { | |
console.log( 'Cuerpo de la promesa' ) | |
resolve() | |
if(error) { reject() } | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numero = Math.floor(Math.random() * (max - min + 1) + min) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const miLista: ReadonlyArray<string> = ["a", "b", "c"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uniqueIds = new Set(); | |
const unique = fotosMarcas.filter((element:any) => { | |
const isDuplicate = uniqueIds.has(element.idTipo); | |
uniqueIds.add(element.idTipo); | |
if (!isDuplicate) { | |
return true; | |
} | |
return false; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Permite tomar los nombres de los objetos y guardarlos en una nueva propiedad | |
let arrayOfObjects = Object.keys(resp).map(key => { | |
let newObject = resp[key] | |
newObject.id = key | |
return newObject | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.shift() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortNumbers(nums: number[]): number[] { | |
let aux = 0; | |
for (let i = 0; i < nums.length; i++) { | |
for (let j = 0; j < nums.length; j++) { | |
if(nums[i] < nums[j] ){ | |
aux = nums[i]; | |
nums[i] = nums[j]; | |
nums[j] = aux; | |
} | |
} | |
} | |
return nums | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.splice(i, 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const array1 = [1, 2, 3, 4]; | |
// 0 + 1 + 2 + 3 + 4 | |
const initialValue = 0; | |
const sumWithInitial = array1.reduce( | |
(previousValue, currentValue) => previousValue + currentValue, | |
initialValue | |
); | |
console.log(sumWithInitial); | |
// expected output: 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let today = new Date().toISOString().slice(0, 10); // "31-08-2022" | |
let today = new Date().toLocaleDateString(); // "31/8/2022" | |
let today = new Date().toLocaleString(); // "21/11/2016, 08:00:00 AM" | |
let fecha = new Date(); // "2022-08-31 10:52:42" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arreglo.unshift(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uniqueId = (length=16) => { | |
return parseInt(Math.ceil(Math.random() * Date.now()).toPrecision(length).toString().replace(".", "")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment