@nkp/color

  • npm
  • Node.JS package

Extracts and transforms colors in within text blocks.

@nkp/color handles:

  • hex3: hex shorthand
  • hex4: hex shorthand with alpha
  • hex6: hex
  • hex8: hex with alpha
import { parseText } from '@nkp/color';

const text = `
this #aabbcc is text rgba(25, 125, 225, 50%) with
colors rgb(255 155 55) strewn throughout #abc.
`;

// map all colours to rgb/rgba
const modified: string = parseText(text)
  .mapColors((match) => match
    .color
    .toRgbx({ useCommas: true, })
  );

// text becomes
//
// this rgb(170, 187, 204) is text rgba(25, 125, 225, 50%) with
// colors rgb(255, 155, 55) strewn throughout rgb(170, 187, 204).
View on GitHub