Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

excolor

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

excolor - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

.eslintrc.cjs

26

example.js

@@ -88,1 +88,27 @@ "use strict";

logs("%[strike]strike");
logs("\n256 color mode table");
logs("----------");
const color = ["white", "black"];
let c = color[0], count = 1;
for (let i = 0; i <= 255; i++) {
if ((i >= 0 && i <= 6) || (i >= 232 && i <= 243)) c = color[0];
if (i >= 7 && i <= 15 || (i >= 244 && i <= 255)) c = color[1];
if (i >= 16 && i <= 231) {
c = (count <= 18) ? color[0] : color[1];
count = (count === 36) ? 1 : count + 1;
}
logs(`%[fg256(${i})]Color ${i} %[${c}|bg256(${i})]Background ${i}`);
}
logs("\nTrue color");
logs("----------");
logs("%[rgb(255,151,0)]This line of text is colored rgb(255,151,0)");
logs("%[bgRgb(69,42,4)|white]This line of text has a background color of bgRgb(69,42,4)");
logs("%[hex(#1F44A7)]This line of text is colored hex(#1F44A7)");
logs("%[bgHex(#7A0000)|hex(#ee3)]This line of text has a background color of bgHex(#7A0000) and color hex(#ee3)");

119

index.js

@@ -38,11 +38,7 @@ const logs = (message, type = "log") => {

result = (i > 4) ? i + 2 : i + 1;
if (result === 0) {
result = null;
}
if (result === 0) result = null;
break;
case 5:
result = (i > 4) ? i + 22 : i + 21;
if (result === 0) {
result = null;
}
if (result === 0) result = null;
break;

@@ -54,6 +50,32 @@ }

function extractRGB(m) {
return [parseInt(m[1], 10), parseInt(m[2], 10), parseInt(m[3], 10)]
.map(v => (v >= 0 && v <= 255) ? v : 0);
}
function hexTOrgb(value) {
let rgb = [0, 0, 0];
if (value.length === 3) {
rgb = [
parseInt(value[0] + value[0], 16),
parseInt(value[1] + value[1], 16),
parseInt(value[2] + value[2], 16)
];
} else {
rgb = [
parseInt(value[0] + value[1], 16),
parseInt(value[2] + value[3], 16),
parseInt(value[4] + value[5], 16)
];
}
return rgb;
}
function sequence(value) {
let
serie = [],
sequence = []
sequence = [],
x256 = null
;

@@ -66,2 +88,54 @@

for (let item of params) {
let rgb = [0, 0, 0];
const
hexPattern = /^hex\(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})\)$/,
hexmatch = item.match(hexPattern),
bghexPattern = /^bgHex\(#([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})\)$/,
bghexmatch = item.match(bghexPattern),
rgbPattern = /^rgb\s*\(\s*(\d{1,3})\s*[,;:]\s*(\d{1,3})\s*[,;:]\s*(\d{1,3})\s*\)$/,
rgbmatch = item.match(rgbPattern),
bgrgbPattern = /^bgRgb\s*\(\s*(\d{1,3})\s*[,;:]\s*(\d{1,3})\s*[,;:]\s*(\d{1,3})\s*\)$/,
bgrgbmatch = item.match(bgrgbPattern),
fg256Pattern = /^fg256\((\d{1,3})\)$/,
fg256match = item.match(fg256Pattern),
bg256Pattern = /^bg256\((\d{1,3})\)$/,
bg256match = item.match(bg256Pattern)
;
if (fg256match) {
x256 = parseInt(fg256match[1], 10);
if ((x256 >= 0 && x256 <= 255)) item = "fg256";
}
if (bg256match) {
x256 = parseInt(bg256match[1], 10);
if ((x256 >= 0 && x256 <= 255)) item = "bg256";
}
if (rgbmatch) {
rgb = extractRGB(rgbmatch);
item = "fg";
}
if (bgrgbmatch) {
rgb = extractRGB(bgrgbmatch);
item = "bg";
}
if (hexmatch) {
rgb = hexTOrgb(hexmatch[1]);
item = "fg";
}
if (bghexmatch) {
rgb = hexTOrgb(bghexmatch[1]);
item = "bg";
}
switch (item) {

@@ -89,2 +163,14 @@ case "normal":

break;
case "fg256":
serie.push(`38;5;${x256}`);
break;
case "bg256":
serie.push(`48;5;${x256}`);
break;
case "fg":
serie.push(`38;2;${rgb[0]};${rgb[1]};${rgb[2]}`);
break;
case "bg":
serie.push(`48;2;${rgb[0]};${rgb[1]};${rgb[2]}`);
break;
default:

@@ -102,3 +188,2 @@ serie.push(get_value_expresion(item, fg)); // Color

sequence = serie.filter(ele => ele !== null);
return s + sequence.join(";") + f;

@@ -143,21 +228,5 @@ }

switch (type) {
case "log":
console.log(init() + r);
break;
case "info":
console.info(init() + r);
break;
case "error":
console.error(init() + r);
break;
case "debug":
console.debug(init() + r);
break;
default:
console.log(init() + r);
break;
}
console[type](init() + r);
};
module.exports = logs;
{
"name": "excolor",
"version": "1.0.3",
"version": "1.1.0",
"description": "This package allows you to easily set text with colors, background colors, and effects in your terminal. With this package, you can customize your messages and make your terminal more visually appealing and easy to read.",

@@ -28,3 +28,2 @@ "main": "index.js",

"shell",
"command line",
"command-line",

@@ -38,3 +37,8 @@ "text"

},
"homepage": "https://github.com/esutoraiki/excolor#readme"
"homepage": "https://github.com/esutoraiki/excolor#readme",
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.14.0",
"globals": "^15.12.0"
}
}
# exColor
This package allows you to easily set text with colors, background colors, and effects in your terminal. With this package, you can customize your messages and make your terminal more visually appealing and easy to read.
`exColor` is a package that allows you to easily apply text colors, background colors, and effects in your terminal. With this package, you can customize your messages to make your terminal output more visually appealing and readable.
## Requirements
- Minimum Node v16.7.0
| **Technology** | **Version** |
| -------------- | ---------------- |
| Node | 16.7.0 or higher |
| NPM | 10.8.2 |

