Socket
Socket
Sign inDemoInstall

kleur

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kleur - npm Package Compare versions

Comparing version 3.0.3 to 4.0.0

colors.js

128

kleur.d.ts
// Originally by: Rogier Schouten <https://github.com/rogierschouten>
// Adapted by: Madhav Varshney <https://github.com/madhavarshney>
declare namespace kleur {
interface Color {
(x: string | number): string;
(): Kleur;
declare module 'kleur' {
namespace kleur {
interface Color {
(x: string | number): string;
(): Kleur;
}
interface Kleur {
// Colors
black: Color;
red: Color;
green: Color;
yellow: Color;
blue: Color;
magenta: Color;
cyan: Color;
white: Color;
gray: Color;
grey: Color;
// Backgrounds
bgBlack: Color;
bgRed: Color;
bgGreen: Color;
bgYellow: Color;
bgBlue: Color;
bgMagenta: Color;
bgCyan: Color;
bgWhite: Color;
// Modifiers
reset: Color;
bold: Color;
dim: Color;
italic: Color;
underline: Color;
inverse: Color;
hidden: Color;
strikethrough: Color;
}
}
interface Kleur {
// Colors
black: Color;
red: Color;
green: Color;
yellow: Color;
blue: Color;
magenta: Color;
cyan: Color;
white: Color;
gray: Color;
grey: Color;
let kleur: kleur.Kleur & { enabled: boolean };
export = kleur;
}
// Backgrounds
bgBlack: Color;
bgRed: Color;
bgGreen: Color;
bgYellow: Color;
bgBlue: Color;
bgMagenta: Color;
bgCyan: Color;
bgWhite: Color;
declare module 'kleur/colors' {
function print(input: null): null;
function print(input: undefined): undefined;
function print(input: string | boolean | number): string;
function print(input: void): void;
type Colorize = typeof print;
// Modifiers
reset: Color;
bold: Color;
dim: Color;
italic: Color;
underline: Color;
inverse: Color;
hidden: Color;
strikethrough: Color;
namespace kleur {
interface Context {
enabled: boolean;
}
interface Kleur {
// Colors
black: Colorize;
red: Colorize;
green: Colorize;
yellow: Colorize;
blue: Colorize;
magenta: Colorize;
cyan: Colorize;
white: Colorize;
gray: Colorize;
grey: Colorize;
// Backgrounds
bgBlack: Colorize;
bgRed: Colorize;
bgGreen: Colorize;
bgYellow: Colorize;
bgBlue: Colorize;
bgMagenta: Colorize;
bgCyan: Colorize;
bgWhite: Colorize;
// Modifiers
reset: Colorize;
bold: Colorize;
dim: Colorize;
italic: Colorize;
underline: Colorize;
inverse: Colorize;
hidden: Colorize;
strikethrough: Colorize;
}
}
let kleur: kleur.Kleur & { $: kleur.Context };
export = kleur;
}
declare let kleur: kleur.Kleur & { enabled: boolean };
export = kleur;
{
"name": "kleur",
"version": "3.0.3",
"version": "4.0.0",
"repository": "lukeed/kleur",
"description": "The fastest Node.js library for formatting terminal text with ANSI colors~!",
"module": "index.mjs",
"main": "index.js",
"types": "kleur.d.ts",
"license": "MIT",
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.js"
},
"./colors": {
"import": "./colors.mjs",
"require": "./colors.js"
}
},
"files": [
"*.js",
"*.d.ts"
"*.d.ts",
"colors.*",
"index.*"
],

@@ -14,9 +28,10 @@ "author": {

"email": "luke.edwards05@gmail.com",
"url": "lukeed.com"
"url": "https://lukeed.com"
},
"scripts": {
"test": "tape test/*.js | tap-spec"
"build": "node build",
"test": "uvu -r esm -i utils"
},
"engines": {
"node": ">=6"
"node": ">=10"
},

@@ -31,7 +46,6 @@ "keywords": [

],
"types": "kleur.d.ts",
"devDependencies": {
"tap-spec": "^5.0.0",
"tape": "^4.9.1"
"esm": "3.2.25",
"uvu": "0.0.11"
}
}

@@ -9,4 +9,4 @@ <div align="center">

</a>
<a href="https://travis-ci.org/lukeed/kleur">
<img src="https://badgen.now.sh/travis/lukeed/kleur" alt="travis" />
<a href="https://github.com/lukeed/kleur/actions?query=workflow%3ACI">
<img src="https://github.com/lukeed/kleur/workflows/CI/badge.svg?event=push" alt="CI" />
</a>

@@ -30,2 +30,3 @@ <a href="https://npmjs.org/package/kleur">

* Conditional [color support](#conditional-support)
* [Fully treeshakable](#individual-colors)
* Familiar [API](#api)

@@ -35,3 +36,3 @@

As of `v3.0` the Chalk-style syntax (magical getter) is no longer used.<br>If you need or require that syntax, consider using [`ansi-colors`](https://github.com/doowb/ansi-colors), which maintains `chalk` parity.
As of `v3.0` the Chalk-style syntax (magical getter) is no longer used.<br>Please visit [History](#history) for migration paths supporting that syntax.

@@ -51,12 +52,12 @@ ---

```js
const { red, white, blue, bold } = require('kleur');
import kleur from 'kleur';
// basic usage
red('red text');
kleur.red('red text');
// chained methods
blue().bold().underline('howdy partner');
kleur.blue().bold().underline('howdy partner');
// nested methods
bold(`${ white().bgRed('[ERROR]') } ${ red().italic('Something happened')}`);
kleur.bold(`${ white().bgRed('[ERROR]') } ${ kleur.red().italic('Something happened')}`);
```

@@ -67,2 +68,4 @@

```js
const { bold, green } = require('kleur');
console.log(bold().red('this is a bold red message'));

@@ -93,3 +96,3 @@ console.log(bold().italic('this is a bold italicized message'));

```js
const kleur = require('kleur');
import kleur from 'kleur';

@@ -100,3 +103,3 @@ // manually disable

// or use another library to detect support
kleur.enabled = require('color-support').level;
kleur.enabled = require('color-support').level > 0;

@@ -127,2 +130,45 @@ console.log(kleur.red('I will only be colored red if the terminal supports colors'));

## Individual Colors
When you only need a few colors, it doesn't make sense to import _all_ of `kleur` because, as small as it is, `kleur` is not treeshakeable, and so most of its code will be doing nothing. In order to fix this, you can import from the `kleur/colors` submodule which _fully_ supports tree-shaking.
The caveat with this approach is that color functions **are not** chainable~!<br>Each function receives and colorizes its input. You may combine colors, backgrounds, and modifiers by nesting function calls within other functions.
```js
// or: import * as kleur from 'kleur/colors';
import { red, underline, bgWhite } from 'kleur/colors';
red('red text');
//~> kleur.red('red text');
underline(red('red underlined text'));
//~> kleur.underline().red('red underlined text');
bgWhite(underline(red('red underlined text w/ white background')));
//~> kleur.bgWhite().underline().red('red underlined text w/ white background');
```
> **Note:** All the same [colors, backgrounds, and modifiers](#api) are available.
***Conditional Support***
The `kleur/colors` submodule also allows you to toggle color support, as needed.<br>
It includes the same initial assumptions as `kleur`, in an attempt to have colors enabled by default.
Unlike `kleur`, this setting exists as `kleur.$.enabled` instead of `kleur.enabled`:
```js
import * as kleur from 'kleur/colors';
// or: import { $, red } from 'kleur/colors';
// manually disabled
kleur.$.enabled = false;
// or use another library to detect support
kleur.$.enabled = require('color-support').level > 0;
console.log(red('I will only be colored red if the terminal supports colors'));
```
## Benchmarks

@@ -135,5 +181,6 @@

```
chalk :: 14.543ms
kleur :: 0.474ms
ansi-colors :: 1.923ms
chalk :: 5.303ms
kleur :: 0.488ms
kleur/colors :: 0.369ms
ansi-colors :: 1.504ms
```

@@ -145,21 +192,24 @@

# All Colors
ansi-colors x 199,381 ops/sec ±1.04% (96 runs sampled)
chalk x 12,107 ops/sec ±2.07% (87 runs sampled)
kleur x 715,334 ops/sec ±0.30% (93 runs sampled)
ansi-colors x 183,435 ops/sec ±0.96% (94 runs sampled)
chalk x 677,371 ops/sec ±0.17% (94 runs sampled)
kleur x 718,990 ops/sec ±0.51% (91 runs sampled)
kleur/colors x 862,421 ops/sec ±0.19% (95 runs sampled)
# Stacked colors
ansi-colors x 24,494 ops/sec ±1.03% (93 runs sampled)
chalk x 2,650 ops/sec ±2.06% (85 runs sampled)
kleur x 75,798 ops/sec ±0.19% (97 runs sampled)
ansi-colors x 23,647 ops/sec ±1.14% (90 runs sampled)
chalk x 332,056 ops/sec ±0.57% (94 runs sampled)
kleur x 75,924 ops/sec ±0.32% (98 runs sampled)
kleur/colors x 103,509 ops/sec ±0.30% (96 runs sampled)
# Nested colors
ansi-colors x 77,766 ops/sec ±0.32% (94 runs sampled)
chalk x 5,596 ops/sec ±1.85% (86 runs sampled)
kleur x 137,660 ops/sec ±0.31% (93 runs sampled)
ansi-colors x 67,278 ops/sec ±0.72% (96 runs sampled)
chalk x 124,868 ops/sec ±0.34% (96 runs sampled)
kleur x 136,444 ops/sec ±0.16% (97 runs sampled)
kleur/colors x 143,956 ops/sec ±0.25% (95 runs sampled)
```
## Credits
## History
This project originally forked [Brian Woodward](https://github.com/doowb)'s awesome [`ansi-colors`](https://github.com/doowb/ansi-colors) library.
This project originally forked [`ansi-colors`](https://github.com/doowb/ansi-colors).

@@ -177,3 +227,3 @@ Beginning with `kleur@3.0`, the Chalk-style syntax (magical getter) has been replaced with function calls per key:

If you prefer the old syntax, you may migrate to `ansi-colors`. Versions below `kleur@3.0` have been deprecated.
If you prefer the old syntax, you may migrate to `ansi-colors` or newer `chalk` releases.<br>Versions below `kleur@3.0` have been officially deprecated.

@@ -180,0 +230,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