UNPKG

2.84 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright Google LLC All Rights Reserved.
5 *
6 * Use of this source code is governed by an MIT-style license that can be
7 * found in the LICENSE file at https://angular.io/license
8 */
9var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
10 if (k2 === undefined) k2 = k;
11 var desc = Object.getOwnPropertyDescriptor(m, k);
12 if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
13 desc = { enumerable: true, get: function() { return m[k]; } };
14 }
15 Object.defineProperty(o, k2, desc);
16}) : (function(o, m, k, k2) {
17 if (k2 === undefined) k2 = k;
18 o[k2] = m[k];
19}));
20var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21 Object.defineProperty(o, "default", { enumerable: true, value: v });
22}) : function(o, v) {
23 o["default"] = v;
24});
25var __importStar = (this && this.__importStar) || function (mod) {
26 if (mod && mod.__esModule) return mod;
27 var result = {};
28 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29 __setModuleDefault(result, mod);
30 return result;
31};
32Object.defineProperty(exports, "__esModule", { value: true });
33exports.colors = exports.removeColor = void 0;
34const ansiColors = __importStar(require("ansi-colors"));
35const tty_1 = require("tty");
36function supportColor() {
37 if (process.env.FORCE_COLOR !== undefined) {
38 // 2 colors: FORCE_COLOR = 0 (Disables colors), depth 1
39 // 16 colors: FORCE_COLOR = 1, depth 4
40 // 256 colors: FORCE_COLOR = 2, depth 8
41 // 16,777,216 colors: FORCE_COLOR = 3, depth 16
42 // See: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_getcolordepth_env
43 // and https://github.com/nodejs/node/blob/b9f36062d7b5c5039498e98d2f2c180dca2a7065/lib/internal/tty.js#L106;
44 switch (process.env.FORCE_COLOR) {
45 case '':
46 case 'true':
47 case '1':
48 case '2':
49 case '3':
50 return true;
51 default:
52 return false;
53 }
54 }
55 if (process.stdout instanceof tty_1.WriteStream) {
56 return process.stdout.getColorDepth() > 1;
57 }
58 return false;
59}
60function removeColor(text) {
61 // This has been created because when colors.enabled is false unstyle doesn't work
62 // see: https://github.com/doowb/ansi-colors/blob/a4794363369d7b4d1872d248fc43a12761640d8e/index.js#L38
63 return text.replace(ansiColors.ansiRegex, '');
64}
65exports.removeColor = removeColor;
66// Create a separate instance to prevent unintended global changes to the color configuration
67const colors = ansiColors.create();
68exports.colors = colors;
69colors.enabled = supportColor();