-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Rework color detection #87
Conversation
picocolors.js
Outdated
argv = p.argv || [], | ||
env = p.env || {}, | ||
out = p.stdout || {} | ||
let ne = v => v != null && String(v).length > 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need such elaborate check?
v
is guaranteed to be undefined
or String
, so this could be changed to simple v => !!v
.
And in this case we don't need this function at all.
Just use !!env.NO_COLOR
instead of ne(env.NO_COLOR)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #62 (comment). The key is to keep treating empty string value as falsy value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understood @lukeed comment correctly 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
> !!""
false
> !!"1"
true
> !!undefined
false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point. I tried to recall this behavior but testing it on numbers !!0
tripped me over.
picocolors.js
Outdated
(require != null && require("tty").isatty(1) && env.TERM !== "dumb") || | ||
"CI" in env) | ||
p.platform === "win32" || | ||
(out.isTTY && env.TERM !== "dumb") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out
is used only once.
Could be shorter to write
(p.stdout || {}).isTTY && ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, missed that
@@ -1,12 +1,13 @@ | |||
let argv = process.argv || [], | |||
env = process.env | |||
let p = process || {}, |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh actually using globalThis
would make this library not work in older Node.js version :/
Closes #41, #44, #62, #67, #71, #80, #83.