Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exported style names #83

Merged
merged 5 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)));
});