From 4a26c33b7ac2fa12aced16aa013a269154e39351 Mon Sep 17 00:00:00 2001 From: LitoMore Date: Thu, 13 Oct 2022 00:31:05 +0800 Subject: [PATCH] Fix exported style names (#83) --- index.js | 10 +++++----- test/test.js | 11 ++++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 1d38d09..d7bede4 100644 --- a/index.js +++ b/index.js @@ -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(); @@ -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]; diff --git a/test/test.js b/test/test.js index ee11468..40e4875 100644 --- a/test/test.js +++ b/test/test.js @@ -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'); @@ -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))); +});