Skip to content

Commit

Permalink
Fix exported style names (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore authored Oct 12, 2022
1 parent 1e1b27d commit 4a26c33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ const styles = {
},
};

export const modifierNames = Object.keys(styles.modifier);
export const foregroundColorNames = Object.keys(styles.color);
export const backgroundColorNames = Object.keys(styles.bgColor);
export const colorNames = [...foregroundColorNames, ...backgroundColorNames];

function assembleStyles() {
const codes = new Map();

Expand Down Expand Up @@ -216,8 +221,3 @@ function assembleStyles() {
const ansiStyles = assembleStyles();

export default ansiStyles;

export const modifierNames = Object.keys(styles.modifier);
export const foregroundColorNames = Object.keys(styles.color);
export const backgroundColorNames = Object.keys(styles.bgColor);
export const colorNames = [...foregroundColorNames, ...backgroundColorNames];
11 changes: 10 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test from 'ava';
import ansiStyles from '../index.js';
import ansiStyles, {modifierNames, foregroundColorNames, backgroundColorNames, colorNames} from '../index.js';

test('return ANSI escape codes', t => {
t.is(ansiStyles.green.open, '\u001B[32m');
Expand Down Expand Up @@ -65,3 +65,12 @@ test('export raw ANSI escape codes', t => {
test('rgb → truecolor is stubbed', t => {
t.is(ansiStyles.color.ansi16m(123, 45, 67), '\u001B[38;2;123;45;67m');
});

test('non-styles should not be exported', t => {
const isNonStyle = name => name === 'close' || name.startsWith('ansi');
t.false(modifierNames.some(name => isNonStyle(name)));
t.false(foregroundColorNames.some(name => isNonStyle(name)));
t.false(backgroundColorNames.some(name => isNonStyle(name)));
t.true(backgroundColorNames.every(name => name.startsWith('bg')));
t.false(colorNames.some(name => isNonStyle(name)));
});

0 comments on commit 4a26c33

Please sign in to comment.