Registry / gaming / tm-text

tm-text

JSON →
library1.1.0jsnpmunverified

tm-text is a library for parsing and formatting Trackmania and ManiaPlanet game text, converting color codes and formatting tokens (e.g., $f00 for red, $o for bold) into HTML, human-readable strings, or tokenized structures. The current version is 1.1.0, released on npm. It supports both ESM and CommonJS, ships TypeScript types, and is actively maintained on GitHub by Brainshaker95. Compared to alternatives, it provides a simple interface with functions like humanize, htmlify, tokenize, and blockify, covering all documented tokens including color codes, bold, italic, links, and shadow.

npm install tm-text
INSTALL
IMPORT
SIG · TM-TEXT
T
tm-text
gamingjavascriptv1.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tmText
import tmText from 'tm-text'
const tmText = require('tm-text')
Default import is preferred for ESM. CommonJS users must use require('tm-text').default or destructure { tmText }.
htmlify
import { htmlify } from 'tm-text'
import htmlify from 'tm-text'
htmlify is a named export, not the default.
humanize
import { humanize } from 'tm-text'
const humanize = require('tm-text').humanize
CommonJS destructuring works as require('tm-text').humanize; ESM named import is cleaner.
tokenize
import { tokenize } from 'tm-text'
Named export; no common mistake beyond the above patterns.
blockify
import { blockify } from 'tm-text'
Named export.

Parses Trackmania formatted text, then converts to human-readable string and HTML with color spans.

import tmText from 'tm-text'; const text = tmText('$f00R$fa2a$ff3i$0f0n$06fb$30fo$60fw'); console.log(text.humanize()); // 'Rainbow' console.log(text.htmlify()); // '<span style="color: #ff0000;">R</span><span style="color: #ffaa22;">a</span>...' console.log(text.tokenize()); // [{ type: 'color', value: '$f00', ... }, ...] console.log(text.blockify()); // [{ type: 'text', content: 'R', ... }, ...]
Debug
Known issues
gotchaThe dollar sign '$' in Trackmania text must be escaped as '$$' to display a literal dollar sign.
fix
Use '$$' in the input string to represent a single '$' character.
affects: >=1.0.0
gotchaColor codes with fewer than 3 hex digits (e.g., '$00') are not valid; format is $" followed by exactly 3 hex digits.
fix
Ensure all color tokens follow the pattern $[0-9a-fA-F]{3}.
affects: >=1.0.0
gotchaThe library does not handle nested or overlapping formatting tokens; input must be well-formed.
fix
Check your Trackmania text for proper token nesting before using tm-text.
affects: >=1.0.0
breakingESM-only from version 2.0.0 (future release); CommonJS support may be removed.
fix
Plan migration to ESM imports for future versions.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: tmText is not a function
Using CommonJS require incorrectly; require('tm-text') returns an object, not a function.
fix
Use const tmText = require('tm-text').default; or const { tmText } = require('tm-text');
Cannot find module 'tm-text'
Package not installed or environment resolution issue.
fix
Run npm install tm-text and ensure import path is correct (no './').
TS2307: Cannot find module 'tm-text' or its corresponding type declarations.
TypeScript cannot locate type definitions; may need to install @types or check tsconfig.
fix
Ensure 'node_modules' is in typeRoots, or add 'tm-text' to 'types' in tsconfig.json.
SyntaxError: Unexpected token 'export'
Using ESM syntax in a CommonJS context without transpilation.
fix
Use const { tmText } = require('tm-text'); instead of import.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
35 hits · last 30 days
node
32
OpenAI (training)
1
Resources
tm-text — npm install tm-text · libregistry