Files
SnowLuma/.pnpm-store/v11/files/14/27140541b1f95891857e1bc40fbddbe607a6243d4305cc540affcc2e07f2f128b7410924c08bf713961234f58f31458dff4f8be1ef64cc163a303b21be45fc
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

38 lines
1.1 KiB
Plaintext

//#region src/utils/color.ts
/**
* @module
* Color utility.
*/
/**
* Get whether color change on terminal is enabled or disabled.
* If `NO_COLOR` environment variable is set, this function returns `false`.
* Unlike getColorEnabledAsync(), this cannot check Cloudflare environment variables.
* @see {@link https://no-color.org/}
*
* @returns {boolean}
*/
function getColorEnabled() {
const { process, Deno } = globalThis;
return !(typeof Deno?.noColor === "boolean" ? Deno.noColor : process !== void 0 ? "NO_COLOR" in process?.env : false);
}
/**
* 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}
*/
async function getColorEnabledAsync() {
const { navigator } = globalThis;
const cfWorkers = "cloudflare:workers";
return !(navigator !== void 0 && navigator.userAgent === "Cloudflare-Workers" ? await (async () => {
try {
return "NO_COLOR" in ((await import(cfWorkers)).env ?? {});
} catch {
return false;
}
})() : !getColorEnabled());
}
//#endregion
export { getColorEnabled, getColorEnabledAsync };