Options
All
  • Public
  • Public/Protected
  • All
Menu

Module text

@skeldjs/text

This package contains a text building API for the Rich Text formatter used in Among Us, meant to be installed separately with npm install --save @skeldjs/text or yarn add @skeldjs/text, and is one package of a bigger project, skeldjs.

You can view auto-updating documentation for this package hosted at github pages at https://skeld.js.org/modules/text.html

Basic Usage

Creating a basic document

const formatted = tb()
    .bold(
        color("red", "Hello")
    );

console.log(formatted.toString()); // <b><color="red">Hello</color></b>

or you can define a boilerplate for the document, where the children of the elements in the tb function are not considered.

const formatted = tb(bold(), color("red"))
    .text("Hello");

console.log(formatted.toString()); // <b><color="red">Hello</color></b>

You can also create elements standalone.

const formatted = bold("Hello");

console.log(formatted.toString()); // <b>Hello</b>

Parse RichText

The package also provides a way to parse the Rich Text format.

const parsed = parseTMP("<b><color=red>Hello</color></b>");

console.log(parsed);
/*
TMPElement {
  tagName: 'doc',
  attributes: {},
  children: [
    TMPElement {
      tagName: 'b',
      attributes: {},
      children: [
        TMPElement {
          tagName: 'color',
          attributes: { color: 'red' },
          children: [ 'Hello' ]
        }
      ]
    }
  ]
}
*/

Generate HTML

It also provides a way to convert roughly to HTML where possible.

const parsed = parseTMP("<b><color=red>Hello</color></b>");

console.log(toHTML(parsed));
/*
<div style="width:100%;height:100%;">
    <b>
        <div style="display:inline-block;color:red">
            <span>Hello</span>
        </div>
    </b>
</div>
*/

Index

Type aliases

ParsePart

TMPColorName

TMPColorName: "black" | "blue" | "green" | "orange" | "purple"

TMPNode

TMPNode: TMPElement | string

TMPRGBA

TMPRGBA: [number, number, number, number]

TMPTag

TMPTag: "doc" | "align" | "alpha" | "color" | "b" | "i" | "cspace" | "font" | "indent" | "line-height" | "line-indent" | "link" | "lowercase" | "uppercase" | "smallcaps" | "margin" | "mark" | "mspace" | "noparse" | "nobr" | "page" | "pos" | "size" | "space" | "sprite" | "s" | "u" | "style" | "sub" | "sup" | "voffset" | "width"

Functions

align

alpha

bold

color

  • color(clr: string | [number, number, number, number], ...content: TMPNode[]): TMPElement

font

highlight

  • highlight(color: string | [number, number, number, number], ...content: TMPNode[]): TMPElement

indent

italics

link

lnheight

lnindent

lowercase

margin

monospace

nbspace

nextpage

parseTMP

  • parseTMP(content: string): any

pos

size

smallcaps

space

spacing

st

strikethrough

subscript

superscript

Const tb

text

toHTML

underline

uppercase

voffset

width

Generated using TypeDoc