|
1 | | -# node-tm-essentials |
2 | | -A lightweight library in Node.js that provides formatting features and little additions for any development related to Trackmania. |
| 1 | +# Trackmania Essentials (for Node.js) |
| 2 | + |
| 3 | +[](https://npmjs.com/tm-essentials) |
| 4 | +[](https://github.com/GreepTheSheep/node-tm-essentials/releases/latest) |
| 5 | + |
| 6 | +A light-weight library that provides formatting features for Trackmania games. |
| 7 | + |
| 8 | +## Text formatting |
| 9 | + |
| 10 | +`TextFormatter.deformat()` |
| 11 | + |
| 12 | +```js |
| 13 | +let formatted = "$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085 $094v$0A30$0B1.$0C01"; |
| 14 | +let deformatted = TextFormatter.deformat(formatted); |
| 15 | +console.log(deformatted); |
| 16 | + |
| 17 | +// Output: TMU.KrazyColors v0.1 |
| 18 | +``` |
| 19 | + |
| 20 | +`TextFormatter.formatAnsi()` |
| 21 | + |
| 22 | +Will parse the color formatting and convert it to ANSI escape codes. Works best on console output. |
| 23 | + |
| 24 | +```js |
| 25 | +let formatted = "$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085 $094v$0A30$0B1.$0C01"; |
| 26 | +let ansiFormat = TextFormatter.formatAnsi(formatted); |
| 27 | +console.log(deformatted); |
| 28 | +``` |
| 29 | + |
| 30 | +This will not deformat basic formatting codes, but you can combine them with `TextFormatter.deformat()` to get the original text. |
| 31 | + |
| 32 | +```js |
| 33 | +let formatted = "$F00T$D01M$C13U$A14.$815K$727r$528a$329z$23By$03CC$03Co$04Bl$059o$068r$077s$085 $094v$0A30$0B1.$0C01"; |
| 34 | +let ansiFormat = TextFormatter.deformat(TextFormatter.formatAnsi(formatted)); |
| 35 | +console.log(deformatted); |
| 36 | +``` |
| 37 | + |
| 38 | +## Time formatting |
| 39 | + |
| 40 | +`Time.time` - Total milliseconds as integer value. |
| 41 | + |
| 42 | +`Time.toTmString()` |
| 43 | + |
| 44 | +```js |
| 45 | +Time.fromMilliseconds(1337).toTmString(); // "0:01.337" |
| 46 | +Time.fromMilliseconds(1337).toTmString(true); // Will use hundredths as output: "0:01.33" |
| 47 | + |
| 48 | +Time.fromSeconds(13.37).toTmString(); // "0:13.370" |
| 49 | +Time.fromMinutes(13.37).toTmString(); // "13:37.000" |
| 50 | +Time.fromHours(13.37).toTmString(); // "13:37:00.000" |
| 51 | + |
| 52 | +Time.noTime.toTmString(); // "-:--.---" |
| 53 | +``` |
| 54 | + |
| 55 | +## Accounts formatting |
| 56 | + |
| 57 | +`Accounts.toAccountId()` |
| 58 | + |
| 59 | +```js |
| 60 | +Accounts.toAccountId("Jtmn3kBnSSadky_mLNhp_A") // "26d9a7de-4067-4926-9d93-2fe62cd869fc" |
| 61 | +``` |
| 62 | + |
| 63 | +`Accounts.toLogin()` |
| 64 | + |
| 65 | +```js |
| 66 | +Accounts.toLogin("26d9a7de-4067-4926-9d93-2fe62cd869fc") // "Jtmn3kBnSSadky_mLNhp_A" |
| 67 | +``` |
0 commit comments