Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* @flow */
import colorette from 'colorette';
import memoize from 'fast-memoize';
import { withRgbColor, withRgbBackgroundColor } from './colors/rgb';
import { withHexColor, withHexBackgroundColor } from './colors/hex';
import { withKeywordColor, withKeywordBackgroundColor } from './colors/keyword';
colorette.options.enabled = process.env.CI ? true : colorette.options.enabled;
const CSI = '\u001b[';
const reset = memoize(
(text: string) => (text ? `${CSI}0m${text}${CSI}0m` : text)
);
const capitalize = memoize(
(text: string) => `${text[0].toUpperCase()}${text.slice(1)}`
);
const colorize = memoize(
(color: string, isBackground: boolean, text: string) => {
if (color === 'initial') {
return reset(text);
}
import colorette from 'colorette';
import * as supportsColor from 'supports-color';
import applyStyle from '../applyStyle';
colorette.options.enabled = true;
supportsColor.stdout.level = 3;
describe('applyStyle', () => {
it('should reset if color is initial', () => {
expect(JSON.stringify(applyStyle({ color: 'initial' }, 'hello'))).toMatch(
/"\\u001b\[0m\\u001b\[0mhello\\u001b\[0m\\u001b\[0m"/
);
});
it('should apply background ANSI color', () => {
expect(JSON.stringify(applyStyle({ bgColor: 'blue' }, 'hello'))).toMatch(
/\\u001b\[44mhello\\u001b\[49m/
);
});
it('should should apply raw color', () => {