@icarusmx/creta 1.0.19 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/creta.js CHANGED
@@ -768,21 +768,7 @@ async function startEnunciadosSelectorInteractive() {
768
768
  }
769
769
 
770
770
  console.log("Los enunciados fundamentales son un conjunto de afirmaciones que tienen el propósito de ejercitar el pensamiento orientado a objetos de los estudiantes de Creta. Escogimos estos enunciados porque creemos que exhaustan los conceptos mínimos necesarios para entender el paradigma de la programación orientada a objetos.")
771
-
772
- // Wait for user to press Enter before showing the list
773
- const rl = createInterface({
774
- input: process.stdin,
775
- output: process.stdout
776
- })
777
-
778
- await new Promise((resolve) => {
779
- rl.question("\nPresiona Enter para ver los enunciados...", () => {
780
- rl.close()
781
- resolve()
782
- })
783
- })
784
-
785
- console.clear()
771
+ console.log("")
786
772
  console.log("Elige qué enunciado te gustaría explorar:")
787
773
  console.log("")
788
774
 
@@ -803,6 +789,8 @@ async function startEnunciadosSelectorInteractive() {
803
789
  process.stdout.write('\x1b[2J')
804
790
  process.stdout.write('\x1b[H')
805
791
 
792
+ console.log("Los enunciados fundamentales son un conjunto de afirmaciones que tienen el propósito de ejercitar el pensamiento orientado a objetos de los estudiantes de Creta. Escogimos estos enunciados porque creemos que exhaustan los conceptos mínimos necesarios para entender el paradigma de la programación orientada a objetos.")
793
+ console.log("")
806
794
  console.log("Elige qué enunciado te gustaría explorar:")
807
795
  console.log("")
808
796
 
@@ -1001,10 +989,7 @@ async function startEnunciadosSelectorFallback() {
1001
989
 
1002
990
  try {
1003
991
  console.log("Los enunciados fundamentales son un conjunto de afirmaciones que tienen el propósito de ejercitar el pensamiento orientado a objetos de los estudiantes de Creta. Escogimos estos enunciados porque creemos que exhaustan los conceptos mínimos necesarios para entender el paradigma de la programación orientada a objetos.")
1004
-
1005
- const respuestaEnter = await askQuestion("\nPresiona Enter para ver los enunciados...")
1006
-
1007
- console.clear()
992
+ console.log("")
1008
993
  console.log("Elige qué enunciado te gustaría explorar:")
1009
994
  console.log("")
1010
995
 
@@ -94,86 +94,84 @@ export class Lesson1SystemDecomposition {
94
94
  console.clear()
95
95
  console.log("Descomposición en objetos:")
96
96
 
97
- console.log("\n📄 Clase Book:")
98
- console.log("━".repeat(50))
99
- console.log("class Book {")
100
- console.log(" constructor(title, author, isbn) {")
101
- console.log(" this.title = title")
102
- console.log(" this.author = author")
103
- console.log(" this.isbn = isbn")
104
- console.log(" this.isLoaned = false")
105
- console.log(" }")
106
- console.log("")
107
- console.log(" isAvailable() {")
108
- console.log(" return !this.isLoaned")
109
- console.log(" }")
110
- console.log("")
111
- console.log(" markAsLoaned() {")
112
- console.log(" this.isLoaned = true")
113
- console.log(" }")
114
- console.log("")
115
- console.log(" markAsReturned() {")
116
- console.log(" this.isLoaned = false")
117
- console.log(" }")
118
- console.log("}")
119
- console.log("━".repeat(50))
97
+ const bookCode = `class Book {
98
+ constructor(title, author, isbn) {
99
+ this.title = title
100
+ this.author = author
101
+ this.isbn = isbn
102
+ this.isLoaned = false
103
+ }
104
+
105
+ isAvailable() {
106
+ return !this.isLoaned
107
+ }
108
+
109
+ markAsLoaned() {
110
+ this.isLoaned = true
111
+ }
112
+
113
+ markAsReturned() {
114
+ this.isLoaned = false
115
+ }
116
+ }`
117
+
118
+ this.printCodeWithColors("📄 Clase Book", bookCode)
120
119
 
121
120
  await this.waitForEnter("\nPresiona Enter para ver User...")
122
121
 
123
- console.log("\n📄 Clase User:")
124
- console.log("━".repeat(50))
125
- console.log("class User {")
126
- console.log(" constructor(name, email, maxLoans = 3) {")
127
- console.log(" this.name = name")
128
- console.log(" this.email = email")
129
- console.log(" this.maxLoans = maxLoans")
130
- console.log(" this.currentLoans = []")
131
- console.log(" }")
132
- console.log("")
133
- console.log(" canBorrow() {")
134
- console.log(" return this.currentLoans.length < this.maxLoans")
135
- console.log(" }")
136
- console.log("")
137
- console.log(" addLoan(loan) {")
138
- console.log(" this.currentLoans.push(loan)")
139
- console.log(" }")
140
- console.log("")
141
- console.log(" removeLoan(loan) {")
142
- console.log(" const index = this.currentLoans.indexOf(loan)")
143
- console.log(" if (index > -1) this.currentLoans.splice(index, 1)")
144
- console.log(" }")
145
- console.log("}")
146
- console.log("━".repeat(50))
122
+ const userCode = `class User {
123
+ constructor(name, email, maxLoans = 3) {
124
+ this.name = name
125
+ this.email = email
126
+ this.maxLoans = maxLoans
127
+ this.currentLoans = []
128
+ }
129
+
130
+ canBorrow() {
131
+ return this.currentLoans.length < this.maxLoans
132
+ }
133
+
134
+ addLoan(loan) {
135
+ this.currentLoans.push(loan)
136
+ }
137
+
138
+ removeLoan(loan) {
139
+ const index = this.currentLoans.indexOf(loan)
140
+ if (index > -1) this.currentLoans.splice(index, 1)
141
+ }
142
+ }`
143
+
144
+ this.printCodeWithColors("📄 Clase User", userCode)
147
145
 
148
146
  await this.waitForEnter("\nPresiona Enter para ver Loan...")
149
147
 
150
- console.log("\n📄 Clase Loan:")
151
- console.log("━".repeat(50))
152
- console.log("class Loan {")
153
- console.log(" constructor(user, book, durationDays = 14) {")
154
- console.log(" this.user = user")
155
- console.log(" this.book = book")
156
- console.log(" this.startDate = new Date()")
157
- console.log(" this.dueDate = new Date(Date.now() + durationDays * 24 * 60 * 60 * 1000)")
158
- console.log(" this.returned = false")
159
- console.log(" }")
160
- console.log("")
161
- console.log(" isOverdue() {")
162
- console.log(" return !this.returned && new Date() > this.dueDate")
163
- console.log(" }")
164
- console.log("")
165
- console.log(" calculateFine() {")
166
- console.log(" if (!this.isOverdue()) return 0")
167
- console.log(" const daysLate = Math.ceil((new Date() - this.dueDate) / (24 * 60 * 60 * 1000))")
168
- console.log(" return daysLate * 5 // $5 por día")
169
- console.log(" }")
170
- console.log("")
171
- console.log(" returnBook() {")
172
- console.log(" this.returned = true")
173
- console.log(" this.book.markAsReturned()")
174
- console.log(" this.user.removeLoan(this)")
175
- console.log(" }")
176
- console.log("}")
148
+ const loanCode = `class Loan {
149
+ constructor(user, book, durationDays = 14) {
150
+ this.user = user
151
+ this.book = book
152
+ this.startDate = new Date()
153
+ this.dueDate = new Date(Date.now() + durationDays * 24 * 60 * 60 * 1000)
154
+ this.returned = false
155
+ }
156
+
157
+ isOverdue() {
158
+ return !this.returned && new Date() > this.dueDate
159
+ }
160
+
161
+ calculateFine() {
162
+ if (!this.isOverdue()) return 0
163
+ const daysLate = Math.ceil((new Date() - this.dueDate) / (24 * 60 * 60 * 1000))
164
+ return daysLate * 5 // $5 por día
165
+ }
166
+
167
+ returnBook() {
168
+ this.returned = true
169
+ this.book.markAsReturned()
170
+ this.user.removeLoan(this)
171
+ }
172
+ }`
173
+
174
+ this.printCodeWithColors("📄 Clase Loan", loanCode)
177
175
 
178
176
  await this.waitForEnter("\nPresiona Enter para ver Library...")
179
177
 
@@ -268,6 +266,36 @@ export class Lesson1SystemDecomposition {
268
266
  await this.waitForEnter("\n✨ ¡Lección 1 completada! Presiona Enter para continuar...")
269
267
  }
270
268
 
269
+ formatCode(code) {
270
+ // ANSI color codes
271
+ const colors = {
272
+ keyword: '\x1b[35m', // magenta for keywords like class, constructor
273
+ property: '\x1b[32m', // green for this.property
274
+ string: '\x1b[33m', // yellow for strings
275
+ comment: '\x1b[90m', // gray for comments
276
+ reset: '\x1b[0m' // reset color
277
+ }
278
+
279
+ return code
280
+ .replace(/\b(class|constructor|return|if|const|let|new)\b/g, `${colors.keyword}$1${colors.reset}`)
281
+ .replace(/\bthis\./g, `${colors.property}this.${colors.reset}`)
282
+ .replace(/'([^']*)'/g, `${colors.string}'$1'${colors.reset}`)
283
+ .replace(/"([^"]*)"/g, `${colors.string}"$1"${colors.reset}`)
284
+ .replace(/\/\/.*$/gm, `${colors.comment}$&${colors.reset}`)
285
+ }
286
+
287
+ printCodeWithColors(title, code) {
288
+ console.log(`\n${title}`)
289
+ console.log("━".repeat(50))
290
+
291
+ code.split('\n').forEach(line => {
292
+ const formattedLine = this.formatCode(line)
293
+ console.log(formattedLine)
294
+ })
295
+
296
+ console.log("━".repeat(50))
297
+ }
298
+
271
299
  async waitForEnter(message) {
272
300
  return new Promise((resolve) => {
273
301
  this.rl.question(message, () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@icarusmx/creta",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "Salgamos de este laberinto.",
5
5
  "type": "module",
6
6
  "bin": {