0
0
mirror of https://github.com/honojs/hono.git synced 2024-11-21 18:18:57 +01:00

fix(color): Deno does not require permission for NO_COLOR (#3306)

This commit is contained in:
ryu 2024-08-26 20:55:14 +09:00 committed by GitHub
parent 6d7565e2a1
commit 0a94e53832
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,16 +3,23 @@
* Color utility.
*/
/**
* Get whether color change on terminal is enabled or disabled.
* If `NO_COLOR` environment variable is set, this function returns `false`.
* @see {@link https://no-color.org/}
*
* @returns {boolean}
*/
export function getColorEnabled(): boolean {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { process, Deno } = globalThis as any
const isNoColor =
typeof process !== 'undefined'
typeof Deno?.noColor === 'boolean'
? (Deno.noColor as boolean)
: typeof process !== 'undefined'
? // eslint-disable-next-line no-unsafe-optional-chaining
'NO_COLOR' in process?.env
: typeof Deno?.noColor === 'boolean'
? (Deno.noColor as boolean)
: false
return !isNoColor