fix
This commit is contained in:
parent
4c91ef9855
commit
d03611672b
49
main.js
49
main.js
|
@ -1,16 +1,19 @@
|
|||
const fetch = require('node-fetch');
|
||||
const colors = require('colors');
|
||||
|
||||
const myJSON = new Array;
|
||||
myJSON[0] = new Array;
|
||||
myJSON[1] = new Array;
|
||||
const grafana = "0JQGVd17k,2kaHDi9Mk,2unJ5DJnz,4NoNjDNnz,4lYKRi9Gk,5tTwzgsGz,7XcE-x-Wz,8-fqFVkMz,8DAxd31nz,8UMbCpu7k,8pQEQODnz,9H3mUIsMk,9nobGlwnz,AnCRQmA7z,AuTDo9Jnz,BBFXc5sGk,CfZJcWV7k,Cjc6nn-nk,E5_uc4T7z,E7j0G_w7z,F8OlxJo7k,FhqWmeYnz,GNdlFvw7z,II7k2Zrnz,Iao2L197k,Iqd3I5d7z,IsrZyXn7k,Jr24DEB7z,JrpXuDH7k,K0zrySyGk,KBZB1irnz,KgBor-W7z,NILbmd17k,Pj9wvQd7z,PrdD1meWk,RHv9vnYnz,SznAihXnk,T9Ymh_6Gz,T9m5uGEWk,TNS6uzcMk,TT_taT9nk,Tjd73I_7k,TudUK-jnk,U-lYgzxnk,VptulAznk,W2cbuExMk,X6dZrjEGk,XAlCcZA7k,XVvG8IsGz,Xqm6kPonk,ZiXs9VE7z,_QLGJ7wnz,_UeQygu7k,aMO-J8F7k,aPGvnjw7z,bK25D91nz,c0Hrkzunz,c9jJCCx7k,cACgeLWnk,ch4PmVB7k,cv36OPfnk,cw9_1NPGk,erpDsePGz,fCu6VduGz,fXoeoOv7k,fuusUxbnz,g-N7CE57k,gpITUSsGz,hG9phnMnz,hWFz_nm7k,hboD-hu7k,iJE3Ap9nz,iMzV8SsMk,i__5md17k,j8lmJ-Unz,lV3Rg3Jnk,lyqP98f7z,mvnxOoa7z,n-Z8l-B7k,oPW0X9Lnk,p0dM_oa7z,pq29M097z,sGjEGaX7z,tx77ieLnz,uvOwigsMz,w4XEL_xnk,w9w3Uo-7z,whXjzKv7k,wpD7ILrnk,wqH4Y6EMz,xSIMUHB7z,x_kkKL9nk,xoFDqNBnz,yk96BLw7k,zEx8L817z,4UC0PZCnk";
|
||||
const delimiter = ",";
|
||||
const findAll = "vn.client";
|
||||
|
||||
const regexRawSQL = new RegExp(findAll, 'i');
|
||||
const myArray = grafana.split(delimiter);
|
||||
/*https://grafana.verdnatura.es/api/search*/
|
||||
|
||||
async function main(){
|
||||
for (let i=0; i < myArray.length; i++) {
|
||||
|
||||
let percentage = Math.round((i / myArray.length) * 100);
|
||||
|
||||
let url = "https://grafana.verdnatura.es/api/dashboards/uid/" + myArray[i];
|
||||
let response = await fetch(url, {
|
||||
method: "GET",
|
||||
|
@ -19,13 +22,37 @@ async function main(){
|
|||
}
|
||||
});
|
||||
let data = await response.json();
|
||||
let y = i + 1;
|
||||
let dataFiltered = data.filter(function (v){
|
||||
return v.rawQuery
|
||||
});
|
||||
myJSON(i).push(myArray[i]);
|
||||
myJSON(i)(y).push(dataFiltered);
|
||||
/*console.log(data);*/
|
||||
|
||||
let isFound = false;
|
||||
|
||||
const dashboard = data.dashboard;
|
||||
if (dashboard) {
|
||||
if (dashboard.panels)
|
||||
panelsLoop: for (const panel of dashboard.panels)
|
||||
if (panel.targets)
|
||||
for (const target of panel.targets) {
|
||||
isFound = regexRawSQL.test(target.rawSql);
|
||||
if (isFound) break panelsLoop;
|
||||
}
|
||||
|
||||
if (dashboard.templating && !isFound)
|
||||
for (const list of dashboard.templating.list) {
|
||||
isFound = regexRawSQL.test(list.query);
|
||||
if (isFound) break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*console.clear();^
|
||||
console.log("Cargando... " + percentage + "%");
|
||||
console.clear()*/
|
||||
if (isFound)
|
||||
console.log('https://grafana.verdnatura.es/d/' + `${myArray[i]}:`, colors.green(isFound));
|
||||
|
||||
if (!isFound)
|
||||
console.log(`${myArray[i]}:`, colors.red(isFound));
|
||||
}
|
||||
/*console.clear();
|
||||
console.table(myJSON[0][0]);*/
|
||||
}
|
||||
main()
|
||||
main();
|
|
@ -3,6 +3,14 @@
|
|||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/colors": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
|
||||
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==",
|
||||
"engines": {
|
||||
"node": ">=0.1.90"
|
||||
}
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.6.7",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
MIT License
|
||||
|
||||
Original Library
|
||||
- Copyright (c) Marak Squires
|
||||
|
||||
Additional Functionality
|
||||
- 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.
|
|
@ -0,0 +1,221 @@
|
|||
# colors.js
|
||||
[](https://travis-ci.org/Marak/colors.js)
|
||||
[](https://www.npmjs.org/package/colors)
|
||||
[](https://david-dm.org/Marak/colors.js)
|
||||
[](https://david-dm.org/Marak/colors.js#info=devDependencies)
|
||||
|
||||
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
|
||||
|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
npm install colors
|
||||
|
||||
## colors and styles!
|
||||
|
||||
### text colors
|
||||
|
||||
- black
|
||||
- red
|
||||
- green
|
||||
- yellow
|
||||
- blue
|
||||
- magenta
|
||||
- cyan
|
||||
- white
|
||||
- gray
|
||||
- grey
|
||||
|
||||
### bright text colors
|
||||
|
||||
- brightRed
|
||||
- brightGreen
|
||||
- brightYellow
|
||||
- brightBlue
|
||||
- brightMagenta
|
||||
- brightCyan
|
||||
- brightWhite
|
||||
|
||||
### background colors
|
||||
|
||||
- bgBlack
|
||||
- bgRed
|
||||
- bgGreen
|
||||
- bgYellow
|
||||
- bgBlue
|
||||
- bgMagenta
|
||||
- bgCyan
|
||||
- bgWhite
|
||||
- bgGray
|
||||
- bgGrey
|
||||
|
||||
### bright background colors
|
||||
|
||||
- bgBrightRed
|
||||
- bgBrightGreen
|
||||
- bgBrightYellow
|
||||
- bgBrightBlue
|
||||
- bgBrightMagenta
|
||||
- bgBrightCyan
|
||||
- bgBrightWhite
|
||||
|
||||
### styles
|
||||
|
||||
- reset
|
||||
- bold
|
||||
- dim
|
||||
- italic
|
||||
- underline
|
||||
- inverse
|
||||
- hidden
|
||||
- strikethrough
|
||||
|
||||
### extras
|
||||
|
||||
- rainbow
|
||||
- zebra
|
||||
- america
|
||||
- trap
|
||||
- random
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
By popular demand, `colors` now ships with two types of usages!
|
||||
|
||||
The super nifty way
|
||||
|
||||
```js
|
||||
var colors = require('colors');
|
||||
|
||||
console.log('hello'.green); // outputs green text
|
||||
console.log('i like cake and pies'.underline.red) // outputs red underlined text
|
||||
console.log('inverse the color'.inverse); // inverses the color
|
||||
console.log('OMG Rainbows!'.rainbow); // rainbow
|
||||
console.log('Run the trap'.trap); // Drops the bass
|
||||
|
||||
```
|
||||
|
||||
or a slightly less nifty way which doesn't extend `String.prototype`
|
||||
|
||||
```js
|
||||
var colors = require('colors/safe');
|
||||
|
||||
console.log(colors.green('hello')); // outputs green text
|
||||
console.log(colors.red.underline('i like cake and pies')) // outputs red underlined text
|
||||
console.log(colors.inverse('inverse the color')); // inverses the color
|
||||
console.log(colors.rainbow('OMG Rainbows!')); // rainbow
|
||||
console.log(colors.trap('Run the trap')); // Drops the bass
|
||||
|
||||
```
|
||||
|
||||
I prefer the first way. Some people seem to be afraid of extending `String.prototype` and prefer the second way.
|
||||
|
||||
If you are writing good code you will never have an issue with the first approach. If you really don't want to touch `String.prototype`, the second usage will not touch `String` native object.
|
||||
|
||||
## Enabling/Disabling Colors
|
||||
|
||||
The package will auto-detect whether your terminal can use colors and enable/disable accordingly. When colors are disabled, the color functions do nothing. You can override this with a command-line flag:
|
||||
|
||||
```bash
|
||||
node myapp.js --no-color
|
||||
node myapp.js --color=false
|
||||
|
||||
node myapp.js --color
|
||||
node myapp.js --color=true
|
||||
node myapp.js --color=always
|
||||
|
||||
FORCE_COLOR=1 node myapp.js
|
||||
```
|
||||
|
||||
Or in code:
|
||||
|
||||
```javascript
|
||||
var colors = require('colors');
|
||||
colors.enable();
|
||||
colors.disable();
|
||||
```
|
||||
|
||||
## Console.log [string substitution](http://nodejs.org/docs/latest/api/console.html#console_console_log_data)
|
||||
|
||||
```js
|
||||
var name = 'Marak';
|
||||
console.log(colors.green('Hello %s'), name);
|
||||
// outputs -> 'Hello Marak'
|
||||
```
|
||||
|
||||
## Custom themes
|
||||
|
||||
### Using standard API
|
||||
|
||||
```js
|
||||
|
||||
var colors = require('colors');
|
||||
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
console.log("this is an error".error);
|
||||
|
||||
// outputs yellow text
|
||||
console.log("this is a warning".warn);
|
||||
```
|
||||
|
||||
### Using string safe API
|
||||
|
||||
```js
|
||||
var colors = require('colors/safe');
|
||||
|
||||
// set single property
|
||||
var error = colors.red;
|
||||
error('this is red');
|
||||
|
||||
// set theme
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red'
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
console.log(colors.error("this is an error"));
|
||||
|
||||
// outputs yellow text
|
||||
console.log(colors.warn("this is a warning"));
|
||||
|
||||
```
|
||||
|
||||
### Combining Colors
|
||||
|
||||
```javascript
|
||||
var colors = require('colors');
|
||||
|
||||
colors.setTheme({
|
||||
custom: ['red', 'underline']
|
||||
});
|
||||
|
||||
console.log('test'.custom);
|
||||
```
|
||||
|
||||
*Protip: There is a secret undocumented style in `colors`. If you find the style you can summon him.*
|
|
@ -0,0 +1,82 @@
|
|||
var colors = require('../lib/index');
|
||||
|
||||
console.log('First some yellow text'.yellow);
|
||||
|
||||
console.log('Underline that text'.yellow.underline);
|
||||
|
||||
console.log('Make it bold and red'.red.bold);
|
||||
|
||||
console.log(('Double Raindows All Day Long').rainbow);
|
||||
|
||||
console.log('Drop the bass'.trap);
|
||||
|
||||
console.log('DROP THE RAINBOW BASS'.trap.rainbow);
|
||||
|
||||
// styles not widely supported
|
||||
console.log('Chains are also cool.'.bold.italic.underline.red);
|
||||
|
||||
// styles not widely supported
|
||||
console.log('So '.green + 'are'.underline + ' ' + 'inverse'.inverse
|
||||
+ ' styles! '.yellow.bold);
|
||||
console.log('Zebras are so fun!'.zebra);
|
||||
|
||||
//
|
||||
// Remark: .strikethrough may not work with Mac OS Terminal App
|
||||
//
|
||||
console.log('This is ' + 'not'.strikethrough + ' fun.');
|
||||
|
||||
console.log('Background color attack!'.black.bgWhite);
|
||||
console.log('Use random styles on everything!'.random);
|
||||
console.log('America, Heck Yeah!'.america);
|
||||
|
||||
console.log('Blindingly '.brightCyan + 'bright? '.brightRed + 'Why '.brightYellow + 'not?!'.brightGreen);
|
||||
|
||||
console.log('Setting themes is useful');
|
||||
|
||||
//
|
||||
// Custom themes
|
||||
//
|
||||
console.log('Generic logging theme as JSON'.green.bold.underline);
|
||||
// Load theme with JSON literal
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red',
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
console.log('this is an error'.error);
|
||||
|
||||
// outputs yellow text
|
||||
console.log('this is a warning'.warn);
|
||||
|
||||
// outputs grey text
|
||||
console.log('this is an input'.input);
|
||||
|
||||
console.log('Generic logging theme as file'.green.bold.underline);
|
||||
|
||||
// Load a theme from file
|
||||
try {
|
||||
colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
// outputs red text
|
||||
console.log('this is an error'.error);
|
||||
|
||||
// outputs yellow text
|
||||
console.log('this is a warning'.warn);
|
||||
|
||||
// outputs grey text
|
||||
console.log('this is an input'.input);
|
||||
|
||||
// console.log("Don't summon".zalgo)
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
var colors = require('../safe');
|
||||
|
||||
console.log(colors.yellow('First some yellow text'));
|
||||
|
||||
console.log(colors.yellow.underline('Underline that text'));
|
||||
|
||||
console.log(colors.red.bold('Make it bold and red'));
|
||||
|
||||
console.log(colors.rainbow('Double Raindows All Day Long'));
|
||||
|
||||
console.log(colors.trap('Drop the bass'));
|
||||
|
||||
console.log(colors.rainbow(colors.trap('DROP THE RAINBOW BASS')));
|
||||
|
||||
// styles not widely supported
|
||||
console.log(colors.bold.italic.underline.red('Chains are also cool.'));
|
||||
|
||||
// styles not widely supported
|
||||
console.log(colors.green('So ') + colors.underline('are') + ' '
|
||||
+ colors.inverse('inverse') + colors.yellow.bold(' styles! '));
|
||||
|
||||
console.log(colors.zebra('Zebras are so fun!'));
|
||||
|
||||
console.log('This is ' + colors.strikethrough('not') + ' fun.');
|
||||
|
||||
|
||||
console.log(colors.black.bgWhite('Background color attack!'));
|
||||
console.log(colors.random('Use random styles on everything!'));
|
||||
console.log(colors.america('America, Heck Yeah!'));
|
||||
|
||||
console.log(colors.brightCyan('Blindingly ') + colors.brightRed('bright? ') + colors.brightYellow('Why ') + colors.brightGreen('not?!'));
|
||||
|
||||
console.log('Setting themes is useful');
|
||||
|
||||
//
|
||||
// Custom themes
|
||||
//
|
||||
// console.log('Generic logging theme as JSON'.green.bold.underline);
|
||||
// Load theme with JSON literal
|
||||
colors.setTheme({
|
||||
silly: 'rainbow',
|
||||
input: 'blue',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red',
|
||||
});
|
||||
|
||||
// outputs red text
|
||||
console.log(colors.error('this is an error'));
|
||||
|
||||
// outputs yellow text
|
||||
console.log(colors.warn('this is a warning'));
|
||||
|
||||
// outputs blue text
|
||||
console.log(colors.input('this is an input'));
|
||||
|
||||
|
||||
// console.log('Generic logging theme as file'.green.bold.underline);
|
||||
|
||||
// Load a theme from file
|
||||
colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));
|
||||
|
||||
// outputs red text
|
||||
console.log(colors.error('this is an error'));
|
||||
|
||||
// outputs yellow text
|
||||
console.log(colors.warn('this is a warning'));
|
||||
|
||||
// outputs grey text
|
||||
console.log(colors.input('this is an input'));
|
||||
|
||||
// console.log(colors.zalgo("Don't summon him"))
|
||||
|
||||
|
|
@ -0,0 +1,136 @@
|
|||
// 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 enable(): void;
|
||||
export function disable(): void;
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,211 @@
|
|||
/*
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Original Library
|
||||
- Copyright (c) Marak Squires
|
||||
|
||||
Additional functionality
|
||||
- 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.
|
||||
|
||||
*/
|
||||
|
||||
var colors = {};
|
||||
module['exports'] = colors;
|
||||
|
||||
colors.themes = {};
|
||||
|
||||
var util = require('util');
|
||||
var ansiStyles = colors.styles = require('./styles');
|
||||
var defineProps = Object.defineProperties;
|
||||
var newLineRegex = new RegExp(/[\r\n]+/g);
|
||||
|
||||
colors.supportsColor = require('./system/supports-colors').supportsColor;
|
||||
|
||||
if (typeof colors.enabled === 'undefined') {
|
||||
colors.enabled = colors.supportsColor() !== false;
|
||||
}
|
||||
|
||||
colors.enable = function() {
|
||||
colors.enabled = true;
|
||||
};
|
||||
|
||||
colors.disable = function() {
|
||||
colors.enabled = false;
|
||||
};
|
||||
|
||||
colors.stripColors = colors.strip = function(str) {
|
||||
return ('' + str).replace(/\x1B\[\d+m/g, '');
|
||||
};
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
var stylize = colors.stylize = function stylize(str, style) {
|
||||
if (!colors.enabled) {
|
||||
return str+'';
|
||||
}
|
||||
|
||||
var styleMap = ansiStyles[style];
|
||||
|
||||
// Stylize should work for non-ANSI styles, too
|
||||
if(!styleMap && style in colors){
|
||||
// Style maps like trap operate as functions on strings;
|
||||
// they don't have properties like open or close.
|
||||
return colors[style](str);
|
||||
}
|
||||
|
||||
return styleMap.open + str + styleMap.close;
|
||||
};
|
||||
|
||||
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
|
||||
var escapeStringRegexp = function(str) {
|
||||
if (typeof str !== 'string') {
|
||||
throw new TypeError('Expected a string');
|
||||
}
|
||||
return str.replace(matchOperatorsRe, '\\$&');
|
||||
};
|
||||
|
||||
function build(_styles) {
|
||||
var builder = function builder() {
|
||||
return applyStyle.apply(builder, arguments);
|
||||
};
|
||||
builder._styles = _styles;
|
||||
// __proto__ is used because we must return a function, but there is
|
||||
// no way to create a function with a different prototype.
|
||||
builder.__proto__ = proto;
|
||||
return builder;
|
||||
}
|
||||
|
||||
var styles = (function() {
|
||||
var ret = {};
|
||||
ansiStyles.grey = ansiStyles.gray;
|
||||
Object.keys(ansiStyles).forEach(function(key) {
|
||||
ansiStyles[key].closeRe =
|
||||
new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
|
||||
ret[key] = {
|
||||
get: function() {
|
||||
return build(this._styles.concat(key));
|
||||
},
|
||||
};
|
||||
});
|
||||
return ret;
|
||||
})();
|
||||
|
||||
var proto = defineProps(function colors() {}, styles);
|
||||
|
||||
function applyStyle() {
|
||||
var args = Array.prototype.slice.call(arguments);
|
||||
|
||||
var str = args.map(function(arg) {
|
||||
// Use weak equality check so we can colorize null/undefined in safe mode
|
||||
if (arg != null && arg.constructor === String) {
|
||||
return arg;
|
||||
} else {
|
||||
return util.inspect(arg);
|
||||
}
|
||||
}).join(' ');
|
||||
|
||||
if (!colors.enabled || !str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
var newLinesPresent = str.indexOf('\n') != -1;
|
||||
|
||||
var nestedStyles = this._styles;
|
||||
|
||||
var i = nestedStyles.length;
|
||||
while (i--) {
|
||||
var code = ansiStyles[nestedStyles[i]];
|
||||
str = code.open + str.replace(code.closeRe, code.open) + code.close;
|
||||
if (newLinesPresent) {
|
||||
str = str.replace(newLineRegex, function(match) {
|
||||
return code.close + match + code.open;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
var ret = {};
|
||||
Object.keys(styles).forEach(function(name) {
|
||||
ret[name] = {
|
||||
get: function() {
|
||||
return build([name]);
|
||||
},
|
||||
};
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
var sequencer = function sequencer(map, str) {
|
||||
var exploded = str.split('');
|
||||
exploded = exploded.map(map);
|
||||
return exploded.join('');
|
||||
};
|
||||
|
||||
// custom formatter methods
|
||||
colors.trap = require('./custom/trap');
|
||||
colors.zalgo = require('./custom/zalgo');
|
||||
|
||||
// maps
|
||||
colors.maps = {};
|
||||
colors.maps.america = require('./maps/america')(colors);
|
||||
colors.maps.zebra = require('./maps/zebra')(colors);
|
||||
colors.maps.rainbow = require('./maps/rainbow')(colors);
|
||||
colors.maps.random = require('./maps/random')(colors);
|
||||
|
||||
for (var map in colors.maps) {
|
||||
(function(map) {
|
||||
colors[map] = function(str) {
|
||||
return sequencer(colors.maps[map], str);
|
||||
};
|
||||
})(map);
|
||||
}
|
||||
|
||||
defineProps(colors, init());
|
|
@ -0,0 +1,46 @@
|
|||
module['exports'] = function runTheTrap(text, options) {
|
||||
var result = '';
|
||||
text = text || 'Run the trap, drop the bass';
|
||||
text = text.split('');
|
||||
var trap = {
|
||||
a: ['\u0040', '\u0104', '\u023a', '\u0245', '\u0394', '\u039b', '\u0414'],
|
||||
b: ['\u00df', '\u0181', '\u0243', '\u026e', '\u03b2', '\u0e3f'],
|
||||
c: ['\u00a9', '\u023b', '\u03fe'],
|
||||
d: ['\u00d0', '\u018a', '\u0500', '\u0501', '\u0502', '\u0503'],
|
||||
e: ['\u00cb', '\u0115', '\u018e', '\u0258', '\u03a3', '\u03be', '\u04bc',
|
||||
'\u0a6c'],
|
||||
f: ['\u04fa'],
|
||||
g: ['\u0262'],
|
||||
h: ['\u0126', '\u0195', '\u04a2', '\u04ba', '\u04c7', '\u050a'],
|
||||
i: ['\u0f0f'],
|
||||
j: ['\u0134'],
|
||||
k: ['\u0138', '\u04a0', '\u04c3', '\u051e'],
|
||||
l: ['\u0139'],
|
||||
m: ['\u028d', '\u04cd', '\u04ce', '\u0520', '\u0521', '\u0d69'],
|
||||
n: ['\u00d1', '\u014b', '\u019d', '\u0376', '\u03a0', '\u048a'],
|
||||
o: ['\u00d8', '\u00f5', '\u00f8', '\u01fe', '\u0298', '\u047a', '\u05dd',
|
||||
'\u06dd', '\u0e4f'],
|
||||
p: ['\u01f7', '\u048e'],
|
||||
q: ['\u09cd'],
|
||||
r: ['\u00ae', '\u01a6', '\u0210', '\u024c', '\u0280', '\u042f'],
|
||||
s: ['\u00a7', '\u03de', '\u03df', '\u03e8'],
|
||||
t: ['\u0141', '\u0166', '\u0373'],
|
||||
u: ['\u01b1', '\u054d'],
|
||||
v: ['\u05d8'],
|
||||
w: ['\u0428', '\u0460', '\u047c', '\u0d70'],
|
||||
x: ['\u04b2', '\u04fe', '\u04fc', '\u04fd'],
|
||||
y: ['\u00a5', '\u04b0', '\u04cb'],
|
||||
z: ['\u01b5', '\u0240'],
|
||||
};
|
||||
text.forEach(function(c) {
|
||||
c = c.toLowerCase();
|
||||
var chars = trap[c] || [' '];
|
||||
var rand = Math.floor(Math.random() * chars.length);
|
||||
if (typeof trap[c] !== 'undefined') {
|
||||
result += trap[c][rand];
|
||||
} else {
|
||||
result += c;
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
|
@ -0,0 +1,110 @@
|
|||
// please no
|
||||
module['exports'] = function zalgo(text, options) {
|
||||
text = text || ' he is here ';
|
||||
var soul = {
|
||||
'up': [
|
||||
'̍', '̎', '̄', '̅',
|
||||
'̿', '̑', '̆', '̐',
|
||||
'͒', '͗', '͑', '̇',
|
||||
'̈', '̊', '͂', '̓',
|
||||
'̈', '͊', '͋', '͌',
|
||||
'̃', '̂', '̌', '͐',
|
||||
'̀', '́', '̋', '̏',
|
||||
'̒', '̓', '̔', '̽',
|
||||
'̉', 'ͣ', 'ͤ', 'ͥ',
|
||||
'ͦ', 'ͧ', 'ͨ', 'ͩ',
|
||||
'ͪ', 'ͫ', 'ͬ', 'ͭ',
|
||||
'ͮ', 'ͯ', '̾', '͛',
|
||||
'͆', '̚',
|
||||
],
|
||||
'down': [
|
||||
'̖', '̗', '̘', '̙',
|
||||
'̜', '̝', '̞', '̟',
|
||||
'̠', '̤', '̥', '̦',
|
||||
'̩', '̪', '̫', '̬',
|
||||
'̭', '̮', '̯', '̰',
|
||||
'̱', '̲', '̳', '̹',
|
||||
'̺', '̻', '̼', 'ͅ',
|
||||
'͇', '͈', '͉', '͍',
|
||||
'͎', '͓', '͔', '͕',
|
||||
'͖', '͙', '͚', '̣',
|
||||
],
|
||||
'mid': [
|
||||
'̕', '̛', '̀', '́',
|
||||
'͘', '̡', '̢', '̧',
|
||||
'̨', '̴', '̵', '̶',
|
||||
'͜', '͝', '͞',
|
||||
'͟', '͠', '͢', '̸',
|
||||
'̷', '͡', ' ҉',
|
||||
],
|
||||
};
|
||||
var all = [].concat(soul.up, soul.down, soul.mid);
|
||||
|
||||
function randomNumber(range) {
|
||||
var r = Math.floor(Math.random() * range);
|
||||
return r;
|
||||
}
|
||||
|
||||
function isChar(character) {
|
||||
var bool = false;
|
||||
all.filter(function(i) {
|
||||
bool = (i === character);
|
||||
});
|
||||
return bool;
|
||||
}
|
||||
|
||||
|
||||
function heComes(text, options) {
|
||||
var result = '';
|
||||
var counts;
|
||||
var l;
|
||||
options = options || {};
|
||||
options['up'] =
|
||||
typeof options['up'] !== 'undefined' ? options['up'] : true;
|
||||
options['mid'] =
|
||||
typeof options['mid'] !== 'undefined' ? options['mid'] : true;
|
||||
options['down'] =
|
||||
typeof options['down'] !== 'undefined' ? options['down'] : true;
|
||||
options['size'] =
|
||||
typeof options['size'] !== 'undefined' ? options['size'] : 'maxi';
|
||||
text = text.split('');
|
||||
for (l in text) {
|
||||
if (isChar(l)) {
|
||||
continue;
|
||||
}
|
||||
result = result + text[l];
|
||||
counts = {'up': 0, 'down': 0, 'mid': 0};
|
||||
switch (options.size) {
|
||||
case 'mini':
|
||||
counts.up = randomNumber(8);
|
||||
counts.mid = randomNumber(2);
|
||||
counts.down = randomNumber(8);
|
||||
break;
|
||||
case 'maxi':
|
||||
counts.up = randomNumber(16) + 3;
|
||||
counts.mid = randomNumber(4) + 1;
|
||||
counts.down = randomNumber(64) + 3;
|
||||
break;
|
||||
default:
|
||||
counts.up = randomNumber(8) + 1;
|
||||
counts.mid = randomNumber(6) / 2;
|
||||
counts.down = randomNumber(8) + 1;
|
||||
break;
|
||||
}
|
||||
|
||||
var arr = ['up', 'mid', 'down'];
|
||||
for (var d in arr) {
|
||||
var index = arr[d];
|
||||
for (var i = 0; i <= counts[index]; i++) {
|
||||
if (options[index]) {
|
||||
result = result + soul[index][randomNumber(soul[index].length)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
// don't summon him
|
||||
return heComes(text, options);
|
||||
};
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
var colors = require('./colors');
|
||||
|
||||
module['exports'] = function() {
|
||||
//
|
||||
// Extends prototype of native string object to allow for "foo".red syntax
|
||||
//
|
||||
var addProperty = function(color, func) {
|
||||
String.prototype.__defineGetter__(color, func);
|
||||
};
|
||||
|
||||
addProperty('strip', function() {
|
||||
return colors.strip(this);
|
||||
});
|
||||
|
||||
addProperty('stripColors', function() {
|
||||
return colors.strip(this);
|
||||
});
|
||||
|
||||
addProperty('trap', function() {
|
||||
return colors.trap(this);
|
||||
});
|
||||
|
||||
addProperty('zalgo', function() {
|
||||
return colors.zalgo(this);
|
||||
});
|
||||
|
||||
addProperty('zebra', function() {
|
||||
return colors.zebra(this);
|
||||
});
|
||||
|
||||
addProperty('rainbow', function() {
|
||||
return colors.rainbow(this);
|
||||
});
|
||||
|
||||
addProperty('random', function() {
|
||||
return colors.random(this);
|
||||
});
|
||||
|
||||
addProperty('america', function() {
|
||||
return colors.america(this);
|
||||
});
|
||||
|
||||
//
|
||||
// Iterate through all default styles and colors
|
||||
//
|
||||
var x = Object.keys(colors.styles);
|
||||
x.forEach(function(style) {
|
||||
addProperty(style, function() {
|
||||
return colors.stylize(this, style);
|
||||
});
|
||||
});
|
||||
|
||||
function applyTheme(theme) {
|
||||
//
|
||||
// Remark: This is a list of methods that exist
|
||||
// on String that you should not overwrite.
|
||||
//
|
||||
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', 'toLocaleLowerCase', 'toLocaleUpperCase',
|
||||
'toLowerCase', 'toUpperCase', 'trim', 'trimLeft', 'trimRight',
|
||||
];
|
||||
|
||||
Object.keys(theme).forEach(function(prop) {
|
||||
if (stringPrototypeBlacklist.indexOf(prop) !== -1) {
|
||||
console.log('warn: '.red + ('String.prototype' + prop).magenta +
|
||||
' is probably something you don\'t want to override. ' +
|
||||
'Ignoring style name');
|
||||
} else {
|
||||
if (typeof(theme[prop]) === 'string') {
|
||||
colors[prop] = colors[theme[prop]];
|
||||
addProperty(prop, function() {
|
||||
return colors[prop](this);
|
||||
});
|
||||
} else {
|
||||
var themePropApplicator = function(str) {
|
||||
var ret = str || this;
|
||||
for (var t = 0; t < theme[prop].length; t++) {
|
||||
ret = colors[theme[prop][t]](ret);
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
addProperty(prop, themePropApplicator);
|
||||
colors[prop] = function(str) {
|
||||
return themePropApplicator(str);
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
} else {
|
||||
applyTheme(theme);
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,13 @@
|
|||
var colors = require('./colors');
|
||||
module['exports'] = colors;
|
||||
|
||||
// Remark: By default, colors will add style properties to String.prototype.
|
||||
//
|
||||
// If you don't wish to extend String.prototype, you can do this instead and
|
||||
// native String will not be touched:
|
||||
//
|
||||
// var colors = require('colors/safe);
|
||||
// colors.red("foo")
|
||||
//
|
||||
//
|
||||
require('./extendStringPrototype')();
|
|
@ -0,0 +1,10 @@
|
|||
module['exports'] = function(colors) {
|
||||
return function(letter, i, exploded) {
|
||||
if (letter === ' ') return letter;
|
||||
switch (i%3) {
|
||||
case 0: return colors.red(letter);
|
||||
case 1: return colors.white(letter);
|
||||
case 2: return colors.blue(letter);
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,12 @@
|
|||
module['exports'] = function(colors) {
|
||||
// RoY G BiV
|
||||
var rainbowColors = ['red', 'yellow', 'green', 'blue', 'magenta'];
|
||||
return function(letter, i, exploded) {
|
||||
if (letter === ' ') {
|
||||
return letter;
|
||||
} else {
|
||||
return colors[rainbowColors[i++ % rainbowColors.length]](letter);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
module['exports'] = function(colors) {
|
||||
var available = ['underline', 'inverse', 'grey', 'yellow', 'red', 'green',
|
||||
'blue', 'white', 'cyan', 'magenta', 'brightYellow', 'brightRed',
|
||||
'brightGreen', 'brightBlue', 'brightWhite', 'brightCyan', 'brightMagenta'];
|
||||
return function(letter, i, exploded) {
|
||||
return letter === ' ' ? letter :
|
||||
colors[
|
||||
available[Math.round(Math.random() * (available.length - 2))]
|
||||
](letter);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
module['exports'] = function(colors) {
|
||||
return function(letter, i, exploded) {
|
||||
return i % 2 === 0 ? letter : colors.inverse(letter);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
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.
|
||||
|
||||
*/
|
||||
|
||||
var styles = {};
|
||||
module['exports'] = styles;
|
||||
|
||||
var codes = {
|
||||
reset: [0, 0],
|
||||
|
||||
bold: [1, 22],
|
||||
dim: [2, 22],
|
||||
italic: [3, 23],
|
||||
underline: [4, 24],
|
||||
inverse: [7, 27],
|
||||
hidden: [8, 28],
|
||||
strikethrough: [9, 29],
|
||||
|
||||
black: [30, 39],
|
||||
red: [31, 39],
|
||||
green: [32, 39],
|
||||
yellow: [33, 39],
|
||||
blue: [34, 39],
|
||||
magenta: [35, 39],
|
||||
cyan: [36, 39],
|
||||
white: [37, 39],
|
||||
gray: [90, 39],
|
||||
grey: [90, 39],
|
||||
|
||||
brightRed: [91, 39],
|
||||
brightGreen: [92, 39],
|
||||
brightYellow: [93, 39],
|
||||
brightBlue: [94, 39],
|
||||
brightMagenta: [95, 39],
|
||||
brightCyan: [96, 39],
|
||||
brightWhite: [97, 39],
|
||||
|
||||
bgBlack: [40, 49],
|
||||
bgRed: [41, 49],
|
||||
bgGreen: [42, 49],
|
||||
bgYellow: [43, 49],
|
||||
bgBlue: [44, 49],
|
||||
bgMagenta: [45, 49],
|
||||
bgCyan: [46, 49],
|
||||
bgWhite: [47, 49],
|
||||
bgGray: [100, 49],
|
||||
bgGrey: [100, 49],
|
||||
|
||||
bgBrightRed: [101, 49],
|
||||
bgBrightGreen: [102, 49],
|
||||
bgBrightYellow: [103, 49],
|
||||
bgBrightBlue: [104, 49],
|
||||
bgBrightMagenta: [105, 49],
|
||||
bgBrightCyan: [106, 49],
|
||||
bgBrightWhite: [107, 49],
|
||||
|
||||
// legacy styles for colors pre v1.0.0
|
||||
blackBG: [40, 49],
|
||||
redBG: [41, 49],
|
||||
greenBG: [42, 49],
|
||||
yellowBG: [43, 49],
|
||||
blueBG: [44, 49],
|
||||
magentaBG: [45, 49],
|
||||
cyanBG: [46, 49],
|
||||
whiteBG: [47, 49],
|
||||
|
||||
};
|
||||
|
||||
Object.keys(codes).forEach(function(key) {
|
||||
var val = codes[key];
|
||||
var style = styles[key] = [];
|
||||
style.open = '\u001b[' + val[0] + 'm';
|
||||
style.close = '\u001b[' + val[1] + 'm';
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
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,0 +1,151 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
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';
|
||||
|
||||
var os = require('os');
|
||||
var hasFlag = require('./has-flag.js');
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return {
|
||||
level: level,
|
||||
hasBasic: true,
|
||||
has256: level >= 2,
|
||||
has16m: level >= 3,
|
||||
};
|
||||
}
|
||||
|
||||
function supportsColor(stream) {
|
||||
if (forceColor === false) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (hasFlag('color=16m') || hasFlag('color=full')
|
||||
|| hasFlag('color=truecolor')) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
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),
|
||||
};
|
|
@ -0,0 +1,45 @@
|
|||
{
|
||||
"name": "colors",
|
||||
"description": "get colors in your node.js console",
|
||||
"version": "1.4.0",
|
||||
"author": "Marak Squires",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "DABH",
|
||||
"url": "https://github.com/DABH"
|
||||
}
|
||||
],
|
||||
"homepage": "https://github.com/Marak/colors.js",
|
||||
"bugs": "https://github.com/Marak/colors.js/issues",
|
||||
"keywords": [
|
||||
"ansi",
|
||||
"terminal",
|
||||
"colors"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "http://github.com/Marak/colors.js.git"
|
||||
},
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"lint": "eslint . --fix",
|
||||
"test": "node tests/basic-test.js && node tests/safe-test.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.1.90"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"files": [
|
||||
"examples",
|
||||
"lib",
|
||||
"LICENSE",
|
||||
"safe.js",
|
||||
"themes",
|
||||
"index.d.ts",
|
||||
"safe.d.ts"
|
||||
],
|
||||
"devDependencies": {
|
||||
"eslint": "^5.2.0",
|
||||
"eslint-config-google": "^0.11.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
// 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 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 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;
|
|
@ -0,0 +1,10 @@
|
|||
//
|
||||
// Remark: Requiring this file will use the "safe" colors API,
|
||||
// which will not touch String.prototype.
|
||||
//
|
||||
// var colors = require('colors/safe');
|
||||
// colors.red("foo")
|
||||
//
|
||||
//
|
||||
var colors = require('./lib/colors');
|
||||
module['exports'] = colors;
|
|
@ -0,0 +1,12 @@
|
|||
module['exports'] = {
|
||||
silly: 'rainbow',
|
||||
input: 'grey',
|
||||
verbose: 'cyan',
|
||||
prompt: 'grey',
|
||||
info: 'green',
|
||||
data: 'grey',
|
||||
help: 'cyan',
|
||||
warn: 'yellow',
|
||||
debug: 'blue',
|
||||
error: 'red',
|
||||
};
|
|
@ -5,9 +5,18 @@
|
|||
"packages": {
|
||||
"": {
|
||||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
"node-fetch": "^2.6.7"
|
||||
}
|
||||
},
|
||||
"node_modules/colors": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
|
||||
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==",
|
||||
"engines": {
|
||||
"node": ">=0.1.90"
|
||||
}
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.6.7",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
|
||||
|
@ -48,6 +57,11 @@
|
|||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"colors": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
|
||||
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "2.6.7",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz",
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
"node-fetch": "^2.6.7"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue