mirror of
https://github.com/flynx/colors.js.git
synced 2025-10-29 02:50:10 +00:00
commit
97cc55e8ed
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
**/*.sw*
|
||||||
@ -7,10 +7,10 @@ Here we describe upcoming releases and the key features/fixes they include. Don
|
|||||||
### 1.3.0
|
### 1.3.0
|
||||||
* Support custom colors
|
* Support custom colors
|
||||||
|
|
||||||
### 1.2.1
|
### 1.2.2
|
||||||
* Refactor tests to use a testing library like jest (only affects dev/testing)
|
* 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)
|
### ~~1.2.0 (release date: about 3/5/18, barring any new issues)~~
|
||||||
* Built-in Typescript definitions
|
* ~~Built-in Typescript definitions~~
|
||||||
* Key bug fixes for webpack/bundlers, webstorm, etc.
|
* ~~Key bug fixes for webpack/bundlers, webstorm, etc.~~
|
||||||
|
|
||||||
|
|||||||
2
index.d.ts
vendored
2
index.d.ts
vendored
@ -46,6 +46,8 @@ export interface Color {
|
|||||||
zalgo: Color;
|
zalgo: Color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function enable(): void;
|
||||||
|
export function disable(): void;
|
||||||
export function setTheme(theme: any): void;
|
export function setTheme(theme: any): void;
|
||||||
|
|
||||||
export let enabled: boolean;
|
export let enabled: boolean;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Original Library
|
Original Library
|
||||||
- Copyright (c) Marak Squires
|
- Copyright (c) Marak Squires
|
||||||
|
|
||||||
Additional functionality
|
Additional functionality
|
||||||
@ -33,8 +33,10 @@ module['exports'] = colors;
|
|||||||
|
|
||||||
colors.themes = {};
|
colors.themes = {};
|
||||||
|
|
||||||
|
var util = require('util');
|
||||||
var ansiStyles = colors.styles = require('./styles');
|
var ansiStyles = colors.styles = require('./styles');
|
||||||
var defineProps = Object.defineProperties;
|
var defineProps = Object.defineProperties;
|
||||||
|
var newLineRegex = new RegExp(/[\r\n]+/g);
|
||||||
|
|
||||||
colors.supportsColor = require('./system/supports-colors').supportsColor;
|
colors.supportsColor = require('./system/supports-colors').supportsColor;
|
||||||
|
|
||||||
@ -42,6 +44,14 @@ if (typeof colors.enabled === "undefined") {
|
|||||||
colors.enabled = colors.supportsColor() !== false;
|
colors.enabled = colors.supportsColor() !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
colors.enable = function () {
|
||||||
|
colors.enabled = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
colors.disable = function () {
|
||||||
|
colors.enabled = false;
|
||||||
|
};
|
||||||
|
|
||||||
colors.stripColors = colors.strip = function(str){
|
colors.stripColors = colors.strip = function(str){
|
||||||
return ("" + str).replace(/\x1B\[\d+m/g, '');
|
return ("" + str).replace(/\x1B\[\d+m/g, '');
|
||||||
};
|
};
|
||||||
@ -91,25 +101,27 @@ var styles = (function () {
|
|||||||
var proto = defineProps(function colors() {}, styles);
|
var proto = defineProps(function colors() {}, styles);
|
||||||
|
|
||||||
function applyStyle() {
|
function applyStyle() {
|
||||||
var args = arguments;
|
var args = Array.prototype.slice.call(arguments);
|
||||||
var argsLen = args.length;
|
|
||||||
var str = argsLen !== 0 && String(arguments[0]);
|
var str = args.map(function(arg) {
|
||||||
if (argsLen > 1) {
|
return typeof arg === 'object' ? util.inspect(arg) : arg;
|
||||||
for (var a = 1; a < argsLen; a++) {
|
}).join(' ');
|
||||||
str += ' ' + args[a];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!colors.enabled || !str) {
|
if (!colors.enabled || !str) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var newLinesPresent = str.indexOf('\n') != -1;
|
||||||
|
|
||||||
var nestedStyles = this._styles;
|
var nestedStyles = this._styles;
|
||||||
|
|
||||||
var i = nestedStyles.length;
|
var i = nestedStyles.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
var code = ansiStyles[nestedStyles[i]];
|
var code = ansiStyles[nestedStyles[i]];
|
||||||
str = code.open + str.replace(code.closeRe, code.open) + code.close;
|
str = code.open + str.replace(code.closeRe, code.open) + code.close;
|
||||||
|
if (newLinesPresent){
|
||||||
|
str = str.replace(newLineRegex, code.close + '\n' + code.open);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
|
|||||||
@ -9,14 +9,6 @@ module['exports'] = function () {
|
|||||||
String.prototype.__defineGetter__(color, func);
|
String.prototype.__defineGetter__(color, func);
|
||||||
};
|
};
|
||||||
|
|
||||||
var sequencer = function sequencer (map, str) {
|
|
||||||
return function () {
|
|
||||||
var exploded = this.split(""), i = 0;
|
|
||||||
exploded = exploded.map(map);
|
|
||||||
return exploded.join("");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
addProperty('strip', function () {
|
addProperty('strip', function () {
|
||||||
return colors.strip(this);
|
return colors.strip(this);
|
||||||
});
|
});
|
||||||
@ -67,7 +59,7 @@ module['exports'] = function () {
|
|||||||
var stringPrototypeBlacklist = [
|
var stringPrototypeBlacklist = [
|
||||||
'__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor',
|
'__defineGetter__', '__defineSetter__', '__lookupGetter__', '__lookupSetter__', 'charAt', 'constructor',
|
||||||
'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'toLocaleString', 'toString', 'valueOf', 'charCodeAt',
|
'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'
|
'toLocaleLowerCase', 'toLocaleUpperCase', 'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "colors",
|
"name": "colors",
|
||||||
"description": "get colors in your node.js console",
|
"description": "get colors in your node.js console",
|
||||||
"version": "1.2.1",
|
"version": "1.2.2",
|
||||||
"author": "Marak Squires",
|
"author": "Marak Squires",
|
||||||
"homepage": "https://github.com/Marak/colors.js",
|
"homepage": "https://github.com/Marak/colors.js",
|
||||||
"bugs": "https://github.com/Marak/colors.js/issues",
|
"bugs": "https://github.com/Marak/colors.js/issues",
|
||||||
|
|||||||
3
safe.d.ts
vendored
3
safe.d.ts
vendored
@ -4,6 +4,9 @@
|
|||||||
// Definitions: https://github.com/Marak/colors.js
|
// Definitions: https://github.com/Marak/colors.js
|
||||||
|
|
||||||
export const enabled: boolean;
|
export const enabled: boolean;
|
||||||
|
export function enable(): void;
|
||||||
|
export function disable(): void;
|
||||||
|
export function setTheme(theme: any): void;
|
||||||
|
|
||||||
export function strip(str: string): string;
|
export function strip(str: string): string;
|
||||||
export function stripColors(str: string): string;
|
export function stripColors(str: string): string;
|
||||||
|
|||||||
@ -43,8 +43,19 @@ aE(s, 'yellow', 33);
|
|||||||
|
|
||||||
assert.equal(s, 'string');
|
assert.equal(s, 'string');
|
||||||
|
|
||||||
colors.setTheme({error:'red'});
|
var testStringWithNewLines = s + '\n' + s;
|
||||||
|
|
||||||
assert.equal(typeof("astring".red),'string');
|
// single style
|
||||||
assert.equal(typeof("astring".error),'string');
|
assert.equal(testStringWithNewLines.red, '\x1b[31m' + s + '\n' + s + '\x1b[39m');
|
||||||
|
|
||||||
|
var testStringWithNewLinesStyled = s.underline + '\n' + s.bold;
|
||||||
|
|
||||||
|
// nested styles
|
||||||
|
assert.equal(testStringWithNewLinesStyled.red, '\x1b[31m' + '\x1b[4m' + s + '\x1b[24m' + '\n' + '\x1b[1m' + s + '\x1b[22m' + '\x1b[39m');
|
||||||
|
|
||||||
|
colors.setTheme({ error: 'red' });
|
||||||
|
|
||||||
|
assert.equal(typeof ("astring".red), 'string');
|
||||||
|
assert.equal(typeof ("astring".error), 'string');
|
||||||
|
|
||||||
|
assert.equal(s, 'string');
|
||||||
|
|||||||
@ -39,7 +39,19 @@ aE(s, 'red', 31);
|
|||||||
aE(s, 'yellow', 33);
|
aE(s, 'yellow', 33);
|
||||||
|
|
||||||
assert.equal(s, 'string');
|
assert.equal(s, 'string');
|
||||||
colors.setTheme({error:'red'});
|
|
||||||
|
|
||||||
assert.equal(typeof(colors.red("astring")), 'string');
|
var testStringWithNewLines = s + '\n' + s;
|
||||||
assert.equal(typeof(colors.error("astring")), 'string');
|
|
||||||
|
// single style
|
||||||
|
assert.equal(colors.red(testStringWithNewLines), '\x1b[31m' + s + '\x1b[39m' + '\n' + '\x1b[31m' + s + '\x1b[39m');
|
||||||
|
|
||||||
|
var testStringWithNewLinesStyled = colors.underline(s) + '\n' + colors.bold(s);
|
||||||
|
|
||||||
|
// nested styles
|
||||||
|
assert.equal(colors.red(testStringWithNewLinesStyled), '\x1b[31m' + '\x1b[4m' + s + '\x1b[24m' + '\x1b[39m' + '\n' + '\x1b[31m' + '\x1b[1m' + s + '\x1b[22m' + '\x1b[39m');
|
||||||
|
|
||||||
|
colors.setTheme({ error: 'red' });
|
||||||
|
|
||||||
|
assert.equal(typeof (colors.red("astring")), 'string');
|
||||||
|
assert.equal(typeof (colors.error("astring")), 'string');
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user