1.4.1 • Published 12 months ago

text-mesh-transformer v1.4.1

Weekly downloads
-
License
-
Repository
github
Last release
12 months ago

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
1.4.1

12 months ago

1.4.0

12 months ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.3.3

1 year ago

1.0.6

1 year ago

1.3.2

1 year ago

1.0.5

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.1

1 year ago

1.0.4

1 year ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago