diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt deleted file mode 100644 index 3de4e33..0000000 --- a/MIT-LICENSE.txt +++ /dev/null @@ -1,23 +0,0 @@ -Original Library - - Copyright (c) Marak Squires - -Additional Functionality - - 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. \ No newline at end of file diff --git a/ReadMe.md b/ReadMe.md index beb5b14..aea4b9a 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,8 +1,8 @@ -# colors.js +# colors.js [![Build Status](https://travis-ci.org/Marak/colors.js.svg?branch=master)](https://travis-ci.org/Marak/colors.js) ## get color and style in your node.js console - +![Demo](https://raw.githubusercontent.com/Marak/colors.js/master/screenshots/colors.png) ## Installation @@ -162,6 +162,18 @@ console.log(colors.error("this is an error")); // outputs yellow text console.log(colors.warn("this is a warning")); + ``` -*Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.* \ No newline at end of file +You can also combine them: + +```javascript +colors.setTheme({ + link: ['underline', 'blue'] +}); + +// outputs underlined blue text +console.log(colors.info('Listening on ') + colors.link('http://0.0.0.0:' + port) ); +``` + +*Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.* diff --git a/lib/colors.js b/lib/colors.js index 59898de..790ffd4 100644 --- a/lib/colors.js +++ b/lib/colors.js @@ -48,6 +48,10 @@ colors.stripColors = colors.strip = function(str){ var stylize = colors.stylize = function stylize (str, style) { + if (!colors.enabled) { + return str+''; + } + return ansiStyles[style].open + str + ansiStyles[style].close; } @@ -115,6 +119,13 @@ function applyTheme (theme) { for (var style in theme) { (function(style){ colors[style] = function(str){ + if (typeof theme[style] === 'object'){ + var out = str; + for (var i in theme[style]){ + out = colors[theme[style][i]](out); + } + return out; + } return colors[theme[style]](str); }; })(style) diff --git a/lib/extendStringPrototype.js b/lib/extendStringPrototype.js index b6b5b03..bbb9bcc 100644 --- a/lib/extendStringPrototype.js +++ b/lib/extendStringPrototype.js @@ -1,5 +1,4 @@ -var colors = require('./colors'), - styles = require('./styles'); +var colors = require('./colors'); module['exports'] = function () { @@ -18,10 +17,6 @@ module['exports'] = function () { } }; - var stylize = function stylize (str, style) { - return styles[style].open + str + styles[style].close; - } - addProperty('strip', function () { return colors.strip(this); }); @@ -60,7 +55,7 @@ module['exports'] = function () { var x = Object.keys(colors.styles); x.forEach(function (style) { addProperty(style, function () { - return stylize(this, style); + return colors.stylize(this, style); }); }); diff --git a/lib/index.js b/lib/index.js index 96d2b84..fd0956d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -9,4 +9,4 @@ module['exports'] = colors; // colors.red("foo") // // -var extendStringPrototype = require('./extendStringPrototype')(); \ No newline at end of file +require('./extendStringPrototype')(); \ No newline at end of file diff --git a/package.json b/package.json index dc6ce6b..d759f3b 100644 --- a/package.json +++ b/package.json @@ -17,5 +17,12 @@ "engines": { "node": ">=0.1.90" }, - "main": "./lib/index" + "main": "lib", + "files": [ + "examples", + "lib", + "LICENSE", + "safe.js", + "themes" + ] } diff --git a/screenshots/colors.png b/screenshots/colors.png index 7200a62..6352ae5 100644 Binary files a/screenshots/colors.png and b/screenshots/colors.png differ