text-mesh-transformer
TypeScript icon, indicating that this package has built-in type declarations

1.4.1 • Public • Published

text-mesh-transformer

text-mesh-transformer

Install

npm i text-mesh-transformer

Description

Transformer for TextMesh Pro Rich Text tags.

Usage

const ansiStyles = await import('ansi-styles');
const transform = require('./dist/index.js').default;
const Tag = require('./dist/index.js').Tag;

const str = transform(`
  foo <color=red>test <color=blue><u><b>moo</b></u></color> bar
`, (openTag, content) => {
  switch (openTag.tag) {
    case Tag.Color: {
      if (openTag.value in ansiStyles) {
        return `${ansiStyles[openTag.value].open}${content}${ansiStyles[openTag.value].close}`;
      }
      break;
    }
    case Tag.Underline:
      return `${ansiStyles.modifier.underline.open}${content}${ansiStyles.modifier.underline.close}`;
    case Tag.Italic:
      return `${ansiStyles.modifier.italic.open}${content}${ansiStyles.modifier.italic.close}`;
    case Tag.Bold:
      return `${ansiStyles.modifier.bold.open}${content}${ansiStyles.modifier.bold.close}`;
  }

  return content;
});
  
console.log(str); //returns styled console.log string

Readme

Keywords

none

Package Sidebar

Install

npm i text-mesh-transformer

Weekly Downloads

6

Version

1.4.1

License

none

Unpacked Size

46.7 kB

Total Files

17

Last publish

Collaborators

  • ayecue