diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d36e1a8..6e98150 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,11 +10,12 @@ jobs: fail-fast: false matrix: node-version: - - 14 - - 12 + - 22 + - 20 + - 18 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index 58f133a..ee8bc27 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,4 +1,4 @@ -export interface CSPair { // eslint-disable-line @typescript-eslint/naming-convention +export type CSPair = { // eslint-disable-line @typescript-eslint/naming-convention /** The ANSI terminal control sequence for starting this style. */ @@ -8,9 +8,9 @@ export interface CSPair { // eslint-disable-line @typescript-eslint/naming-conve The ANSI terminal control sequence for ending this style. */ readonly close: string; -} +}; -export interface ColorBase { +export type ColorBase = { /** The ANSI terminal control sequence for ending this color. */ @@ -21,9 +21,9 @@ export interface ColorBase { ansi256(code: number): string; ansi16m(red: number, green: number, blue: number): string; -} +}; -export interface Modifier { +export type Modifier = { /** Resets the current color chain. */ @@ -70,9 +70,9 @@ export interface Modifier { Puts a horizontal line through the center of the text. (Not widely supported) */ readonly strikethrough: CSPair; -} +}; -export interface ForegroundColor { +export type ForegroundColor = { readonly black: CSPair; readonly red: CSPair; readonly green: CSPair; @@ -100,9 +100,9 @@ export interface ForegroundColor { readonly cyanBright: CSPair; readonly magentaBright: CSPair; readonly whiteBright: CSPair; -} +}; -export interface BackgroundColor { +export type BackgroundColor = { readonly bgBlack: CSPair; readonly bgRed: CSPair; readonly bgGreen: CSPair; @@ -130,9 +130,9 @@ export interface BackgroundColor { readonly bgCyanBright: CSPair; readonly bgMagentaBright: CSPair; readonly bgWhiteBright: CSPair; -} +}; -export interface ConvertColor { +export type ConvertColor = { /** Convert from the RGB color space to the ANSI 256 color space. @@ -178,7 +178,7 @@ export interface ConvertColor { @param hex - A hexadecimal string containing RGB data. */ hexToAnsi(hex: string): number; -} +}; /** Basic modifier names. diff --git a/index.js b/index.js index d7bede4..eaa7bed 100644 --- a/index.js +++ b/index.js @@ -109,7 +109,7 @@ function assembleStyles() { // From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js Object.defineProperties(styles, { rgbToAnsi256: { - value: (red, green, blue) => { + value(red, green, blue) { // We use the extended greyscale palette here, with the exception of // black and white. normal palette only has 4 greyscale shades. if (red === green && green === blue) { @@ -132,7 +132,7 @@ function assembleStyles() { enumerable: false, }, hexToRgb: { - value: hex => { + value(hex) { const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16)); if (!matches) { return [0, 0, 0]; @@ -161,7 +161,7 @@ function assembleStyles() { enumerable: false, }, ansi256ToAnsi: { - value: code => { + value(code) { if (code < 8) { return 30 + code; } diff --git a/index.test-d.ts b/index.test-d.ts index 8dc8e32..1571549 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,11 @@ import {expectAssignable, expectError, expectType} from 'tsd'; -import ansiStyles, {CSPair, ModifierName, ForegroundColorName, BackgroundColorName, ColorName} from './index.js'; +import ansiStyles, { + type BackgroundColorName, + type ColorName, + type CSPair, + type ForegroundColorName, + type ModifierName, +} from './index.js'; expectType>(ansiStyles.codes); diff --git a/package.json b/package.json index 6cd3ca5..dd26fb6 100644 --- a/package.json +++ b/package.json @@ -46,9 +46,9 @@ "text" ], "devDependencies": { - "ava": "^3.15.0", + "ava": "^6.1.3", "svg-term-cli": "^2.1.1", - "tsd": "^0.19.0", - "xo": "^0.47.0" + "tsd": "^0.31.1", + "xo": "^0.58.0" } } diff --git a/test/test.js b/test/test.js index 40e4875..aed48fa 100644 --- a/test/test.js +++ b/test/test.js @@ -1,5 +1,10 @@ import test from 'ava'; -import ansiStyles, {modifierNames, foregroundColorNames, backgroundColorNames, colorNames} from '../index.js'; +import ansiStyles, { + backgroundColorNames, + colorNames, + foregroundColorNames, + modifierNames, +} from '../index.js'; test('return ANSI escape codes', t => { t.is(ansiStyles.green.open, '\u001B[32m');