Socket
Socket
Sign inDemoInstall

colors

Package Overview
Dependencies
0
Maintainers
2
Versions
29
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.2 to 1.2.0-rc0

lib/system/has-flag.js

6

examples/normal-usage.js

@@ -63,3 +63,7 @@ var colors = require('../lib/index');

// Load a theme from file
colors.setTheme(__dirname + '/../themes/generic-logging.js');
try {
colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));
} catch (err) {
console.log(err);
}

@@ -66,0 +70,0 @@ // outputs red text

30

lib/colors.js

@@ -39,6 +39,6 @@ /*

colors.supportsColor = require('./system/supports-colors');
colors.supportsColor = require('./system/supports-colors').supportsColor;
if (typeof colors.enabled === "undefined") {
colors.enabled = colors.supportsColor;
colors.enabled = colors.supportsColor() !== false;
}

@@ -119,3 +119,10 @@

function applyTheme (theme) {
colors.setTheme = function (theme) {
if (typeof theme === 'string') {
console.log('colors.setTheme now only accepts an object, not a string. ' +
'If you are trying to set a theme from a file, it is now your (the caller\'s) responsibility to require the file. ' +
'The old syntax looked like colors.setTheme(__dirname + \'/../themes/generic-logging.js\'); ' +
'The new syntax looks like colors.setTheme(require(__dirname + \'/../themes/generic-logging.js\'));');
return;
}
for (var style in theme) {

@@ -137,17 +144,2 @@ (function(style){

colors.setTheme = function (theme) {
if (typeof theme === 'string') {
try {
colors.themes[theme] = require(theme);
applyTheme(colors.themes[theme]);
return colors.themes[theme];
} catch (err) {
console.log(err);
return err;
}
} else {
applyTheme(theme);
}
};
function init() {

@@ -190,2 +182,2 @@ var ret = {};

defineProps(colors, init());
defineProps(colors, init());

@@ -70,3 +70,3 @@ var colors = require('./colors');

'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt',
'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'replace', 'search', 'slice', 'split', 'substring',
'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice', 'split', 'substring',
'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight'

@@ -114,2 +114,2 @@ ];

};
};

@@ -26,37 +26,123 @@ /*

var argv = process.argv;
'use strict';
module.exports = (function () {
if (argv.indexOf('--no-color') !== -1 ||
argv.indexOf('--color=false') !== -1) {
return false;
}
var os = require('os');
var hasFlag = require('./has-flag.js');
if (argv.indexOf('--color') !== -1 ||
argv.indexOf('--color=true') !== -1 ||
argv.indexOf('--color=always') !== -1) {
return true;
}
var env = process.env;
if (process.stdout && !process.stdout.isTTY) {
return false;
}
var forceColor = void 0;
if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
forceColor = false;
} else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
forceColor = true;
}
if ('FORCE_COLOR' in env) {
forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
}
if (process.platform === 'win32') {
return true;
}
function translateLevel(level) {
if (level === 0) {
return false;
}
if ('COLORTERM' in process.env) {
return true;
}
return {
level: level,
hasBasic: true,
has256: level >= 2,
has16m: level >= 3
};
}
if (process.env.TERM === 'dumb') {
return false;
}
function supportsColor(stream) {
if (forceColor === false) {
return 0;
}
if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) {
return true;
}
if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
return 3;
}
return false;
})();
if (hasFlag('color=256')) {
return 2;
}
if (stream && !stream.isTTY && forceColor !== true) {
return 0;
}
var min = forceColor ? 1 : 0;
if (process.platform === 'win32') {
// Node.js 7.5.0 is the first version of Node.js to include a patch to
// libuv that enables 256 color output on Windows. Anything earlier and it
// won't work. However, here we target Node.js 8 at minimum as it is an LTS
// release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
// release that supports 256 colors. Windows 10 build 14931 is the first release
// that supports 16m/TrueColor.
var osRelease = os.release().split('.');
if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
return Number(osRelease[2]) >= 14931 ? 3 : 2;
}
return 1;
}
if ('CI' in env) {
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(function (sign) {
return sign in env;
}) || env.CI_NAME === 'codeship') {
return 1;
}
return min;
}
if ('TEAMCITY_VERSION' in env) {
return (/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0
);
}
if ('TERM_PROGRAM' in env) {
var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
switch (env.TERM_PROGRAM) {
case 'iTerm.app':
return version >= 3 ? 3 : 2;
case 'Hyper':
return 3;
case 'Apple_Terminal':
return 2;
// No default
}
}
if (/-256(color)?$/i.test(env.TERM)) {
return 2;
}
if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
return 1;
}
if ('COLORTERM' in env) {
return 1;
}
if (env.TERM === 'dumb') {
return min;
}
return min;
}
function getSupportLevel(stream) {
var level = supportsColor(stream);
return translateLevel(level);
}
module.exports = {
supportsColor: getSupportLevel,
stdout: getSupportLevel(process.stdout),
stderr: getSupportLevel(process.stderr)
};
{
"name": "colors",
"description": "get colors in your node.js console",
"version": "1.1.2",
"version": "1.2.0-rc0",
"author": "Marak Squires",

@@ -20,3 +20,3 @@ "homepage": "https://github.com/Marak/colors.js",

},
"main": "lib",
"main": "lib/index.js",
"files": [

@@ -23,0 +23,0 @@ "examples",

@@ -1,2 +0,6 @@

# colors.js [![Build Status](https://travis-ci.org/Marak/colors.js.svg?branch=master)](https://travis-ci.org/Marak/colors.js)
# colors.js
[![Build Status](https://travis-ci.org/Marak/colors.js.svg?branch=master)](https://travis-ci.org/Marak/colors.js)
[![version](https://img.shields.io/npm/v/colors.svg)](https://www.npmjs.org/package/colors)
[![dependencies](https://david-dm.org/Marak/colors.js.svg)](https://david-dm.org/Marak/colors.js)
[![devDependencies](https://david-dm.org/Marak/colors.js/dev-status.svg)](https://david-dm.org/Marak/colors.js#info=devDependencies)

@@ -166,3 +170,3 @@ ## get color and style in your node.js console

You can also combine them:
### Combining Colors

@@ -169,0 +173,0 @@ ```javascript

//
// Remark: Requiring this file will use the "safe" colors API which will not touch String.prototype
//
// var colors = require('colors/safe);
// var colors = require('colors/safe');
// colors.red("foo")

@@ -9,2 +9,2 @@ //

var colors = require('./lib/colors');
module['exports'] = colors;
module['exports'] = colors;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc