Skip to content

Commit

Permalink
Merge pull request #216 from Marak/develop
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
DABH committed Mar 10, 2018
2 parents ecc0adc + e89ff93 commit cc857f2
Show file tree
Hide file tree
Showing 12 changed files with 361 additions and 66 deletions.
4 changes: 4 additions & 0 deletions .npmignore
@@ -0,0 +1,4 @@
# Development files
/tests/
/.travis.yml
/screenshots
5 changes: 5 additions & 0 deletions .travis.yml
@@ -1,5 +1,10 @@
language: node_js
node_js:
- "9"
- "8"
- "7"
- "6"
- "5"
- "4"
- "0.12"
- "0.11"
Expand Down
10 changes: 6 additions & 4 deletions ReadMe.md → README.md
@@ -1,8 +1,10 @@
# 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)

**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).
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

Expand Down
6 changes: 5 additions & 1 deletion examples/normal-usage.js
Expand Up @@ -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);
Expand Down
134 changes: 134 additions & 0 deletions index.d.ts
@@ -0,0 +1,134 @@
// Type definitions for Colors.js 1.2
// Project: https://github.com/Marak/colors.js
// Definitions by: Bart van der Schoor <https://github.com/Bartvds>, Staffan Eketorp <https://github.com/staeke>
// 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;
// @ts-ignore
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;
}
}
30 changes: 11 additions & 19 deletions lib/colors.js
Expand Up @@ -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){
Expand Down Expand Up @@ -115,7 +115,14 @@ function applyStyle() {
return str;
}

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) {
(function(style){
colors[style] = function(str){
Expand All @@ -132,21 +139,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) {
Expand Down Expand Up @@ -184,4 +176,4 @@ for (var map in colors.maps) {
})(map)
}

defineProps(colors, init());
defineProps(colors, init());
4 changes: 2 additions & 2 deletions lib/extendStringPrototype.js
Expand Up @@ -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'
];

Expand Down Expand Up @@ -110,4 +110,4 @@ module['exports'] = function () {
}
};

};
};
23 changes: 23 additions & 0 deletions lib/system/has-flag.js
@@ -0,0 +1,23 @@
/*
MIT License
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (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 = function (flag, argv) {
argv = argv || process.argv;

var terminatorPos = argv.indexOf('--');
var prefix = /^-{1,2}/.test(flag) ? '' : '--';
var pos = argv.indexOf(prefix + flag);

return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
};

0 comments on commit cc857f2

Please sign in to comment.