fix: Handle optional chaining

This commit is contained in:
Felix Rieseberg 2024-10-07 11:56:41 -04:00
parent fd1e8912a0
commit 7b30a7a4ad

View file

@ -93,11 +93,11 @@ class Logger {
}
set level (level) {
this.#level = this.#levels.get(level)?.id || null
this.#level = (this.#levels.get(level) && this.#levels.get(level).id) || null
}
isVisible (level) {
return this.level?.index <= this.#levels.get(level)?.index || -1
return (this.level && this.level.index <= (this.#levels.get(level) && this.#levels.get(level).index)) || -1
}
#onLog (...args) {
@ -124,7 +124,7 @@ class Logger {
}
#color (str, { fg, bg, inverse }) {
if (!this.#stream?.isTTY) {
if (!this.#stream || !this.#stream.isTTY) {
return str
}
@ -136,7 +136,7 @@ class Logger {
}
#log (levelId, msgPrefix, ...args) {
if (!this.isVisible(levelId) || typeof this.#stream?.write !== 'function') {
if (!this.isVisible(levelId) || (this.#stream && typeof this.#stream.write !== 'function')) {
return
}