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

yoctocolors

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

yoctocolors - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

base.d.ts

49

index.d.ts

@@ -1,47 +0,2 @@

export type Format = (string: string) => string;
export const reset: Format;
export const bold: Format;
export const dim: Format;
export const italic: Format;
export const underline: Format;
export const overline: Format;
export const inverse: Format;
export const hidden: Format;
export const strikethrough: Format;
export const black: Format;
export const red: Format;
export const green: Format;
export const yellow: Format;
export const blue: Format;
export const magenta: Format;
export const cyan: Format;
export const white: Format;
export const gray: Format;
export const bgBlack: Format;
export const bgRed: Format;
export const bgGreen: Format;
export const bgYellow: Format;
export const bgBlue: Format;
export const bgMagenta: Format;
export const bgCyan: Format;
export const bgWhite: Format;
export const bgGray: Format;
export const redBright: Format;
export const greenBright: Format;
export const yellowBright: Format;
export const blueBright: Format;
export const magentaBright: Format;
export const cyanBright: Format;
export const whiteBright: Format;
export const bgRedBright: Format;
export const bgGreenBright: Format;
export const bgYellowBright: Format;
export const bgBlueBright: Format;
export const bgMagentaBright: Format;
export const bgCyanBright: Format;
export const bgWhiteBright: Format;
export * from './base.js';
export * as default from './base.js';

@@ -1,88 +0,2 @@

import tty from 'node:tty';
// eslint-disable-next-line no-warning-comments
// TODO: Use a better method when it's added to Node.js (https://github.com/nodejs/node/pull/40240)
const hasColors = tty.WriteStream.prototype.hasColors();
const format = (open, close) => {
if (!hasColors) {
return input => input;
}
const openCode = `\u001B[${open}m`;
const closeCode = `\u001B[${close}m`;
return input => {
const string = input + ''; // eslint-disable-line no-implicit-coercion -- This is faster.
let index = string.indexOf(closeCode);
if (index === -1) {
// Note: Intentionally not using string interpolation for performance reasons.
return openCode + string + closeCode;
}
// Handle nested colors.
// We could have done this, but it's too slow (as of Node.js 22).
// return openCode + string.replaceAll(closeCode, openCode) + closeCode;
let result = openCode;
let lastIndex = 0;
while (index !== -1) {
result += string.slice(lastIndex, index) + openCode;
lastIndex = index + closeCode.length;
index = string.indexOf(closeCode, lastIndex);
}
result += string.slice(lastIndex) + closeCode;
return result;
};
};
export const reset = format(0, 0);
export const bold = format(1, 22);
export const dim = format(2, 22);
export const italic = format(3, 23);
export const underline = format(4, 24);
export const overline = format(53, 55);
export const inverse = format(7, 27);
export const hidden = format(8, 28);
export const strikethrough = format(9, 29);
export const black = format(30, 39);
export const red = format(31, 39);
export const green = format(32, 39);
export const yellow = format(33, 39);
export const blue = format(34, 39);
export const magenta = format(35, 39);
export const cyan = format(36, 39);
export const white = format(37, 39);
export const gray = format(90, 39);
export const bgBlack = format(40, 49);
export const bgRed = format(41, 49);
export const bgGreen = format(42, 49);
export const bgYellow = format(43, 49);
export const bgBlue = format(44, 49);
export const bgMagenta = format(45, 49);
export const bgCyan = format(46, 49);
export const bgWhite = format(47, 49);
export const bgGray = format(100, 49);
export const redBright = format(91, 39);
export const greenBright = format(92, 39);
export const yellowBright = format(93, 39);
export const blueBright = format(94, 39);
export const magentaBright = format(95, 39);
export const cyanBright = format(96, 39);
export const whiteBright = format(97, 39);
export const bgRedBright = format(101, 49);
export const bgGreenBright = format(102, 49);
export const bgYellowBright = format(103, 49);
export const bgBlueBright = format(104, 49);
export const bgMagentaBright = format(105, 49);
export const bgCyanBright = format(106, 49);
export const bgWhiteBright = format(107, 49);
export * from './base.js';
export * as default from './base.js';
{
"name": "yoctocolors",
"version": "2.0.2",
"version": "2.1.0",
"description": "The smallest and fastest command-line coloring package on the internet",

@@ -27,3 +27,5 @@ "license": "MIT",

"index.js",
"index.d.ts"
"index.d.ts",
"base.js",
"base.d.ts"
],

@@ -30,0 +32,0 @@ "keywords": [

@@ -25,3 +25,3 @@ <sup>yoctocolors 🌈</sup>

```js
import * as colors from 'yoctocolors';
import colors from 'yoctocolors';

@@ -33,2 +33,12 @@ console.log(colors.red('Yo!'));

You can also import colors as named imports:
```js
import {red, blue, green} from 'yoctocolors';
console.log(red('Yo!'));
console.log(blue(`Welcome to the ${green('yoctocolors')} package!`));
```
*This package supports [basic color detection](https://nodejs.org/api/tty.html#writestreamhascolorscount-env). Colors can be forcefully enabled by setting the `FORCE_COLOR` environment variable to `1` and can be forcefully disabled by setting `NO_COLOR` or `NODE_DISABLE_COLORS` to any value. [More info.](https://nodejs.org/api/tty.html#writestreamgetcolordepthenv)*

@@ -35,0 +45,0 @@

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