Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 76 additions & 74 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,122 +1,124 @@
import {KEYWORD} from 'color-convert/conversions';
import * as cssColors from 'color-name';

declare namespace ansiStyles {
interface ColorConvert {
/**
* The RGB color space
*
* @param red (0-255)
* @param green (0-255)
* @param blue (0-255)
*/
The RGB color space

@param red (0-255)
@param green (0-255)
@param blue (0-255)
*/
rgb(red: number, green: number, blue: number): string;

/**
* The HSL color space
*
* @param hue (0-360)
* @param saturation (0-100)
* @param lightness (0-100)
*/
The HSL color space

@param hue (0-360)
@param saturation (0-100)
@param lightness (0-100)
*/
hsl(hue: number, saturation: number, lightness: number): string;

/**
* The HSV color space
*
* @param hue (0-360)
* @param saturation (0-100)
* @param value (0-100)
*/
The HSV color space

@param hue (0-360)
@param saturation (0-100)
@param value (0-100)
*/
hsv(hue: number, saturation: number, value: number): string;

/**
* The HSV color space
*
* @param hue (0-360)
* @param whiteness (0-100)
* @param blackness (0-100)
*/
The HSV color space

@param hue (0-360)
@param whiteness (0-100)
@param blackness (0-100)
*/
hwb(hue: number, whiteness: number, blackness: number): string;

/**
* The CMYK color space
*
* @param cyan (0-100)
* @param magenta (0-100)
* @param yellow (0-100)
* @param black (0-100)
*/
The CMYK color space

@param cyan (0-100)
@param magenta (0-100)
@param yellow (0-100)
@param black (0-100)
*/
cmyk(cyan: number, magenta: number, yellow: number, black: number): string;

/**
* The XYZ color space
*
* @param x (0-100)
* @param y (0-100)
* @param z (0-100)
*/
The XYZ color space

@param x (0-100)
@param y (0-100)
@param z (0-100)
*/
xyz(x: number, y: number, z: number): string;

/**
* The LAB color space
*
* @param x (0-100)
* @param y (0-100)
* @param z (0-100)
*/
The LAB color space

@param x (0-100)
@param y (0-100)
@param z (0-100)
*/
lab(lightness: number, a: number, b: number): string;

/**
* The LCH/HCL color space
*
* @param lightness (0-100)
* @param chroma (0-100)
* @param hue (0-360)
*/
The LCH/HCL color space

@param lightness (0-100)
@param chroma (0-100)
@param hue (0-360)
*/
lch(lightness: number, chroma: number, hue: number): string;

/**
* The RGB HEX color space
*
* @param hex A hexadecimal string containing RGB data
*/
The RGB HEX color space

@param hex A hexadecimal string containing RGB data
*/
hex(hex: string): string;

keyword(keyword: KEYWORD): string;
/** @param keyword A CSS color name */
keyword(keyword: keyof typeof cssColors): string;

ansi(ansi: number): string;
ansi256(ansi: number): string;

/**
* The HCG color space
*
* @param hue (0-360)
* @param chroma (0-100)
* @param gray (0-100)
*/
The HCG color space

@param hue (0-360)
@param chroma (0-100)
@param gray (0-100)
*/
hcg(hue: number, chroma: number, gray: number): string;

/**
* The Apple RGB 16-bit color space
*
* @param red (0-65535)
* @param green (0-65535)
* @param blue (0-65535)
*/
The Apple RGB 16-bit color space

@param red (0-65535)
@param green (0-65535)
@param blue (0-65535)
*/
apple(r16: number, g16: number, b16: number): string;

/**
* Grayscale color
*
* @param gray (0-100)
*/
Grayscale color

@param gray (0-100)
*/
gray(gray: number): string;
}

interface CSIPair {
/** The ANSI terminal Control Sequence for setting this style */
/** The ANSI terminal Control Sequence for starting this style */
readonly open: string;

/** The ANSI terminal Control Sequence for resetting this style */
/** The ANSI terminal Control Sequence for ending this style */
readonly close: string;
}

Expand All @@ -125,7 +127,7 @@ declare namespace ansiStyles {
readonly ansi256: ColorConvert;
readonly ansi16m: ColorConvert;

/** The ANSI terminal Control Sequence for resetting this color */
/** The ANSI terminal Control Sequence for ending this color */
readonly close: Close;
}

Expand Down
11 changes: 11 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {expectType, expectError} from 'tsd';
import * as cssColors from 'color-name';
import colorConvert = require('color-convert');
import ansiStyles = require('.');

declare function keyof<T>(type: T): keyof T;
declare function params<T extends (...args: any) => unknown>(type: T): Parameters<T>

type CSS_COLOR_NAMES = keyof typeof cssColors;
type ExpectedColorSpaces = Exclude<keyof typeof colorConvert, 'ansi16'> | 'ansi';
let expectedColors!: ExpectedColorSpaces;

Expand All @@ -19,6 +22,10 @@ expectType<keyof typeof ansiStyles.color.ansi>(expectedColors);
expectType<keyof typeof ansiStyles.color.ansi256>(expectedColors);
expectType<keyof typeof ansiStyles.color.ansi16m>(expectedColors);

expectType<[CSS_COLOR_NAMES]>(params(ansiStyles.color.ansi.keyword));
expectType<[CSS_COLOR_NAMES]>(params(ansiStyles.color.ansi256.keyword));
expectType<[CSS_COLOR_NAMES]>(params(ansiStyles.color.ansi16m.keyword));

// -- Background color --
expectType<ExpectedColorSpaces>(keyof(ansiStyles.bgColor.ansi));
expectType<ExpectedColorSpaces>(keyof(ansiStyles.bgColor.ansi256));
Expand All @@ -28,6 +35,10 @@ expectType<keyof typeof ansiStyles.bgColor.ansi>(expectedColors);
expectType<keyof typeof ansiStyles.bgColor.ansi256>(expectedColors);
expectType<keyof typeof ansiStyles.bgColor.ansi16m>(expectedColors);

expectType<[CSS_COLOR_NAMES]>(params(ansiStyles.bgColor.ansi.keyword));
expectType<[CSS_COLOR_NAMES]>(params(ansiStyles.bgColor.ansi256.keyword));
expectType<[CSS_COLOR_NAMES]>(params(ansiStyles.bgColor.ansi16m.keyword));

// - Static colors -
// -- Namespaced --
// --- Foreground color ---
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@
"text"
],
"dependencies": {
"@types/color-convert": "^1.9.0",
"@types/color-name": "^1.1.1",
"color-convert": "^2.0.1"
},
"devDependencies": {
"@types/color-convert": "^1.9.0",
"ava": "^2.3.0",
"svg-term-cli": "^2.1.1",
"tsd": "^0.8.0",
Expand Down