diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..705c19e --- /dev/null +++ b/LICENSE @@ -0,0 +1,18 @@ +MIT License + +Copyright (c) 2025 Drk0027 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and +associated documentation files (the "Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the +following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial +portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT +LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO +EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e35abae --- /dev/null +++ b/README.md @@ -0,0 +1,55 @@ +# Word Clock Javascript + +Este ejercicio didactico busca aprender a crear un modulo para nodejs y a utilizar la documentacion generada por JSDocs y los test Mocha. + +--- + +## 🚀 Tabla de Contenidos +- 🚀 Descripción +- ✨ Características +- ⚙️ Instalación +- 💡 Uso +- 🔧 Tecnologías +- 📄 Licencia + +--- + +## 🚀 Descripción +Este coodigo pretende explicar como funcionan los modulos para nodejs y la implementacion de test de Mocha. + + +## ✨ Características +* Ejecucion en el terminal de NodeJS +* Cambio entre tres idiomas +* Documentacion mediante JSDocs +* Test mediante Mocha + +## ⚙️ Instalación +1. Clona el repositorio: + ```bash + git clone https://git.interlan.ec/Drk0027/Word-Clock-Javascript.git + ``` +2. Navega al directorio: + ```bash + cd Word-Clock-Javascript + ``` +3. Instala las dependencias: + ```bash + npm install + ``` + +## 💡 Uso +**Ejemplo Básico:** +```bash +npm run run #Ejecuta en idioma inglés +npm run run_eo #Ejecuta en idioma esperanto +npm run run_es #Ejecuta en idioma español +npm run test #Ejecuta test mocha +``` + +# 🔧 Tecnologías Usadas + + Lenguaje: JavaScript (Node.js) + +# 📄 Licencia +Este proyecto está bajo la licencia MIT. \ No newline at end of file diff --git a/index.js b/index.js index 6cf46b8..784cb45 100755 --- a/index.js +++ b/index.js @@ -6,198 +6,198 @@ var display = [ { palabra: "It", estado: 1, - id:"it" + id: "it" }, { palabra: " ", estado: 1, - id:"" + id: "" }, { palabra: "is", estado: 1, - id:"is" + id: "is" }, { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: "twenty", estado: 0, - id:"m_20" + id: "m_20" } ], [ { palabra: "quarter", estado: 0, - id:"m_15" + id: "m_15" }, { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: "half", estado: 0, - id:"m_30" + id: "m_30" } ], [ { palabra: "ten", estado: 0, - id:"m_10" + id: "m_10" }, { palabra: "five", estado: 0, - id:"m_5" + id: "m_5" }, { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: "past", estado: 0, - id:"past" + id: "past" } ], [ { palabra: "to", estado: 0, - id:"to" + id: "to" }, { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: "twelve", estado: 0, - id:"h_0" + id: "h_0" }, { palabra: "one", estado: 0, - id:"h_1" + id: "h_1" } ], [ { palabra: "two", estado: 0, - id:"h_2" + id: "h_2" }, { palabra: "three", estado: 0, - id:"h_3" + id: "h_3" }, { palabra: "four", estado: 0, - id:"h_4" + id: "h_4" } ], [ { palabra: "five", estado: 0, - id:"h_5" + id: "h_5" }, { palabra: "six", estado: 0, - id:"h_6" + id: "h_6" }, { palabra: "seven", estado: 0, - id:"h_7" + id: "h_7" } ], [ { palabra: "eight", estado: 0, - id:"h_8" + id: "h_8" }, { palabra: "nine", estado: 0, - id:"h_9" + id: "h_9" }, { palabra: "ten", estado: 0, - id:"h_10" + id: "h_10" } ], [ { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: "eleven", estado: 0, - id:"h_11" + id: "h_11" }, { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: " ", estado: 0, - id:"" + id: "" } ], [ { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: "O'Clock", estado: 0, - id:"m_0" + id: "m_0" }, { palabra: " ", estado: 0, - id:"" + id: "" }, { palabra: "now", estado: 1, - id:"now" + id: "now" } ], ] @@ -209,13 +209,13 @@ console.log(chalk.greenBright("---WordClock---")) * Reinicia el display a sus valores por defecto * */ -function resetDisplay(){ - display.map(fila=>{ - fila.map(columna=>{ - if(columna.id=="it"||columna.id=="is"||columna.id=="now"){ - display[display.indexOf(fila)][fila.indexOf(columna)].estado=1 - }else{ - display[display.indexOf(fila)][fila.indexOf(columna)].estado=0 +function resetDisplay() { + display.map(fila => { + fila.map(columna => { + if (columna.id == "it" || columna.id == "is" || columna.id == "now") { + display[display.indexOf(fila)][fila.indexOf(columna)].estado = 1 + } else { + display[display.indexOf(fila)][fila.indexOf(columna)].estado = 0 } }) }) @@ -233,7 +233,7 @@ function actualizar_display() { //evaluar si la columna tiene un estado activo o inactivo y guardar el estado if (columna.estado == 0) { show.push(chalk.gray(columna.palabra)) - }else{ + } else { show.push(chalk.yellowBright(columna.palabra)) } }) @@ -246,12 +246,12 @@ function actualizar_display() { * Actualiza el estado a activo * @param {string} id Recibe el id del elemento a actualizar */ -function cambiar_estado(id){ - display.map(fila=>{ - fila.map(columna=>{ +function cambiar_estado(id) { + display.map(fila => { + fila.map(columna => { //buscar la hora correspondiente mediante el id y cambiar su estado a 1 - if(columna.id==id){ - display[display.indexOf(fila)][fila.indexOf(columna)].estado=1 + if (columna.id == id) { + display[display.indexOf(fila)][fila.indexOf(columna)].estado = 1 } }) }) @@ -276,14 +276,14 @@ function hora() { if (minute > 30) {//si hay mas de 30 minutos //activa la hora pasada tanto - cambiar_estado("h_"+(hour+1)) + cambiar_estado("h_" + (hour + 1)) //activa el to cambiar_estado("to") } else { //activa la hora correspondiente - cambiar_estado("h_"+hour) + cambiar_estado("h_" + hour) if (minute !== 0) { //activa la palabra pasado /past cambiar_estado("past") @@ -296,15 +296,15 @@ function hora() { minutes = { 0: "m_0", 5: "m_5", - 10:"m_10", - 15:"m_15", - 20:"m_20", - 30:"m_30", + 10: "m_10", + 15: "m_15", + 20: "m_20", + 30: "m_30", }; if (offset in minutes) { //activa los minutos - cambiar_estado("m_"+offset) + cambiar_estado("m_" + offset) } else if (offset === 25) { cambiar_estado("m_20") @@ -325,20 +325,20 @@ function hora() { * Permite reemplazar el array de display por el correspondiente segun el idioma seleccionado * @param {string} lang idioma a cambiar */ -function cambiar_idioma(lang){ - if(lang=="es"||lang=="en"||lang=="eo"){ - display=language[lang] +function cambiar_idioma(lang) { + if (lang == "es" || lang == "en" || lang == "eo") { + display = language[lang] return lang - }else{ + } else { console.log("argumento desconocido, usando idioma por defecto") return "en" } - - + + } cambiar_idioma(process.argv[2]) hora() -setInterval(hora,60000) +setInterval(hora, 60000) -exports.cambiar_idioma=cambiar_idioma \ No newline at end of file +exports.cambiar_idioma = cambiar_idioma \ No newline at end of file diff --git a/package.json b/package.json index 475a278..8a37d10 100755 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "terminal" ], "author": "drk0027", - "license": "ISC", + "license": "MIT", "dependencies": { "chai": "^4.3.4", "chalk": "^4.1.1" diff --git a/test/wordclock_test.js b/test/wordclock_test.js index 8709d36..236f8b1 100755 --- a/test/wordclock_test.js +++ b/test/wordclock_test.js @@ -1,64 +1,22 @@ var assert = require("chai").assert; -var expect = require("chai").expect; -var should = require("chai").should(); - var inicio = require("../index"); describe("WordClock evaluado utilizando la interfaz Assert del modulo CHAI", function () { - describe("Comprobar que el idioma sea cambiado con exito",function(){ - it("Comprobar que el idioma esperado coincida con el seleccionado",function(){ - result= inicio.cambiar_idioma("es") - assert.equal(result,"es") + describe("Comprobar que el idioma sea cambiado con exito", function () { + it("Comprobar que el idioma esperado coincida con el seleccionado", function () { + result = inicio.cambiar_idioma("es") + assert.equal(result, "es") }) - it("Comprobar que el idioma seleccionado retorne el idioma predeterminado",function(){ - result= inicio.cambiar_idioma("ep") - assert.equal(result,"en") + it("Comprobar que el idioma esperado coincida con el seleccionado", function () { + result = inicio.cambiar_idioma("eo") + assert.equal(result, "eo") + }) + it("Comprobar que el idioma seleccionado al ser desconocido retorne el idioma predeterminado", function () { + result = inicio.cambiar_idioma("ep") + assert.equal(result, "en") }) }) - + }); - -/* - -describe("WordClock evaluado utilizando la interfaz Assert del modulo CHAI", function () { - describe("revisar que el idioma sea cambiado con exito",function(){ - it("Comprobar que el idioma esperado coincida con el seleccionado",function(){ - result= inicio.cambiar_idioma("es") - assert.equal(result,"es") - }) - it("Comprobar que el idioma seleccionado retorne el idioma predeterminado",function(){ - result= inicio.cambiar_idioma("ep") - assert.equal(result,"error") - }) - }) - -}); - -describe("WordClock evaluado utilizando la interfaz EXPECT del modulo CHAI",function(){ - describe("Revisar funcion cambiar_idioma",function(){ - it("revisar el valor de retorno esperado usando expect(value).to.equal('value')",function(){ - result=inicio.cambiar_idioma("es") - expect(result).to.equal("es") - }) - }) -}) - -describe("Calcultator tests using SHOULD interface from CHAI module: ", function () { - describe("Check addTested Function: ", function () { - it("Check the returned value using: value.should.equal(value): ", function () { - result = calculator.addTested("text"); - result.should.equal("text tested"); - }); - it("Check the returned value using: value.should.be.a('value'): ", function () { - result = calculator.addTested("text"); - result.should.be.a('string'); - }); - it("Check the returned value using: expect(value).to.have.lengthOf(value): ", function () { - result = calculator.addTested("text"); - result.should.have.lengthOf(11); - }); - }); -}); -*/ \ No newline at end of file