Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added PROTOTIPO_ANALIZADOR_DE_TEXTO.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
801 changes: 28 additions & 773 deletions README.md

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions analyzer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const analyzer = {

getWordCount: (text) => { //cuenta el numero de palabras en el texto
if(!text) return 0; //verificamos si el texto está vacio, si está vacio da 0
return text.trim().split(/\s+/).length;
//text.trim elimina espacios del inicio y fin, con el .split(/\s+/) cuenta por espacios
},

getCharacterCount: (text) => { //cuenta el numero de caracteres en el texto
if(!text) return 0;
return text.length;//devuelve el número de caracteres
},


getCharacterCountExcludingSpaces: (text) => {
if(!text) return 0;
const signosDePuntuacion = [".", ",", ":", ";", "¿", "?", "¡", "!", "'"];
//creamos la constante con los signos de puntuacion correspondientes
let charCountExSpa = 0;
//creamos una variable que estará en 0
for (let i = 0; i < text.length; i++) {
//bucle para contar el indice desde 0 y si es menor que 0 ir sumando 1
const char = text[i]; // declara char y le da el valor de del caracter en la posicion i
if (!signosDePuntuacion.includes(char) && char !==' '){
// evalua que en la cadena no haya espacios ni los signos
charCountExSpa++;
}
}
return charCountExSpa;
},

getAverageWordLength: (text) => {
if(text) {
//si text es null o undefine luego de elminar espacios en blanco
const limpiaEspa = text.trim();
if(!limpiaEspa) return 0;
const words = limpiaEspa.split(/\s+/);
const totalWords = words.length;
//almacena el número total de palabras
const sumLengths = words.reduce ((sum,word) => sum + word.length, 0);
//suma las longitudes de todas las palabras
const averageLength = totalWords > 0 ? parseFloat ((sumLengths / totalWords).toFixed(2)) : 0;
//si totalWord es mayor a 0 se calcula la longitud promedio
return averageLength;
} else {
return 0;
}
},


getNumberCount: (text) => {
const todosLosNumeros = (/\b\d+(\.\d+)?\b/g); //BUSCAR LOS REGEX
//Define una expresión regular para encontrar todos los dígitos (del 0 al 9)
const numbers = text.match(todosLosNumeros);
//Buscar todos los dígitos que coincidan de la const todosLosNumeros
if (!numbers) return 0;
//sino hay numeros arroja 0

return numbers.length;

},


getNumberSum: (text) => {
const sumNum = (/\b\d+(\.\d+)?\b/g);
const number = text.match(sumNum);
if (!number) return 0;
const sum = number.reduce((acc, num) => acc + parseFloat(num, 10), 0); //NO ENTIENDO BIEN
//con reduce iteramos y toma el valor acumulado y el numero actual y se suma
//luego de convertirlo en un valor entero
return sum;

},
};

export default analyzer;
Binary file added fondo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Analizador de textos</title>
<link rel="stylesheet" href="style.css" />
</head>

<body>
<header>
<meta name="viewport" content="widt=device-width, initial-scale=1">
<h1>ANALIZADOR DE TEXTO</h1>
</header>

<div>
<h2>Te presentamos una herramienta para contar las metricas de textos, que te ayudará a saber la cantidad de palabras para establecer tus tarifas en traducciones</h2>

<textarea name="user-input" placeholder="Escribe tu texto aquí por favor"></textarea>

<ul class="lista">
<li class="metricas" data-testid="word-count" >PALABRAS: 0</li>
<li class="metricas" data-testid="character-count">CARACTERES: 0</li>
<li class="metricas" data-testid="character-no-spaces-count">CARACTERES SIN ESPACIOS: 0</li>
<li class="metricas" data-testid="number-count">NÚMEROS: 0</li>
<li class="metricas" data-testid="number-sum">SUMA DE NÚMEROS: 0</li>
<li class="metricas" data-testid="word-length-average">PROMEDIO DE LONGITUD: 0</li>
</ul>

<button type="button" id="reset-button">BORRAR</button>
</div>

<footer>
<p>MAYERLING HERNANDEZ</p>
</footer>

<script src="index.js" type="module"></script>

</body>
</html>
49 changes: 49 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import analyzer from './analyzer.js';

//TODO: escuchar eventos del DOM e invocar los métodos del objeto `analyzer`

const textarea = document.querySelector("textarea"); //busco el elemento testarea
const palabras = document.querySelector('li[data-testid="word-count"]');
const caracteres = document.querySelector('li[data-testid="character-count"]');
const caracteresSinEspacios = document.querySelector('li[data-testid="character-no-spaces-count"]');
const numeros = document.querySelector('li[data-testid="number-count"]');
const suma = document.querySelector('li[data-testid="number-sum"]');
const longitud = document.querySelector('li[data-testid="word-length-average"]');
const resetButton = document.getElementById('reset-button'); //busco el elemento id reset-button

textarea.addEventListener("input", () => { // escucha el input cada que se escribeconst text = textarea.value; //declaramos la constante y obtiene el contenido act del cuadro de texto
const text = textarea.value;

const wordCount = analyzer.getWordCount(text); //llama a una funcion para contar el numero de palabras
palabras.textContent = `PALABRAS: ${wordCount}`; //crea cadena de texto con el numero de palabras

const characterCount = analyzer.getCharacterCount(text);//llama a una funcion para contar el numero de caracteres
caracteres.textContent = `CARACTERES: ${characterCount}`;//crea cadena de texto con el numero de caracteres

const characterCountExcludingSpaces = analyzer.getCharacterCountExcludingSpaces(text);//llama a una funcion para contar el numero de palabras sin epacios ni signos de puntuacion
caracteresSinEspacios.textContent = `CARACTERES SIN ESPACIOS: ${characterCountExcludingSpaces}`;//crea cadena de texto con el numero de palabras sin espacios ni signos de puntuacion

const averageWordLength = analyzer.getAverageWordLength(text);//llama a una funcion para contar la longitud de palabras
longitud.textContent = `LONGITUD: ${averageWordLength}`;//crea cadena de texto con la longitud de palabras

const numberCount = analyzer.getNumberCount(text);//llama a una funcion para contar los números
numeros.textContent = `NUMEROS: ${numberCount}`;//crea cadena de texto con la cantidad de números

const numberSum = analyzer.getNumberSum(text);//llama a una funcion para sumar los números
suma.textContent = `SUMA: ${numberSum}`; // //crea cadena de texto con la suma de números


});



resetButton.addEventListener('click', () => { // cuando se haga click se ejecutara la lista de funciones
textarea.value = ''; //borrará lo escrito en el textarea
palabras.textContent="PALABRAS: 0";
caracteres.textContent="CARACTERES: 0";
caracteresSinEspacios.textContent = "CARACTERES SIN ESPACIOS: 0";
longitud.textContent = "LONGITUD: 0";
numeros.textContent = "NÚMEROS: 0";
suma.textContent = "SUMA: 0";
//dejará los númeos a 0 de cada una de la lista
})
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"eslint": "^8.3.0",
"gh-pages": "^3.1.0",
"htmlhint": "^1.0.0",
"jest": "^27.0.1",
"jest": "^27.5.1",
"jsdom": "^21.1.1",
"opener": "^1.5.1",
"serve": "^13.0.2"
Expand All @@ -42,4 +42,4 @@
"version": "8.4.0",
"commit": "d5b8aec07b9436348c5e1eb156926b50f8ab795f"
}
}
}
24 changes: 0 additions & 24 deletions src/analyzer.js

This file was deleted.

33 changes: 0 additions & 33 deletions src/index.html

This file was deleted.

19 changes: 0 additions & 19 deletions src/index.js

This file was deleted.

27 changes: 0 additions & 27 deletions src/style.css

This file was deleted.

Loading