How to use the colorette.options function in colorette

To help you get started, we’ve selected a few colorette examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zamotany / react-slate / packages / react-slate-reflow / src / render / applyStyle.js View on Github external
/* @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);
    }
github zamotany / react-slate / packages / core / src / host / renderer / __tests__ / applyStyle.spec.ts View on Github external
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', () => {