Skip to content

Commit

Permalink
Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore committed Oct 3, 2022
1 parent 0ae8de5 commit 07cd4fd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
"dist"
],
"scripts": {
"build": "tsc",
"pretest": "del-cli dist && npm run build",
"test": "xo && ava"
"build": "del-cli dist && tsc",
"test": "xo && c8 ava"
},
"repository": {
"type": "git",
Expand All @@ -27,13 +26,14 @@
},
"homepage": "https://github.com/LitoMore/chalk-pipe#readme",
"devDependencies": {
"@ava/typescript": "^1.1.1",
"@sindresorhus/tsconfig": "^1.0.2",
"ava": "^3.15.0",
"@sindresorhus/tsconfig": "^3.0.1",
"@types/node": "^18.8.0",
"ava": "^4.3.3",
"c8": "^7.12.0",
"del-cli": "^3.0.1",
"ts-node": "^9.1.1",
"typescript": "^4.2.4",
"xo": "^0.38.2"
"ts-node": "^10.9.1",
"typescript": "^4.8.4",
"xo": "^0.52.3"
},
"dependencies": {
"chalk": "^4.1.0"
Expand Down
9 changes: 5 additions & 4 deletions source/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import chalk, {Chalk, Modifiers, ForegroundColor} from 'chalk';
import type {Chalk, Modifiers, ForegroundColor} from 'chalk';
import chalk from 'chalk';
import {modifiers, normalColors, cssColorNames} from './styles.js';

const isBackground = (style: string) => {
Expand All @@ -18,12 +19,12 @@ const isHexColor = (style: string) => {
};

const isKeyword = (style: string) => {
// @ts-expect-error
return Boolean(cssColorNames[style]);
return style in cssColorNames;
};

const chalkPipe = (stylePipe?: string, customChalk?: Chalk) => {
let paint = customChalk ?? chalk;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
let paint = customChalk || chalk;

if (!stylePipe || stylePipe.length === 0) {
return paint;
Expand Down
8 changes: 4 additions & 4 deletions source/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const modifiers = [
'underline',
'inverse',
'hidden',
'strikethrough'
'strikethrough',
];

export const normalColors = [
Expand All @@ -25,7 +25,7 @@ export const normalColors = [
'blueBright',
'magentaBright',
'cyanBright',
'whiteBright'
'whiteBright',
];

export const cssColorNames = {
Expand Down Expand Up @@ -176,5 +176,5 @@ export const cssColorNames = {
white: '#ffffff',
whitesmoke: '#f5f5f5',
yellow: '#ffff00',
yellowgreen: '#9acd32'
};
yellowgreen: '#9acd32',
} as const;
2 changes: 1 addition & 1 deletion source/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('Normal Colors', (t) => {
const text = scheme('bar');
const should =
chalk.black.red.green.yellow.blue.magenta.cyan.white.gray.redBright.greenBright.yellowBright.blueBright.magentaBright.cyanBright.whiteBright(
'bar'
'bar',
);

t.is(text, should);
Expand Down

0 comments on commit 07cd4fd

Please sign in to comment.