@@ -21,7 +24,188 @@ ## Installation

To use exColor with ES6 syntax, you can do so as follows:
To use `exColor` with ES6 syntax, you can do so as follows:
```js
import logs from "excolor"
import logs from "excolor";
logs("%[yellow] Hello world of color ");
```
You can combine different color and effect operators in a single `exColor` string by separating them with the `|` character. This feature allows you to apply multiple styles simultaneously, creating custom text combinations.
In the example:
```js
import logs from "excolor";
logs("%[yellowBright|bgRed|blink] Hello world of color ");
```
The following operators are combined:
- **`yellowBright`**: Applies a bright yellow text color.
- **`bgRed`**: Sets a red background.
- **`blink`**: Makes the text blink.
This combination creates text with bright yellow color on a red background that blinks. You can mix any number of color operators (foreground and background) and effects (like `bold`, `italic`, `underline`, etc.) to achieve the desired style.
This flexibility allows you to create complex and styled text outputs in the terminal.
## Key Features
### Text Colors (foreground color)
You can apply basic colors and their bright variants. Examples:
- **Basic Colors**: `black`, `red`, `green`, `yellow`, `blue`, `magenta`, `cyan`, `white`.
- **Bright Colors**: `blackBright`, `redBright`, `greenBright`, `yellowBright`, `blueBright`, `magentaBright`, `cyanBright`, `whiteBright`.
```js
import logs from "excolor";
logs("%[red]This text is red");
logs("%[greenBright]This text is bright green");
```
### Background Colors
Set background colors for your text:
- **Basic Backgrounds**: `bgBlack`, `bgRed`, `bgGreen`, `bgYellow`, `bgBlue`, `bgMagenta`, `bgCyan`, `bgWhite`.
- **Bright Backgrounds**: `bgBlackBright`, `bgRedBright`, `bgGreenBright`, `bgYellowBright`, `bgBlueBright`, `bgMagentaBright`, `bgCyanBright`, `bgWhiteBright`.
```js
import logs from "excolor";
logs("%[bgBlue]This text has a blue background");
logs("%[bgRedBright]This text has a bright red background");
```
### Text Effects
`exColor` allows you to add effects like:
- **Bold**: `bold`
- **Dim**: `dim`
- **Italic**: `italic`
- **Underline**: `underline`
- **Blink**: `blink`
- **Invert** (swaps text and background): `invert`
- **Hide**: `hide`
- **Strikethrough**: `strike`
```js
import logs from "excolor";
logs("%[bold]This text is bold");
logs("%[underline|red]This text is underlined and red");
logs("%[blink]This text will blink");
```
### 256-Color Mode
In 256-color mode, you can use ANSI's 256-color palette, which provides a wide range of color options for both text and background. This palette includes:
- **16 basic colors** (from 0 to 15)
- **216 colors** in various shades created by combining RGB values (from 16 to 231)
- **24 grayscale colors** (from 232 to 255)
You can set the text color using `fg256(number)` and the background color using `bg256(number)`.
```js
import logs from "excolor";
logs("%[fg256(82)]This is a custom 256 color text");
logs("%[bg256(124)]This text has a custom 256 color background");
```
### Reset Operators
`exColor` provides specific operators to reset text color, background color, and effects to the terminal’s default settings. These operators allow you to clear any styling and return to the terminal’s original look.
#### Reset Operators
- **`!bg` or `!background`**:
- Resets the **background color** to the terminal's default.
- Usage: `%[!bg]` or `%[!background]`
- **`!fg` or `!color`**:
- Resets the **text color** to the terminal's default.
- Usage: `%[!fg]` or `%[!color]`
- **`normal`, `reset`, or `""` (empty string)**:
- Resets **all styles, colors, and effects** to the terminal's default settings.
- Usage: `%[normal]`, `%[reset]`, or simply `%[]`
#### Examples
```js
// Text with a red background and white text, then reset to the default background
logs("%[white|bgRed]Important Message%[!bg] now with default background");
// Text with bold effect and green color, then reset text color
logs("%[green|bold]Green Bold Text%[!fg] default text color");
// Text with underline and blue color, then reset all styles
logs("%[blue|underline]Underlined Text%[reset] default text and style");
```
These reset operators allow for fine control over styling, making it easy to return to default colors or clear specific effects without affecting the rest of the terminal's styling.
#### Example:
```js
import logs from "excolor";
logs("%[fg256(82)]This is a custom 256 color text");
logs("%[bg256(124)]This text has a custom 256 color background");
```
Each color code can be referenced directly in `exColor` to customize your terminal output precisely as you desire.
You can use ANSI's 256-color palette. Use `fg256(number)` for text and `bg256(number)` for background.
### RGB and Hexadecimal Colors
For more customization, you can specify colors in RGB and Hexadecimal formats.
- **RGB**: `rgb(r,g,b)` for text and `bgRgb(r,g,b)` for background.**RGB**: `rgb(r,g,b)` for text and `bgRgb(r,g,b)` for background.
The **RGB** format allows you to specify colors by setting values for **Red (R)**, **Green (G)**, and **Blue (B)**. Each of these components can take an integer value between 0 and 255, where:
- `r` (Red) represents the intensity of the red component.
- `g` (Green) represents the intensity of the green component.
- `b` (Blue) represents the intensity of the blue component.
For example, `rgb(255,0,0)` produces a bright red color (maximum intensity of red and no green or blue), while `rgb(0,255,0)` produces a bright green.
#### Example:
```js
import logs from "excolor";
logs("%[rgb(255,151,0)]This text is colored rgb(255,151,0)");
logs("%[bgRgb(69,42,4)|white]This text has a background color in RGB");
```
- **Hexadecimal**: `hex(#RRGGBB)` for text and `bgHex(#RRGGBB)` for background.
The **Hexadecimal** format represents colors using a six-digit hexadecimal code, where each pair of digits corresponds to one of the RGB components:
- `RR` is the hexadecimal value for the red component.
- `GG` is the hexadecimal value for the green component.
- `BB` is the hexadecimal value for the blue component.
Each pair can range from `00` (0 in decimal) to `FF` (255 in decimal), allowing for 256 possible values per color channel. For example, `#FF5733` represents a eddish-orange color, where `FF` is the maximum red, `57` is a moderate amount of green, and `33` is a small amount of blue.
```js
import logs from "excolor";
logs("%[hex(#1F44A7)]This text is colored hex(#1F44A7)");
logs("%[bgHex(#7A0000)|hex(#ee3)]background color with text color in hex");
```
## Example in `example.js`
The `example.js` file included in the project provides detailed examples of all these features. Run this file to see the colors and effects in action and verify the functionality of the package.
If you want to run the excolor example script, use the following command:
```bash
npm explore excolor -- npm run example
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc