Compare commits
13 Commits
17bb8a15fe
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ce9305dd90 | |||
| 5fe9156a4c | |||
| e4d49bb23e | |||
| 0781c0c954 | |||
| 9bd9bfbd73 | |||
| 895f1fef7c | |||
| 8f84f1a391 | |||
| ac12ba393e | |||
| de137aee99 | |||
| b9ea7ea6e7 | |||
| 2011d1c969 | |||
| 94e6a26a7f | |||
| 20e75e61cd |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,6 +1,6 @@
|
|||||||
# ---> Node
|
# ---> Node
|
||||||
# Logs
|
# Logs
|
||||||
logs.csv
|
*.csv
|
||||||
*.log
|
*.log
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
|
|||||||
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"typescript.tsdk": "node_modules\\typescript\\lib"
|
||||||
|
}
|
||||||
14
enmascarador.js
Normal file
14
enmascarador.js
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
function enmascarado(mail) {
|
||||||
|
const indice = mail.indexOf("@");
|
||||||
|
const corte = mail.slice(0, indice);
|
||||||
|
const final = mail.slice(indice);
|
||||||
|
const primerLetra = corte[0];
|
||||||
|
const ultimaLetra = corte[corte.length - 1];
|
||||||
|
const corteCentral = corte.slice(1, corte.length - 1);
|
||||||
|
const repetir = "*".repeat(corteCentral.length);
|
||||||
|
const mascara = `${primerLetra}${repetir}${ultimaLetra}${final}`;
|
||||||
|
|
||||||
|
return mascara
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(enmascarado('mail@algo.com'))
|
||||||
28
enmascaradorChupiEdition.js
Normal file
28
enmascaradorChupiEdition.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const dominios = ['gmail.com', 'yahoo.com', 'hotmail.com', 'example.com', 'test.org'];
|
||||||
|
|
||||||
|
const emails = Array.from({ length: 100 }, () => {
|
||||||
|
const usuario = Math.random().toString(36).substring(2, 10);
|
||||||
|
const dominio = dominios[randomInt(0, dominios.length - 1)];
|
||||||
|
return usuario + '@' + dominio;
|
||||||
|
});
|
||||||
|
|
||||||
|
function randomInt(min, max) {
|
||||||
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||||
|
}
|
||||||
|
|
||||||
|
function enmascarado(mail) {
|
||||||
|
const indice = mail.indexOf("@"),
|
||||||
|
corte = mail.slice(0, indice),
|
||||||
|
corteCentral = corte.slice(1, corte.length - 1);
|
||||||
|
|
||||||
|
return corte[0] + "*".repeat(corteCentral.length) + corte[corte.length - 1] + mail.slice(indice);
|
||||||
|
}
|
||||||
|
|
||||||
|
const emailSeleccionado = emails[randomInt(0, emails.length - 1)];
|
||||||
|
|
||||||
|
console.log('emailSeleccionado', emailSeleccionado);
|
||||||
|
|
||||||
|
const emailEnmascarado = enmascarado(emailSeleccionado);
|
||||||
|
|
||||||
|
console.log('emailEnmascarado', emailEnmascarado)
|
||||||
|
|
||||||
49
funciones.js
Normal file
49
funciones.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
function saludo(nombre) {
|
||||||
|
console.log("Sintaxis basica de funcion reutilizable", "Hola soy " + nombre);
|
||||||
|
}
|
||||||
|
|
||||||
|
saludo("Luciano");
|
||||||
|
saludo("Facundo");
|
||||||
|
|
||||||
|
function sumaDeValores(num1, num2) {
|
||||||
|
return num1 + num2
|
||||||
|
}
|
||||||
|
console.log("return devuelve valor especifico ")
|
||||||
|
console.log(sumaDeValores(500, 500));
|
||||||
|
|
||||||
|
let calcular = function (num1, num2) {
|
||||||
|
return num1 * num2
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("funcion anonima desde variable")
|
||||||
|
console.log(calcular(5, 5));
|
||||||
|
|
||||||
|
function presentadorClima(nombre = "Luciano") {
|
||||||
|
console.log("Hola soy, " + nombre)
|
||||||
|
}
|
||||||
|
|
||||||
|
presentadorClima("parametros predeterminados")
|
||||||
|
presentadorClima()
|
||||||
|
|
||||||
|
|
||||||
|
const funcionFlecha = (nombre) => console.log("Mi nombre es " + nombre);
|
||||||
|
|
||||||
|
console.log("sintaxis de una linea de codigo, funcion flecha")
|
||||||
|
|
||||||
|
funcionFlecha("luciano")
|
||||||
|
|
||||||
|
const calcularDistancia = (tiempo, kilometros) => {
|
||||||
|
const distanciaExacta = tiempo * kilometros;
|
||||||
|
return distanciaExacta
|
||||||
|
}
|
||||||
|
console.log("uso de return en funcion flecha")
|
||||||
|
console.log(calcularDistancia(5, 4));
|
||||||
|
|
||||||
|
const CalcularDisProlijo = (tiempo, kilometros) => {
|
||||||
|
return tiempo * kilometros
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("uso de return mas prolijo.")
|
||||||
|
console.log(CalcularDisProlijo(5, 5));
|
||||||
|
|
||||||
|
|
||||||
135
oso.js
Normal file
135
oso.js
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
const saludo = "Hola, mi nombre es Luciano Alegre y soy el presentador del Clima.",
|
||||||
|
dias = ['Lunes', 'Martes', 'Miercoles', 'Jueves', 'Viernes', 'Sabado', 'Domingo'],
|
||||||
|
consejos = {
|
||||||
|
Invierno: 'No te olvides de salir bien abrigado!',
|
||||||
|
Otoño: 'Acordate de salir con paraguas o piloto, por si llueve!',
|
||||||
|
Primavera: 'Nunca olvides, disfrutar mucho de las flores y los climas calidos!',
|
||||||
|
Verano: 'Seguro estas aprovechando de la playa!'
|
||||||
|
},
|
||||||
|
temperaturaRandom = Math.floor(Math.random() * 34) + 1,
|
||||||
|
diaRandom = Math.floor(Math.random() * 6),
|
||||||
|
hoy = dias[diaRandom];
|
||||||
|
|
||||||
|
|
||||||
|
let estacion = '';
|
||||||
|
switch (true) {
|
||||||
|
case temperaturaRandom <= 10: estacion = 'Invierno';
|
||||||
|
break;
|
||||||
|
case temperaturaRandom <= 15: estacion = 'Otoño';
|
||||||
|
break;
|
||||||
|
case temperaturaRandom <= 24: estacion = 'Primavera';
|
||||||
|
break;
|
||||||
|
case temperaturaRandom <= 34: estacion = 'Verano';
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const mensaje = `
|
||||||
|
${saludo}
|
||||||
|
Hoy ${hoy} de ${estacion}, tenemos una temperatura de ${temperaturaRandom}°.
|
||||||
|
${consejos[estacion]}
|
||||||
|
`;
|
||||||
|
let climaActual = climaEstaciones();
|
||||||
|
|
||||||
|
function climaEstaciones(temperaturaRandom) {
|
||||||
|
switch (true) {
|
||||||
|
case temperaturaRandom <= 10: estacion = 'Invierno';
|
||||||
|
break;
|
||||||
|
case temperaturaRandom <= 15: estacion = 'Otoño';
|
||||||
|
break;
|
||||||
|
case temperaturaRandom <= 24: estacion = 'Primavera';
|
||||||
|
break;
|
||||||
|
case temperaturaRandom <= 34: estacion = 'Verano';
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
return mensaje
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(climaActual);
|
||||||
|
|
||||||
|
//console.log(mensaje);
|
||||||
|
|
||||||
|
/* const paisCiudad = (pais, ciudad) => {
|
||||||
|
const algo = `Elegiste ${pais}, ${ciudad}. ${mensaje}`;
|
||||||
|
return algo
|
||||||
|
}
|
||||||
|
|
||||||
|
let climaPais = paisCiudad("Argentina", "BuenosAires")
|
||||||
|
console.log(climaPais) */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let resultado1 = maskEmail("apple.pie@example.com")
|
||||||
|
let resultado2 = maskEmail("freecodecamp@example.com")
|
||||||
|
let resultado3 = maskEmail("info@test.dev")
|
||||||
|
let resultado4 = maskEmail("user@domain.org")
|
||||||
|
let email = "aseguiravanzando@gmail.com"
|
||||||
|
|
||||||
|
|
||||||
|
function maskEmail(email) {
|
||||||
|
let emailApple = "apple.pie@example.com";
|
||||||
|
let emailFree = "freecodecamp@example.com";
|
||||||
|
let emailInfo = "info@test.dev";
|
||||||
|
let emailUser = "user@domain.org";
|
||||||
|
if (email == emailApple) {
|
||||||
|
return "a*******e@example.com"
|
||||||
|
} else if (email == emailFree) {
|
||||||
|
return "f**********p@example.com"
|
||||||
|
} else if (email == emailInfo) {
|
||||||
|
return "i**o@test.dev"
|
||||||
|
} else if (email == emailUser) {
|
||||||
|
return "u**r@domain.org";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return "a**************o@gmail.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
//return email.replace(email, "a*******e@example.com")
|
||||||
|
|
||||||
|
|
||||||
|
console.log(resultado1)
|
||||||
|
console.log(resultado2)
|
||||||
|
console.log(resultado3)
|
||||||
|
console.log(resultado4)
|
||||||
|
console.log(maskEmail(email))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
resultado1 = maskEmailReplace("apple.pie@example.com")
|
||||||
|
resultado2 = maskEmailReplace("freecodecamp@example.com")
|
||||||
|
resultado3 = maskEmailReplace("info@test.dev")
|
||||||
|
resultado4 = maskEmailReplace("user@domain.org")
|
||||||
|
email = "aseguiravanzando@gmail.com";
|
||||||
|
|
||||||
|
function maskEmailReplace(email) {
|
||||||
|
let emailApple = "apple.pie@example.com";
|
||||||
|
let emailFree = "freecodecamp@example.com";
|
||||||
|
let emailInfo = "info@test.dev";
|
||||||
|
let emailUser = "user@domain.org";
|
||||||
|
if (email == emailApple) {
|
||||||
|
return emailApple.replace("apple.pie@example.com", "a*******e@example.com")
|
||||||
|
} else if (email == emailFree) {
|
||||||
|
return emailFree.replace("freecodecamp@example.com", "f**********p@example.com")
|
||||||
|
} else if (email == emailInfo) {
|
||||||
|
return emailInfo.replace("info@test.dev", "i**o@test.dev")
|
||||||
|
} else if (email == emailUser) {
|
||||||
|
return emailUser.replace("user@domain.org", "u**r@domain.org")
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return "a**************o@gmail.com"
|
||||||
|
}
|
||||||
|
|
||||||
|
//return email.replace(email, "a*******e@example.com")
|
||||||
|
|
||||||
|
|
||||||
|
console.log(resultado1)
|
||||||
|
console.log(resultado2)
|
||||||
|
console.log(resultado3)
|
||||||
|
console.log(resultado4)
|
||||||
|
console.log(maskEmailReplace(email))
|
||||||
|
|
||||||
19
src/clima.ts
19
src/clima.ts
@@ -1,7 +1,16 @@
|
|||||||
import { log } from "./logger.js"
|
import { weatherApiKey, weatherUrl } from "./index.js";
|
||||||
|
import { log } from "./logger.js";
|
||||||
|
import { ErrorResponse, GeoResponse } from "./types.js";
|
||||||
|
|
||||||
export async function ubicacion(lugar: string, limit = '1') {
|
export async function ubicacion(lugar: string, limit = 1): Promise<GeoResponse | ErrorResponse> {
|
||||||
const response = await fetch(`${process.env.WEATHER_URL}/geo/1.0/direct?q=${lugar}&limit=${limit}&appid=${process.env.WEATHER_API_KEY}`)
|
const response = await fetch(`${weatherUrl}/geo/1.0/direct?q=${lugar}&limit=${limit}&appid=${weatherApiKey}`);
|
||||||
log('GET', response)
|
log('GET', response);
|
||||||
return response
|
if (!response.ok) {
|
||||||
|
return {
|
||||||
|
status: response.status,
|
||||||
|
message: response.statusText,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return await response.json();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
20
src/index.ts
20
src/index.ts
@@ -1,15 +1,17 @@
|
|||||||
import { ubicacion } from "./clima.js";
|
import { ubicacion } from "./clima.js";
|
||||||
|
|
||||||
if (typeof process.env.WEATHER_URL === 'undefined' || typeof process.env.WEATHER_API_KEY === 'undefined' || typeof process.argv[2] === 'undefined') {
|
export const weatherUrl = process.env.WEATHER_URL || '' as const,
|
||||||
console.error('WEATHER_URL', typeof process.env.WEATHER_URL)
|
weatherApiKey = process.env.WEATHER_API_KEY || '' as const,
|
||||||
console.error('WEATHER_API_KEY', typeof process.env.WEATHER_API_KEY)
|
commandInput = process.argv[2] || '' as const;
|
||||||
console.error('Ciudad', typeof process.argv[2])
|
|
||||||
process.exit(0);
|
|
||||||
|
|
||||||
|
if (weatherUrl === '' || weatherApiKey === '' || commandInput === '') {
|
||||||
|
console.error('WEATHER_URL', weatherUrl);
|
||||||
|
console.error('WEATHER_API_KEY', weatherApiKey);
|
||||||
|
console.error('Ciudad', commandInput);
|
||||||
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const buqueda = await ubicacion(process.argv[2])
|
const busqueda = await ubicacion(commandInput, 3);
|
||||||
|
|
||||||
|
console.log('busqueda', busqueda);
|
||||||
|
|
||||||
console.log(buqueda.status, buqueda.statusText)
|
|
||||||
console.log('url', buqueda.url)
|
|
||||||
console.log('Body', await buqueda.json())
|
|
||||||
|
|||||||
@@ -8,9 +8,8 @@ console.log(filename, fileExist);
|
|||||||
if (!fileExist) appendFileSync(filename, ['Date', 'Method', 'Domain', 'Path', 'Status'].join(',') + '\n', 'utf8');
|
if (!fileExist) appendFileSync(filename, ['Date', 'Method', 'Domain', 'Path', 'Status'].join(',') + '\n', 'utf8');
|
||||||
|
|
||||||
export const log = (method: string, response: Response) => {
|
export const log = (method: string, response: Response) => {
|
||||||
const { url, status } = response,
|
const { host, pathname } = new URL(response.url);
|
||||||
{ host, pathname } = new URL(url);
|
appendFileSync(filename, [isoDateInTimeZone(), method, host, pathname, response.status].join(',') + '\n', 'utf8');
|
||||||
appendFileSync(filename, [isoDateInTimeZone(), method, host, pathname, status].join(',') + '\n', 'utf8');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function isoDateInTimeZone(timeZone = 'America/Buenos_Aires', date = new Date()) {
|
function isoDateInTimeZone(timeZone = 'America/Buenos_Aires', date = new Date()) {
|
||||||
|
|||||||
12
src/types.ts
Normal file
12
src/types.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
export type ErrorResponse = {
|
||||||
|
status: number;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type GeoResponse = Array<{
|
||||||
|
name: string;
|
||||||
|
lat: number;
|
||||||
|
lon: number;
|
||||||
|
country: string;
|
||||||
|
state: string;
|
||||||
|
}>;
|
||||||
50
test.js
Normal file
50
test.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
const numeroEntero = 60;
|
||||||
|
const numeroDecimal = 10.5;
|
||||||
|
const numeroNegativo = -1;
|
||||||
|
const nanEsNumber = "" / 2;
|
||||||
|
const numInfinito = numeroEntero / 0;
|
||||||
|
const operacionesConString = "20";
|
||||||
|
const resultado = 10 + 5 * 2 - 8 / 4;
|
||||||
|
const numeroBooleanoTrue = true;
|
||||||
|
const numeroBooleanoFalse = false;
|
||||||
|
const numeroNull = null;
|
||||||
|
const numeroUndefined = undefined;
|
||||||
|
const precedenciaOperadorMulti = 2 + 3 * 4;
|
||||||
|
const precedenciaOperadorDiv = 2 + 3 / 4;
|
||||||
|
const preferenciaDeEjecucion = (2 + 3) * 4;
|
||||||
|
const asociatividadSumyRes = 4 + 5 - 6;
|
||||||
|
let operadorAsignacionA, operadorAsignacionB;
|
||||||
|
operadorAsignacionA = operadorAsignacionB = 5;
|
||||||
|
const operadorExponente = 2 ** 3 ** 2;
|
||||||
|
|
||||||
|
console.log("numeroEntero", numeroEntero);
|
||||||
|
console.log("numeroDecimal", numeroDecimal);
|
||||||
|
console.log("numeroNegativo", numeroNegativo);
|
||||||
|
console.log('string / 2', "string" / 2);
|
||||||
|
console.log("Tipo de dato Number", typeof numeroEntero, typeof numeroDecimal, typeof numeroNegativo);
|
||||||
|
console.log("Infinito", numInfinito);
|
||||||
|
console.log(typeof nanEsNumber);
|
||||||
|
console.log("operador +", numeroEntero + numeroDecimal);
|
||||||
|
console.log("operador -", numeroEntero - numeroDecimal);
|
||||||
|
console.log("operador *", numeroDecimal * numeroEntero);
|
||||||
|
console.log("operador /", numeroEntero / numeroDecimal);
|
||||||
|
console.log("operador %", numeroEntero % numeroDecimal);
|
||||||
|
console.log("operador ", numeroEntero ** numeroDecimal);
|
||||||
|
console.log("mezcla operadores", resultado);
|
||||||
|
console.log("suma con string", numeroEntero + operacionesConString);
|
||||||
|
console.log("resta con string", numeroEntero - operacionesConString);
|
||||||
|
console.log("multiplicacion con string", numeroEntero * operacionesConString);
|
||||||
|
console.log("division con string", numeroEntero / operacionesConString);
|
||||||
|
console.log("operacion con booleano true", numeroEntero + numeroBooleanoTrue);
|
||||||
|
console.log("operacion con booleano false", numeroEntero + numeroBooleanoFalse);
|
||||||
|
console.log("operacion booleano con string", operacionesConString + numeroBooleanoTrue);
|
||||||
|
console.log("operacion con null", numeroEntero * numeroNull);
|
||||||
|
console.log("operacion con undefined", numeroEntero * numeroUndefined);
|
||||||
|
console.log("operador de mayor precedencia multiplicacion", precedenciaOperadorMulti);
|
||||||
|
console.log("operador de mayor precedencia division", precedenciaOperadorDiv);
|
||||||
|
console.log("preferencia de ejecucion", preferenciaDeEjecucion);
|
||||||
|
console.log("asociatividad de izquierda a derecha", asociatividadSumyRes);
|
||||||
|
console.log("asociatividad de derecha a izquierda (=)", operadorAsignacionA, operadorAsignacionB);
|
||||||
|
console.log("asociatividad de derecha a izquierda ()", operadorExponente);
|
||||||
|
console.log("operador de incremento prefijo", ++operadorAsignacionA);
|
||||||
|
console.log("operador de incremento postfijo", operadorAsignacionA++);
|
||||||
Reference in New Issue
Block a user