From e368a283b18a978645ce85da5894e7cafed3a773 Mon Sep 17 00:00:00 2001 From: Panu Horsmalahti Date: Sun, 5 Apr 2015 19:45:52 +0300 Subject: [PATCH 01/50] Add .npmignore to exclude unnecessary development files from npm package --- .npmignore | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .npmignore diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..fd842b0 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +# Development files +/tests/ +/.travis.yml +/screenshots From 65b9a16feffefe4f3ade28da0e7e97d6bd89b994 Mon Sep 17 00:00:00 2001 From: mahdi pedramrazi Date: Tue, 25 Aug 2015 14:54:25 -0700 Subject: [PATCH 02/50] Fixing the path in main we are using require.resolve and it's failing because the path is incorrect. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c365064..bc8d2e5 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "engines": { "node": ">=0.1.90" }, - "main": "lib", + "main": "lib/index.js", "files": [ "examples", "lib", From 5152d16f22789d66e107275e006f88517641ed18 Mon Sep 17 00:00:00 2001 From: Edgar Hipp Date: Tue, 21 Jun 2016 13:33:20 +0200 Subject: [PATCH 03/50] Update LICENSE --- LICENSE | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 3de4e33..17880ff 100644 --- a/LICENSE +++ b/LICENSE @@ -1,3 +1,5 @@ +MIT License + Original Library - Copyright (c) Marak Squires @@ -20,4 +22,4 @@ 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. \ No newline at end of file +THE SOFTWARE. From c74f2c3088b20591aae6181ab711ab9685d04d62 Mon Sep 17 00:00:00 2001 From: paladox Date: Thu, 22 Sep 2016 16:24:11 +0100 Subject: [PATCH 04/50] Update supports-colors.js --- lib/system/supports-colors.js | 106 +++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 47 deletions(-) diff --git a/lib/system/supports-colors.js b/lib/system/supports-colors.js index 3e008aa..aa2f841 100644 --- a/lib/system/supports-colors.js +++ b/lib/system/supports-colors.js @@ -1,61 +1,73 @@ -/* -The MIT License (MIT) +'use strict'; +var hasFlag = require('has-flag'); -Copyright (c) Sindre Sorhus (sindresorhus.com) +var support = function (level) { + if (level === 0) { + return false; + } -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: + return { + level: level, + hasBasic: true, + has256: level >= 2, + has16m: level >= 3 + }; +}; -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +var supportLevel = (function () { + if (hasFlag('no-color') || + hasFlag('no-colors') || + hasFlag('color=false')) { + return 0; + } -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. + if (hasFlag('color=16m') || + hasFlag('color=full') || + hasFlag('color=truecolor')) { + return 3; + } -*/ + if (hasFlag('color=256')) { + return 2; + } -var argv = process.argv; + if (hasFlag('color') || + hasFlag('colors') || + hasFlag('color=true') || + hasFlag('color=always')) { + return 1; + } -module.exports = (function () { - if (argv.indexOf('--no-color') !== -1 || - argv.indexOf('--color=false') !== -1) { - return false; - } + if (process.stdout && !process.stdout.isTTY) { + return 0; + } - if (argv.indexOf('--color') !== -1 || - argv.indexOf('--color=true') !== -1 || - argv.indexOf('--color=always') !== -1) { - return true; - } + if (process.platform === 'win32') { + return 1; + } - if (process.stdout && !process.stdout.isTTY) { - return false; - } + if ('COLORTERM' in process.env) { + return 1; + } - if (process.platform === 'win32') { - return true; - } + if (process.env.TERM === 'dumb') { + return 0; + } - if ('COLORTERM' in process.env) { - return true; - } + if (/^xterm-256(?:color)?/.test(process.env.TERM)) { + return 2; + } - if (process.env.TERM === 'dumb') { - return false; - } + if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) { + return 1; + } - if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) { - return true; - } + return 0; +})(); + +if (supportLevel === 0 && 'FORCE_COLOR' in process.env) { + supportLevel = 1; +} + +module.exports = process && support(supportLevel); - return false; -})(); \ No newline at end of file From 7e1e601ddc2e381724fa5ba28cd842712aa3eca4 Mon Sep 17 00:00:00 2001 From: Osman Mesut Ozcan Date: Tue, 31 Jan 2017 17:52:50 +0800 Subject: [PATCH 05/50] Update stringPrototypeBlacklist object stringPrototypeBlacklist is updated according to ES6 String.prototype.repeat() method. --- lib/extendStringPrototype.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/extendStringPrototype.js b/lib/extendStringPrototype.js index 67374a1..10c10f0 100644 --- a/lib/extendStringPrototype.js +++ b/lib/extendStringPrototype.js @@ -67,7 +67,7 @@ module['exports'] = function () { var stringPrototypeBlacklist = [ '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor', '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' ]; @@ -110,4 +110,4 @@ module['exports'] = function () { } }; -}; \ No newline at end of file +}; From 511aa7f822012914e6e1e146b09a708bd30f23f6 Mon Sep 17 00:00:00 2001 From: Osman Mesut OZCAN Date: Tue, 31 Jan 2017 18:17:11 +0800 Subject: [PATCH 06/50] Update stringPrototypeBlacklist object stringPrototypeBlacklist is updated according to ES6 String.prototype.repeat() method --- lib/extendStringPrototype.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extendStringPrototype.js b/lib/extendStringPrototype.js index 10c10f0..d6a3f63 100644 --- a/lib/extendStringPrototype.js +++ b/lib/extendStringPrototype.js @@ -67,7 +67,7 @@ module['exports'] = function () { var stringPrototypeBlacklist = [ '__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt', - 'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match','repeat' , 'replace', 'search', 'slice', 'split', 'substring', + 'indexOf', 'lastIndexof', 'length', 'localeCompare', 'match', 'repeat', 'replace', 'search', 'slice', 'split', 'substring', 'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight' ]; From 8d714a064203406060c67f8ba3c1ecad0e9913cb Mon Sep 17 00:00:00 2001 From: Meriem Khelifi Date: Wed, 8 Mar 2017 23:34:49 +0100 Subject: [PATCH 07/50] Adding badges npm, dependencies and devDependencies --- ReadMe.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ReadMe.md b/ReadMe.md index f09eb70..14a4731 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,4 +1,8 @@ -# 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) ## get color and style in your node.js console From 8c5af7ca1575c66f1b786460c38d900a6f149dd6 Mon Sep 17 00:00:00 2001 From: GlitchMasta47 Date: Sat, 11 Mar 2017 13:07:55 -0600 Subject: [PATCH 08/50] Update safe.js Whoa, string never ends! (even though it's a comment and it doesn't matter for that, but for the documentation's sake) --- safe.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/safe.js b/safe.js index a6a1f3a..b2574e7 100644 --- a/safe.js +++ b/safe.js @@ -1,9 +1,9 @@ // // 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") // // var colors = require('./lib/colors'); -module['exports'] = colors; \ No newline at end of file +module['exports'] = colors; From c018e0b1fbe87af8fa1bcde0d901a36e3d5f26a0 Mon Sep 17 00:00:00 2001 From: John Papandriopoulos Date: Fri, 29 Sep 2017 15:49:30 -0700 Subject: [PATCH 09/50] Remove setTheme dynamic require(...) that is problematic with webpack --- examples/normal-usage.js | 6 +++++- lib/colors.js | 17 +---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/examples/normal-usage.js b/examples/normal-usage.js index 2818741..3ceabd0 100644 --- a/examples/normal-usage.js +++ b/examples/normal-usage.js @@ -60,7 +60,11 @@ console.log("this is an input".input); console.log('Generic logging theme as file'.green.bold.underline); // 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); +} // outputs red text console.log("this is an error".error); diff --git a/lib/colors.js b/lib/colors.js index 790ffd4..96ed4a7 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -115,7 +115,7 @@ function applyStyle() { return str; } -function applyTheme (theme) { +colors.setTheme = function (theme) { for (var style in theme) { (function(style){ colors[style] = function(str){ @@ -132,21 +132,6 @@ function applyTheme (theme) { } } -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() { var ret = {}; Object.keys(styles).forEach(function (name) { From d0ae0e51641f4572d5e42c33861a4e0bd1d0cc8c Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 17 Jun 2015 14:49:52 +0200 Subject: [PATCH 10/50] [fix] In-proper scope reference. Closes #124 --- lib/extendStringPrototype.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/extendStringPrototype.js b/lib/extendStringPrototype.js index bbb9bcc..67374a1 100644 --- a/lib/extendStringPrototype.js +++ b/lib/extendStringPrototype.js @@ -86,7 +86,7 @@ module['exports'] = function () { addProperty(prop, function () { var ret = this; for (var t = 0; t < theme[prop].length; t++) { - ret = exports[theme[prop][t]](ret); + ret = colors[theme[prop][t]](ret); } return ret; }); From fbc26111cef778b63129f8a1ef4c84b3f7f29572 Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 17 Jun 2015 14:50:29 +0200 Subject: [PATCH 11/50] [dist] Bump to v1.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a896254..67e03ed 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "colors", "description": "get colors in your node.js console", - "version": "1.1.0", + "version": "1.1.1", "author": "Marak Squires", "homepage": "https://github.com/Marak/colors.js", "bugs": "https://github.com/Marak/colors.js/issues", From 8407be1d38212a75c84473353570a3227bff70af Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 17 Jun 2015 14:59:08 +0200 Subject: [PATCH 12/50] [fix] Really bad example in README. Examples should actually contain code that can run. Blame c11d23d96aee270bcfc8761c1f6c20579def88f3 --- ReadMe.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ReadMe.md b/ReadMe.md index f139bd5..0326aab 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -166,12 +166,13 @@ console.log(colors.warn("this is a warning")); You can also combine them: ```javascript +var colors = require('colors'); + colors.setTheme({ - link: ['underline', 'blue'] + custom: ['red', 'underline'] }); -// outputs underlined blue text -console.log(colors.info('Listening on ') + colors.link('http://0.0.0.0:' + port)); +console.log('test'.custom); ``` *Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.* From 85ec3019e68304e71c28b8fddf1cd3757386b79f Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 17 Jun 2015 15:01:51 +0200 Subject: [PATCH 13/50] [dist] Bump to v1.1.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 67e03ed..c365064 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "colors", "description": "get colors in your node.js console", - "version": "1.1.1", + "version": "1.1.2", "author": "Marak Squires", "homepage": "https://github.com/Marak/colors.js", "bugs": "https://github.com/Marak/colors.js/issues", From 2f20f2ea50876653003353e17622e1ee6f021292 Mon Sep 17 00:00:00 2001 From: Marak Date: Wed, 17 Jun 2015 15:42:07 +0200 Subject: [PATCH 14/50] Update ReadMe.md --- ReadMe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReadMe.md b/ReadMe.md index 0326aab..f09eb70 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -163,7 +163,7 @@ console.log(colors.warn("this is a warning")); ``` -You can also combine them: +### Combining Colors ```javascript var colors = require('colors'); From dc8eb09f6c3adfff6ea5194cae8a5809e0f43c80 Mon Sep 17 00:00:00 2001 From: fscherwi Date: Thu, 24 Sep 2015 20:38:28 +0200 Subject: [PATCH 15/50] test Node.js 0.12 and 4 --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ec43125..22a2e83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: node_js node_js: + - "4" + - "0.12" - "0.11" - "0.10" - "0.8" - - "0.6" \ No newline at end of file + - "0.6" From b75a729354fbbe2869eb117b85c1e776913943ed Mon Sep 17 00:00:00 2001 From: DABH Date: Mon, 12 Feb 2018 12:19:27 -0800 Subject: [PATCH 16/50] Test against modern Node versions and stop testing against very ancient Node 0.6 --- .travis.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 22a2e83..3c41c89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,14 @@ language: node_js node_js: + - "latest" + - "stable" + - "9" + - "8" + - "7" + - "6" + - "5" - "4" - "0.12" - "0.11" - "0.10" - "0.8" - - "0.6" From a51ced332c9aa6ea881c92835a9668f79dc341d5 Mon Sep 17 00:00:00 2001 From: DABH Date: Mon, 12 Feb 2018 12:25:07 -0800 Subject: [PATCH 17/50] No nvm aliases --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3c41c89..9c75946 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ language: node_js node_js: - - "latest" - - "stable" - "9" - "8" - "7" From f612a2d84f4692388fff096b821db30f60f99be0 Mon Sep 17 00:00:00 2001 From: DABH Date: Tue, 13 Feb 2018 15:36:40 -0800 Subject: [PATCH 18/50] Bump version for next beta release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bc8d2e5..e26e29d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "colors", "description": "get colors in your node.js console", - "version": "1.1.2", + "version": "1.2.0", "author": "Marak Squires", "homepage": "https://github.com/Marak/colors.js", "bugs": "https://github.com/Marak/colors.js/issues", From 4dbe3933ed88330c43992dee14393091a9b9c1b7 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:25:47 +0000 Subject: [PATCH 19/50] Update supports-colors.js --- lib/system/supports-colors.js | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/system/supports-colors.js b/lib/system/supports-colors.js index aa2f841..12e6cd3 100644 --- a/lib/system/supports-colors.js +++ b/lib/system/supports-colors.js @@ -1,3 +1,28 @@ +/* +The MIT License (MIT) + +Copyright (c) Sindre Sorhus (sindresorhus.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. + +*/ + 'use strict'; var hasFlag = require('has-flag'); @@ -46,6 +71,10 @@ var supportLevel = (function () { return 1; } + if ('CI' in process.env || 'TEAMCITY_VERSION' in process.env) { + return 0; + } + if ('COLORTERM' in process.env) { return 1; } @@ -70,4 +99,3 @@ if (supportLevel === 0 && 'FORCE_COLOR' in process.env) { } module.exports = process && support(supportLevel); - From 7bf2511fb392db2dafdddd5a78b7d34a3d44e290 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:26:25 +0000 Subject: [PATCH 20/50] Update supports-colors.js --- lib/system/supports-colors.js | 111 +++++++++++++++++++++++++--------- 1 file changed, 82 insertions(+), 29 deletions(-) diff --git a/lib/system/supports-colors.js b/lib/system/supports-colors.js index 12e6cd3..b39a1e7 100644 --- a/lib/system/supports-colors.js +++ b/lib/system/supports-colors.js @@ -24,25 +24,41 @@ THE SOFTWARE. */ 'use strict'; -var hasFlag = require('has-flag'); +const os = require('os'); +const hasFlag = require('has-flag'); -var support = function (level) { +const env = process.env; + +let forceColor; +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; +} + +function translateLevel(level) { if (level === 0) { return false; } return { - level: level, + level, hasBasic: true, has256: level >= 2, has16m: level >= 3 }; -}; +} -var supportLevel = (function () { - if (hasFlag('no-color') || - hasFlag('no-colors') || - hasFlag('color=false')) { +function supportsColor(stream) { + if (forceColor === false) { return 0; } @@ -56,46 +72,83 @@ var supportLevel = (function () { return 2; } - if (hasFlag('color') || - hasFlag('colors') || - hasFlag('color=true') || - hasFlag('color=always')) { - return 1; - } - - if (process.stdout && !process.stdout.isTTY) { + if (stream && !stream.isTTY && forceColor !== true) { return 0; } + const 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. + const 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 process.env || 'TEAMCITY_VERSION' in process.env) { - return 0; + if ('CI' in env) { + if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') { + return 1; + } + + return min; } - if ('COLORTERM' in process.env) { - return 1; + if ('TEAMCITY_VERSION' in env) { + return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; } - if (process.env.TERM === 'dumb') { - return 0; + if ('TERM_PROGRAM' in env) { + const 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 (/^xterm-256(?:color)?/.test(process.env.TERM)) { + if (/-256(color)?$/i.test(env.TERM)) { return 2; } - if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) { + if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { return 1; } - return 0; -})(); + if ('COLORTERM' in env) { + return 1; + } -if (supportLevel === 0 && 'FORCE_COLOR' in process.env) { - supportLevel = 1; + if (env.TERM === 'dumb') { + return min; + } + + return min; } -module.exports = process && support(supportLevel); +function getSupportLevel(stream) { + const level = supportsColor(stream); + return translateLevel(level); +} + +module.exports = { + supportsColor: getSupportLevel, + stdout: getSupportLevel(process.stdout), + stderr: getSupportLevel(process.stderr) +}; From ca0c69fb8bd6e8d76ad0417160cfe551e54000d4 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:27:23 +0000 Subject: [PATCH 21/50] Update package.json --- package.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package.json b/package.json index c365064..7874fd2 100644 --- a/package.json +++ b/package.json @@ -18,6 +18,9 @@ "node": ">=0.1.90" }, "main": "lib", + "dependencies": { + "has-flag": "^3.0.0" + }, "files": [ "examples", "lib", From 431627771e1617a729a099b2507539f5c1115a7a Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:35:13 +0000 Subject: [PATCH 22/50] Create has-flag.js --- lib/system/has-flag.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/system/has-flag.js diff --git a/lib/system/has-flag.js b/lib/system/has-flag.js new file mode 100644 index 0000000..541c4e1 --- /dev/null +++ b/lib/system/has-flag.js @@ -0,0 +1,20 @@ +/* +MIT License + +Copyright (c) Sindre Sorhus (sindresorhus.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. +*/ + +'use strict'; +module.exports = (flag, argv) => { + argv = argv || process.argv; + const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); + const pos = argv.indexOf(prefix + flag); + const terminatorPos = argv.indexOf('--'); + return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); +}; From 2b739138b3b016c70ceb7c04fb86a04f68dbb170 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:35:35 +0000 Subject: [PATCH 23/50] Update supports-colors.js --- lib/system/supports-colors.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system/supports-colors.js b/lib/system/supports-colors.js index b39a1e7..26b4cbd 100644 --- a/lib/system/supports-colors.js +++ b/lib/system/supports-colors.js @@ -25,7 +25,7 @@ THE SOFTWARE. 'use strict'; const os = require('os'); -const hasFlag = require('has-flag'); +const hasFlag = require('./has-flag.js'); const env = process.env; From 34a3d33de18f8935692de9dfaac695e5a0452306 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:35:46 +0000 Subject: [PATCH 24/50] Update package.json --- package.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/package.json b/package.json index a1ed764..e26e29d 100644 --- a/package.json +++ b/package.json @@ -18,9 +18,6 @@ "node": ">=0.1.90" }, "main": "lib/index.js", - "dependencies": { - "has-flag": "^3.0.0" - }, "files": [ "examples", "lib", From 2dc605c8cd8fa3379fe45ea6fc16ea0100331b27 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:47:45 +0000 Subject: [PATCH 25/50] Update supports-colors.js --- lib/system/supports-colors.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/system/supports-colors.js b/lib/system/supports-colors.js index 26b4cbd..67802ad 100644 --- a/lib/system/supports-colors.js +++ b/lib/system/supports-colors.js @@ -24,10 +24,10 @@ THE SOFTWARE. */ 'use strict'; -const os = require('os'); -const hasFlag = require('./has-flag.js'); +var os = require('os'); +var hasFlag = require('./has-flag.js'); -const env = process.env; +var env = process.env; let forceColor; if (hasFlag('no-color') || @@ -85,7 +85,7 @@ function supportsColor(stream) { // 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. - const osRelease = os.release().split('.'); + var osRelease = os.release().split('.'); if ( Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && @@ -110,7 +110,7 @@ function supportsColor(stream) { } if ('TERM_PROGRAM' in env) { - const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10); + var version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10); switch (env.TERM_PROGRAM) { case 'iTerm.app': From 8d1da39bb4ba14f176dd3b28307b1ad2ed41af5d Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:48:12 +0000 Subject: [PATCH 26/50] Update has-flag.js --- lib/system/has-flag.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/system/has-flag.js b/lib/system/has-flag.js index 541c4e1..c9698f8 100644 --- a/lib/system/has-flag.js +++ b/lib/system/has-flag.js @@ -11,10 +11,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ 'use strict'; -module.exports = (flag, argv) => { +module.exports = function(flag, argv) { argv = argv || process.argv; - const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); - const pos = argv.indexOf(prefix + flag); - const terminatorPos = argv.indexOf('--'); - return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); + var prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); + var pos = argv.indexOf(prefix + flag); + var terminatorPos = argv.indexOf('--'); + var pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); }; From f7227f2e87d74bfa71683e217773d9afe240574a Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:51:51 +0000 Subject: [PATCH 27/50] Update has-flag.js --- lib/system/has-flag.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/system/has-flag.js b/lib/system/has-flag.js index c9698f8..e70d7db 100644 --- a/lib/system/has-flag.js +++ b/lib/system/has-flag.js @@ -11,10 +11,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ 'use strict'; -module.exports = function(flag, argv) { - argv = argv || process.argv; - var prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--'); - var pos = argv.indexOf(prefix + flag); +module.exports = function (flag, argv) { var terminatorPos = argv.indexOf('--'); - var pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); + var prefix = /^-{1,2}/.test(flag) ? '' : '--'; + var pos = argv.indexOf(prefix + flag); + + return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); }; From a0bb4041638d287e59172fd883797fdd632cf013 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:54:30 +0000 Subject: [PATCH 28/50] Update has-flag.js --- lib/system/has-flag.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/system/has-flag.js b/lib/system/has-flag.js index e70d7db..84958fa 100644 --- a/lib/system/has-flag.js +++ b/lib/system/has-flag.js @@ -12,6 +12,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI 'use strict'; module.exports = function (flag, argv) { + argv = argv || process.argv; var terminatorPos = argv.indexOf('--'); var prefix = /^-{1,2}/.test(flag) ? '' : '--'; var pos = argv.indexOf(prefix + flag); From 493733638d8ca986a3b0dd911911f298cbb8ba27 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 00:58:15 +0000 Subject: [PATCH 29/50] Update supports-colors.js --- lib/system/supports-colors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/system/supports-colors.js b/lib/system/supports-colors.js index 67802ad..68034fc 100644 --- a/lib/system/supports-colors.js +++ b/lib/system/supports-colors.js @@ -29,7 +29,7 @@ var hasFlag = require('./has-flag.js'); var env = process.env; -let forceColor; +var forceColor; if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) { @@ -50,7 +50,7 @@ function translateLevel(level) { } return { - level, + level: level, hasBasic: true, has256: level >= 2, has16m: level >= 3 From 2c38a68a7c3038848bc5618b11472a305142c643 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 01:02:05 +0000 Subject: [PATCH 30/50] Update supports-colors.js --- lib/system/supports-colors.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/system/supports-colors.js b/lib/system/supports-colors.js index 68034fc..d2b02a3 100644 --- a/lib/system/supports-colors.js +++ b/lib/system/supports-colors.js @@ -76,7 +76,7 @@ function supportsColor(stream) { return 0; } - const min = forceColor ? 1 : 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 @@ -143,7 +143,7 @@ function supportsColor(stream) { } function getSupportLevel(stream) { - const level = supportsColor(stream); + var level = supportsColor(stream); return translateLevel(level); } From 007f4d1cd5bb8ec62dc0eeb3a2afe388778bebca Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 01:09:26 +0000 Subject: [PATCH 31/50] Update supports-colors.js --- lib/system/supports-colors.js | 107 ++++++++-------------------------- 1 file changed, 25 insertions(+), 82 deletions(-) diff --git a/lib/system/supports-colors.js b/lib/system/supports-colors.js index d2b02a3..48509a6 100644 --- a/lib/system/supports-colors.js +++ b/lib/system/supports-colors.js @@ -24,27 +24,9 @@ THE SOFTWARE. */ 'use strict'; -var os = require('os'); var hasFlag = require('./has-flag.js'); -var env = process.env; - -var forceColor; -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; -} - -function translateLevel(level) { +var support = function (level) { if (level === 0) { return false; } @@ -55,10 +37,12 @@ function translateLevel(level) { has256: level >= 2, has16m: level >= 3 }; -} +}; -function supportsColor(stream) { - if (forceColor === false) { +var supportLevel = (function () { + if (hasFlag('no-color') || + hasFlag('no-colors') || + hasFlag('color=false')) { return 0; } @@ -72,83 +56,42 @@ function supportsColor(stream) { return 2; } - if (stream && !stream.isTTY && forceColor !== true) { + if (hasFlag('color') || + hasFlag('colors') || + hasFlag('color=true') || + hasFlag('color=always')) { + return 1; + } + + if (process.stdout && !process.stdout.isTTY) { 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(sign => sign in env) || env.CI_NAME === 'codeship') { - return 1; - } - - return min; + if ('COLORTERM' in process.env) { + return 1; } - if ('TEAMCITY_VERSION' in env) { - return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; + if (process.env.TERM === 'dumb') { + return 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)) { + if (/^xterm-256(?:color)?/.test(process.env.TERM)) { return 2; } - if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { + if (/^screen|^xterm|^vt100|color|ansi|cygwin|linux/i.test(process.env.TERM)) { return 1; } - if ('COLORTERM' in env) { - return 1; - } + return 0; +})(); - if (env.TERM === 'dumb') { - return min; - } - - return min; +if (supportLevel === 0 && 'FORCE_COLOR' in process.env) { + supportLevel = 1; } -function getSupportLevel(stream) { - var level = supportsColor(stream); - return translateLevel(level); -} - -module.exports = { - supportsColor: getSupportLevel, - stdout: getSupportLevel(process.stdout), - stderr: getSupportLevel(process.stderr) -}; +module.exports = process && support(supportLevel); From fdd9b55cd189a4046502ca499f085a6d9ca1a6c8 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 01:10:20 +0000 Subject: [PATCH 32/50] Update has-flag.js --- lib/system/has-flag.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/system/has-flag.js b/lib/system/has-flag.js index 84958fa..6097003 100644 --- a/lib/system/has-flag.js +++ b/lib/system/has-flag.js @@ -13,8 +13,9 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI 'use strict'; module.exports = function (flag, argv) { argv = argv || process.argv; + var terminatorPos = argv.indexOf('--'); - var prefix = /^-{1,2}/.test(flag) ? '' : '--'; + var prefix = /^-{1,2}/.test(flag) ? '' : '--'; var pos = argv.indexOf(prefix + flag); return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); From e90c3c508873de4fc7a1699968687e79628aa59e Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 02:11:16 +0000 Subject: [PATCH 33/50] Update supports-colors.js --- lib/system/supports-colors.js | 106 +++++++++++++++++++++++++--------- 1 file changed, 78 insertions(+), 28 deletions(-) diff --git a/lib/system/supports-colors.js b/lib/system/supports-colors.js index 48509a6..f351bae 100644 --- a/lib/system/supports-colors.js +++ b/lib/system/supports-colors.js @@ -24,9 +24,23 @@ THE SOFTWARE. */ 'use strict'; + +var os = require('os'); var hasFlag = require('./has-flag.js'); -var support = function (level) { +var env = process.env; + +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; +} + +function translateLevel(level) { if (level === 0) { return false; } @@ -37,18 +51,14 @@ var support = function (level) { has256: level >= 2, has16m: level >= 3 }; -}; +} -var supportLevel = (function () { - if (hasFlag('no-color') || - hasFlag('no-colors') || - hasFlag('color=false')) { +function supportsColor(stream) { + if (forceColor === false) { return 0; } - if (hasFlag('color=16m') || - hasFlag('color=full') || - hasFlag('color=truecolor')) { + if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) { return 3; } @@ -56,42 +66,82 @@ var supportLevel = (function () { return 2; } - if (hasFlag('color') || - hasFlag('colors') || - hasFlag('color=true') || - hasFlag('color=always')) { - return 1; - } - - if (process.stdout && !process.stdout.isTTY) { + 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 ('COLORTERM' in process.env) { - 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 (process.env.TERM === 'dumb') { - return 0; + if ('TEAMCITY_VERSION' in env) { + return (/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0 + ); } - if (/^xterm-256(?:color)?/.test(process.env.TERM)) { + 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|color|ansi|cygwin|linux/i.test(process.env.TERM)) { + if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { return 1; } - return 0; -})(); + if ('COLORTERM' in env) { + return 1; + } -if (supportLevel === 0 && 'FORCE_COLOR' in process.env) { - supportLevel = 1; + if (env.TERM === 'dumb') { + return min; + } + + return min; } -module.exports = process && support(supportLevel); +function getSupportLevel(stream) { + var level = supportsColor(stream); + return translateLevel(level); +} + +module.exports = { + supportsColor: getSupportLevel, + stdout: getSupportLevel(process.stdout), + stderr: getSupportLevel(process.stderr) +}; From 24ab40b4ad043f813691ecd7ef9f6aaa4740951e Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 02:12:04 +0000 Subject: [PATCH 34/50] Update has-flag.js --- lib/system/has-flag.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/system/has-flag.js b/lib/system/has-flag.js index 6097003..df0f8c9 100644 --- a/lib/system/has-flag.js +++ b/lib/system/has-flag.js @@ -11,12 +11,11 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI */ 'use strict'; + module.exports = function (flag, argv) { argv = argv || process.argv; - - var terminatorPos = argv.indexOf('--'); - var prefix = /^-{1,2}/.test(flag) ? '' : '--'; + var prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--'; var pos = argv.indexOf(prefix + flag); - + var terminatorPos = argv.indexOf('--'); return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); }; From fccafd2ad8a762b012edf3462d845b94785edb35 Mon Sep 17 00:00:00 2001 From: paladox Date: Wed, 14 Feb 2018 02:17:48 +0000 Subject: [PATCH 35/50] Update has-flag.js --- lib/system/has-flag.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/system/has-flag.js b/lib/system/has-flag.js index df0f8c9..0ebdbf5 100644 --- a/lib/system/has-flag.js +++ b/lib/system/has-flag.js @@ -14,8 +14,10 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI module.exports = function (flag, argv) { argv = argv || process.argv; - var prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--'; - var pos = argv.indexOf(prefix + flag); + var terminatorPos = argv.indexOf('--'); + var prefix = /^-{1,2}/.test(flag) ? '' : '--'; + var pos = argv.indexOf(prefix + flag); + return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos); }; From 1d7180a8a150100bccbd5324a21f82766add1f85 Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 16 Feb 2018 14:17:42 -0800 Subject: [PATCH 36/50] better way to call updated supportsColor --- lib/colors.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/colors.js b/lib/colors.js index 790ffd4..dc68fdb 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -36,10 +36,10 @@ colors.themes = {}; var ansiStyles = colors.styles = require('./styles'); var defineProps = Object.defineProperties; -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; } colors.stripColors = colors.strip = function(str){ @@ -184,4 +184,4 @@ for (var map in colors.maps) { })(map) } -defineProps(colors, init()); \ No newline at end of file +defineProps(colors, init()); From 0da00b2e321bd4c7782439182ab65cc2f1c5c259 Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 16 Feb 2018 14:32:59 -0800 Subject: [PATCH 37/50] Update colors.js Setting a theme using a dynamic require is bad practice and causes lots of problems. In case anyone is using that "feature," though, we return a warning that very explicitly tells them the (very simple) change they need to make to their code. --- lib/colors.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/colors.js b/lib/colors.js index 96ed4a7..2238270 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -116,6 +116,13 @@ function applyStyle() { } 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) { (function(style){ colors[style] = function(str){ @@ -169,4 +176,4 @@ for (var map in colors.maps) { })(map) } -defineProps(colors, init()); \ No newline at end of file +defineProps(colors, init()); From 15abdf6f8577c0540abf1dec52bef504fea8a71f Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 16 Feb 2018 14:41:53 -0800 Subject: [PATCH 38/50] 1.2.0-rc0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e26e29d..c82b863 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "colors", "description": "get colors in your node.js console", - "version": "1.2.0", + "version": "1.2.0-rc0", "author": "Marak Squires", "homepage": "https://github.com/Marak/colors.js", "bugs": "https://github.com/Marak/colors.js/issues", From aea3ca5614915ea81e7146bdb1bca98b9d2341dc Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 16 Feb 2018 14:57:36 -0800 Subject: [PATCH 39/50] Add note to readme directing users to pre-release version; eagerly solicit feedback... --- ReadMe.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReadMe.md b/ReadMe.md index f09eb70..ff36a05 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,5 +1,9 @@ # colors.js [![Build Status](https://travis-ci.org/Marak/colors.js.svg?branch=master)](https://travis-ci.org/Marak/colors.js) +**Update on colors.js roadmap (2018-02-16):** The maintainers have published a pre-release version of `colors` that addresses a number of compatibility issues raised by community. You may install the +RC version by specifying `next` or `>=1.2.0-rc0` as the version for `colors` in your `package.json`. We are eager to receive community feedback on this version in order to move it out of pre-release. +Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. + ## get color and style in your node.js console ![Demo](https://raw.githubusercontent.com/Marak/colors.js/master/screenshots/colors.png) From f1b9ec090ffee56666d57128c6ced2ca49429acd Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 16 Feb 2018 16:02:56 -0800 Subject: [PATCH 40/50] Ancient Node 0.6 no longer compiles on Travis --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 22a2e83..1e6d011 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,3 @@ node_js: - "0.11" - "0.10" - "0.8" - - "0.6" From 6fc77f93b4bbf5717dd98e0c46851a994ef66945 Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 16 Feb 2018 14:57:36 -0800 Subject: [PATCH 41/50] Add note to readme directing users to pre-release version; eagerly solicit feedback... --- ReadMe.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ReadMe.md b/ReadMe.md index 14a4731..969ef15 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -4,6 +4,10 @@ [![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) +**Update on colors.js roadmap (2018-02-16):** The maintainers have published a pre-release version of `colors` that addresses a number of compatibility issues raised by community. You may install the +RC version by specifying `next` or `>=1.2.0-rc0` as the version for `colors` in your `package.json`. We are eager to receive community feedback on this version in order to move it out of pre-release. +Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. + ## get color and style in your node.js console ![Demo](https://raw.githubusercontent.com/Marak/colors.js/master/screenshots/colors.png) From 08ce9159f4f2af07f4c631ba10fbecc16190b00a Mon Sep 17 00:00:00 2001 From: DABH Date: Wed, 21 Feb 2018 19:51:55 -0800 Subject: [PATCH 42/50] Bring home Typescript definitions from DefinitelyTyped --- index.d.ts | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++ safe.d.ts | 45 ++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 index.d.ts create mode 100644 safe.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..0dbdc83 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,133 @@ +// Type definitions for Colors.js 1.2 +// Project: https://github.com/Marak/colors.js +// Definitions by: Bart van der Schoor , Staffan Eketorp +// Definitions: https://github.com/Marak/colors.js + +export interface Color { + (text: string): string; + + strip: Color; + stripColors: Color; + + black: Color; + red: Color; + green: Color; + yellow: Color; + blue: Color; + magenta: Color; + cyan: Color; + white: Color; + gray: Color; + grey: Color; + + bgBlack: Color; + bgRed: Color; + bgGreen: Color; + bgYellow: Color; + bgBlue: Color; + bgMagenta: Color; + bgCyan: Color; + bgWhite: Color; + + reset: Color; + bold: Color; + dim: Color; + italic: Color; + underline: Color; + inverse: Color; + hidden: Color; + strikethrough: Color; + + rainbow: Color; + zebra: Color; + america: Color; + trap: Color; + random: Color; + zalgo: Color; +} + +export function setTheme(theme: any): void; + +export let enabled: boolean; + +export const strip: Color; +export const stripColors: Color; + +export const black: Color; +export const red: Color; +export const green: Color; +export const yellow: Color; +export const blue: Color; +export const magenta: Color; +export const cyan: Color; +export const white: Color; +export const gray: Color; +export const grey: Color; + +export const bgBlack: Color; +export const bgRed: Color; +export const bgGreen: Color; +export const bgYellow: Color; +export const bgBlue: Color; +export const bgMagenta: Color; +export const bgCyan: Color; +export const bgWhite: Color; + +export const reset: Color; +export const bold: Color; +export const dim: Color; +export const italic: Color; +export const underline: Color; +export const inverse: Color; +export const hidden: Color; +export const strikethrough: Color; + +export const rainbow: Color; +export const zebra: Color; +export const america: Color; +export const trap: Color; +export const random: Color; +export const zalgo: Color; + +declare global { + interface String { + strip: string; + stripColors: string; + + black: string; + red: string; + green: string; + yellow: string; + blue: string; + magenta: string; + cyan: string; + white: string; + gray: string; + grey: string; + + bgBlack: string; + bgRed: string; + bgGreen: string; + bgYellow: string; + bgBlue: string; + bgMagenta: string; + bgCyan: string; + bgWhite: string; + + reset: string; + bold: string; + dim: string; + italic: string; + underline: string; + inverse: string; + hidden: string; + strikethrough: string; + + rainbow: string; + zebra: string; + america: string; + trap: string; + random: string; + zalgo: string; + } +} diff --git a/safe.d.ts b/safe.d.ts new file mode 100644 index 0000000..87f5ef2 --- /dev/null +++ b/safe.d.ts @@ -0,0 +1,45 @@ +// Type definitions for Colors.js 1.2 +// Project: https://github.com/Marak/colors.js +// Definitions by: Bart van der Schoor , Staffan Eketorp +// Definitions: https://github.com/Marak/colors.js + +export const enabled: boolean; + +export function strip(str: string): string; +export function stripColors(str: string): string; + +export function black(str: string): string; +export function red(str: string): string; +export function green(str: string): string; +export function yellow(str: string): string; +export function blue(str: string): string; +export function magenta(str: string): string; +export function cyan(str: string): string; +export function white(str: string): string; +export function gray(str: string): string; +export function grey(str: string): string; + +export function bgBlack(str: string): string; +export function bgRed(str: string): string; +export function bgGreen(str: string): string; +export function bgYellow(str: string): string; +export function bgBlue(str: string): string; +export function bgMagenta(str: string): string; +export function bgCyan(str: string): string; +export function bgWhite(str: string): string; + +export function reset(str: string): string; +export function bold(str: string): string; +export function dim(str: string): string; +export function italic(str: string): string; +export function underline(str: string): string; +export function inverse(str: string): string; +export function hidden(str: string): string; +export function strikethrough(str: string): string; + +export function rainbow(str: string): string; +export function zebra(str: string): string; +export function america(str: string): string; +export function trap(str: string): string; +export function random(str: string): string; +export function zalgo(str: string): string; From a69fcef2703c65f9cbb768d8673d9c5ad72e3bca Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 2 Mar 2018 09:31:04 -0800 Subject: [PATCH 43/50] Create ROADMAP.md --- ROADMAP.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ROADMAP.md diff --git a/ROADMAP.md b/ROADMAP.md new file mode 100644 index 0000000..e8f0816 --- /dev/null +++ b/ROADMAP.md @@ -0,0 +1,16 @@ +# colors.js roadmap + +Here we describe upcoming releases and the key features/fixes they include. Don't see your feature/issue listed here? Get more +1's! + +## Currently Planned Releases + +### 1.3.0 + * Support custom colors + +### 1.2.1 + * Refactor tests to use a testing library like jest (only affects dev/testing) + +### 1.2.0 (release date: about 3/5/18, barring any new issues) + * Built-in Typescript definitions + * Key bug fixes for webpack/bundlers, webstorm, etc. + From 2da55cf0341e8167162b54d6c3317177bc15ac8b Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 2 Mar 2018 09:33:21 -0800 Subject: [PATCH 44/50] Update ReadMe.md link to roadmap --- ReadMe.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReadMe.md b/ReadMe.md index ff36a05..fc76234 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -2,7 +2,7 @@ **Update on colors.js roadmap (2018-02-16):** The maintainers have published a pre-release version of `colors` that addresses a number of compatibility issues raised by community. You may install the RC version by specifying `next` or `>=1.2.0-rc0` as the version for `colors` in your `package.json`. We are eager to receive community feedback on this version in order to move it out of pre-release. -Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. +Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. See also the [roadmap](ROADMAP.md). ## get color and style in your node.js console From ce83bdcac75f72a63b2dd719b1b2ce545f2c12d1 Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 9 Mar 2018 22:22:41 -0800 Subject: [PATCH 45/50] Ignore TS error about String.bold -- fixes #168 etc. --- index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 0dbdc83..db72fab 100644 --- a/index.d.ts +++ b/index.d.ts @@ -114,7 +114,8 @@ declare global { bgCyan: string; bgWhite: string; - reset: string; + reset: string; + // @ts-ignore bold: string; dim: string; italic: string; From f7c5083e3e9f91894567ad87d40e21c296a9a70e Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 9 Mar 2018 22:27:27 -0800 Subject: [PATCH 46/50] Update readme --- ReadMe.md => README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) rename ReadMe.md => README.md (88%) diff --git a/ReadMe.md b/README.md similarity index 88% rename from ReadMe.md rename to README.md index 969ef15..6329b48 100644 --- a/ReadMe.md +++ b/README.md @@ -4,9 +4,7 @@ [![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) -**Update on colors.js roadmap (2018-02-16):** The maintainers have published a pre-release version of `colors` that addresses a number of compatibility issues raised by community. You may install the -RC version by specifying `next` or `>=1.2.0-rc0` as the version for `colors` in your `package.json`. We are eager to receive community feedback on this version in order to move it out of pre-release. -Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. +Please check out the [roadmap.md] for upcoming features and releases. Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. ## get color and style in your node.js console From 4ba76b391d214f9d85b8313706239784944c980b Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 9 Mar 2018 22:28:54 -0800 Subject: [PATCH 47/50] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6329b48..4bebb6c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![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) -Please check out the [roadmap.md] for upcoming features and releases. Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. +Please check out the [roadmap](ROADMAP.md) for upcoming features and releases. Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. ## get color and style in your node.js console From 750f7ed9aff9ee5386356fadbe26ce170a16f947 Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 9 Mar 2018 22:32:54 -0800 Subject: [PATCH 48/50] Version bump (release 1.2.0) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c82b863..e26e29d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "colors", "description": "get colors in your node.js console", - "version": "1.2.0-rc0", + "version": "1.2.0", "author": "Marak Squires", "homepage": "https://github.com/Marak/colors.js", "bugs": "https://github.com/Marak/colors.js/issues", From e89ff93c09a2cc033fdba73a3bcb32c2ca6bab39 Mon Sep 17 00:00:00 2001 From: DABH Date: Fri, 9 Mar 2018 22:36:20 -0800 Subject: [PATCH 49/50] Resolve merge conflicts --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index a435c9c..4bebb6c 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,6 @@ Please check out the [roadmap](ROADMAP.md) for upcoming features and releases. Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. -**Update on colors.js roadmap (2018-02-16):** The maintainers have published a pre-release version of `colors` that addresses a number of compatibility issues raised by community. You may install the -RC version by specifying `next` or `>=1.2.0-rc0` as the version for `colors` in your `package.json`. We are eager to receive community feedback on this version in order to move it out of pre-release. -Please open Issues to provide feedback, and check the `develop` branch for the latest bleeding-edge updates. See also the [roadmap](ROADMAP.md). - ## get color and style in your node.js console ![Demo](https://raw.githubusercontent.com/Marak/colors.js/master/screenshots/colors.png) From dc82cc01d00df2f1cdcf90cba699a5a61da70446 Mon Sep 17 00:00:00 2001 From: DABH Date: Sun, 11 Mar 2018 22:51:05 -0700 Subject: [PATCH 50/50] Fix files field in package.json to include TS definitions; bump version --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e26e29d..a24614a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "colors", "description": "get colors in your node.js console", - "version": "1.2.0", + "version": "1.2.1", "author": "Marak Squires", "homepage": "https://github.com/Marak/colors.js", "bugs": "https://github.com/Marak/colors.js/issues", @@ -23,6 +23,8 @@ "lib", "LICENSE", "safe.js", - "themes" + "themes", + "index.d.ts", + "safe.d.ts" ] }