A light-weight library that provides formatting features for Trackmania games.
npm install tm-essentialsThen you can retrieve the library with:
constTMEssentials=require('tm-essentials');<scriptsrc="https://unpkg.com/tm-essentials"></script>Then you can retrieve the library from the global variable TMEssentials
RegExp to match all the formatting codes
RegExp to match all the color formatting codes
Deformat the text
letformatted="$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085 $094v$0A30$0B1.$0C01";letdeformatted=TextFormatter.deformat(formatted);console.log(deformatted);// Output: TMU.KrazyColors v0.1You can pass options in it:
colorOnly: Deformat color codes only
Will parse the color formatting and convert it to ANSI escape codes. Works best on console output.
letformatted="$l[https://kc.jfreu.com/]$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085$l $094v$0A30$0B1.$0C01";letansiFormat=TextFormatter.formatAnsi(formatted);console.log(ansiFormat);You can pass options in it:
disableLinks: will disable links to external sites (false by default)disableColor: will disable colors while keeping the text styles (false by default)lightBackground: adapt color to be visible on light backgrounds (false by default)colorDepth: color depth of the ANSI escape codes, either"4bit","8bit"or"24bit"("24bit"by default)
letformatted="$l[https://kc.jfreu.com/]$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085$l $094v$0A30$0B1.$0C01";letansiFormat=TextFormatter.formatAnsi(formatted,{disableLinks: true,lightBackground: true,colorDepth: "8bit"});console.log(ansiFormat);letformatted="$l[https://kc.jfreu.com/]$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085$l $094v$0A30$0B1.$0C01";letansiFormatNoColor=TextFormatter.formatAnsi(formatted,{disableLinks: true,disableColor: true});console.log(ansiFormatNoColor);This is a port of the original Maniaplanet style parser written in pure JS. Copyright © 2012 - 2026 Nadeo & Baptiste Lafontaine
letformatted="$l[https://kc.jfreu.com]$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085$l $094v$0A30$0B1.$0C01";lethtmlFormat=TextFormatter.formatHtml(formatted);document.querySelector("#result").innerHTML=htmlFormat;You can pass options in it:
disableLinks: will disable links to external sites (false by default)lightBackground: adapt color to be visible on light backgrounds (false by default)linkTarget: add atargetattribute into links
letformatted="$l[https://kc.jfreu.com]$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085$l $094v$0A30$0B1.$0C01";lethtmlFormat=TextFormatter.formatHtml(formatted,{disableLinks: true,lightBackground: true});document.querySelector("#result").innerHTML=htmlFormat;letformatted="$l[https://greep.fr]Open this link to a new tab$l with the target attribute";lethtmlFormat=TextFormatter.formatHtml(formatted,{linkTarget: "_blank"});document.querySelector("#result").innerHTML=htmlFormat;Time.fromMilliseconds(1337).toTmString();// "0:01.337"Time.fromMilliseconds(1337).toTmString(true);// Will use hundredths as output: "0:01.33"Time.fromSeconds(13.37).toTmString();// "0:13.370"Time.fromMinutes(13.37).toTmString();// "13:37.000"Time.fromHours(13.37).toTmString();// "13:37:00.000"Time.noTime.toTmString();// "-:--.---"TimeSpan will return a Time class when one of noTime property or thoses methods is used:
Time.noTimeTime.fromMilliseconds()Time.fromSeconds()Time.fromMinutes()Time.fromHours()
Time.time - Total milliseconds as integer value.
Time.toTmString() - Outputs the time to a formatted Trackmania-like string
Accounts.toAccountId("Jtmn3kBnSSadky_mLNhp_A")// "26d9a7de-4067-4926-9d93-2fe62cd869fc"Accounts.toLogin("26d9a7de-4067-4926-9d93-2fe62cd869fc")// "Jtmn3kBnSSadky_mLNhp_A"