UNPKG

znv

Version:

Parse your environment with Zod schemas

53 lines 3.15 kB
"use strict"; /* * This file adapted from module "colorette", originally found here: * https://github.com/jorgebucaran/colorette/blob/0928e67466a34e50b53c7a908f32e738c3904846/index.js * * Copyright © Jorge Bucaran <<https://jorgebucaran.com>> * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the 'Software'), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.cyan = exports.magenta = exports.blue = exports.yellow = exports.green = exports.red = exports.isColorSupported = void 0; /* eslint-disable @typescript-eslint/no-base-to-string */ const tty_1 = require("tty"); const { env = {}, argv = [], platform = "", } = typeof process === "undefined" ? {} : process; const isDisabled = "NO_COLOR" in env || argv.includes("--no-color"); const isForced = "FORCE_COLOR" in env || argv.includes("--color"); const isWindows = platform === "win32"; const isDumbTerminal = env["TERM"] === "dumb"; const isCompatibleTerminal = Boolean((0, tty_1.isatty)(1) && env["TERM"] && !isDumbTerminal); const isCI = "CI" in env && ("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env); exports.isColorSupported = !isDisabled && (isForced || (isWindows && !isDumbTerminal) || isCompatibleTerminal || isCI); const replaceClose = (index, str, close, replace, head = str.slice(0, index) + replace, tail = str.slice(index + close.length), next = tail.indexOf(close)) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace)); const clearBleed = (index, str, open, close) => index < 0 ? open + str + close : open + replaceClose(index, str, close, open) + close; const filterEmpty = (open, close) => (str) => str || !(str === "" || str === undefined) ? clearBleed(String(str).indexOf(close, open.length + 1), String(str), open, close) : ""; const create = (open, close) => exports.isColorSupported ? filterEmpty(`\x1b[${open}m`, `\x1b[${close}m`) : String; exports.red = create(31, 39); exports.green = create(32, 39); exports.yellow = create(33, 39); exports.blue = create(34, 39); exports.magenta = create(35, 39); exports.cyan = create(36, 39); //# sourceMappingURL=tty-colors.js.map