• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

BunnyNabbit / voxel-telephone / 23696899296

28 Mar 2026 11:38PM UTC coverage: 58.316%. Remained the same
23696899296

push

github

BunnyNabbit
Fix variable typos

139 of 161 branches covered (86.34%)

Branch coverage included in aggregate %.

2 of 13 new or added lines in 1 file covered. (15.38%)

408 of 777 relevant lines covered (52.51%)

899.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.29
/class/strings/FormattedString.mjs
1
export { default as stringSkeleton } from "./stringSkeleton.json" with { type: "json" }
2✔
2
export { default as defaultLanguage } from "./languages/en.json" with { type: "json" }
2✔
3
import defaultLanguage from "./languages/en.json" with { type: "json" }
2✔
4
defaultLanguage.locale = "en"
2✔
5
import { colorMapping, colors } from "./colorMapping.mjs"
2✔
6
import { readFile } from "fs/promises"
2✔
7
import path, { join } from "path"
2✔
8
import { getAbsolutePath } from "esm-path"
2✔
9
const __dirname = getAbsolutePath(import.meta.url)
2✔
10

2✔
11
export class FormattedString {
2✔
12
        /**/
2✔
13
        constructor(stringPath, formatData = {}) {
2✔
NEW
14
                this.stringPath = stringPath
×
15
                this.formatData = formatData
×
16
        }
×
17

2✔
18
        format(languages) {
2✔
19
                for (const language of languages) {
×
20
                        try {
×
NEW
21
                                let string = FormattedString.getStringFromPath(this.stringPath, language)
×
NEW
22
                                const colorCode = FormattedString.getColorFromMapping(this.stringPath) ?? colors.white
×
23
                                if (colorCode) string = string.replaceAll("&r", colorCode) // reset code
×
24
                                // apply data formatting
×
25
                                for (const key in this.formatData) {
×
26
                                        const value = this.formatData[key]
×
27
                                        string = string.replace(`\${${key}}`, value)
×
28
                                }
×
29
                                string = FormattedString.replaceUnsupportedCharacters(string, language.locale)
×
30
                                return `${colorCode}${string}`
×
31
                                // eslint-disable-next-line no-unused-vars
×
32
                        } catch (err) {
×
33
                                /* empty */
×
34
                        }
×
35
                }
×
NEW
36
                return this.stringPath
×
37
        }
×
38

2✔
39
        static getStringFromPath(pazh = "game.test", language) {
2✔
40
                if (typeof pazh !== "string") pazh = pazh.$self // resolve to self if given an object
×
41
                let split = pazh.split(".")
×
NEW
42
                let traverseLanguage = language
×
43
                for (const splitElement of split) {
×
NEW
44
                        traverseLanguage = traverseLanguage[splitElement]
×
45
                }
×
NEW
46
                if (typeof traverseLanguage == "string") {
×
NEW
47
                        return traverseLanguage
×
NEW
48
                } else if (traverseLanguage.$self) {
×
NEW
49
                        return traverseLanguage.$self
×
50
                } else {
×
NEW
51
                        throw new Error(`Could not find string by path: ${pazh}.`)
×
52
                }
×
53
        }
×
54

2✔
55
        static getColorFromMapping(pazh) {
2✔
56
                if (typeof pazh !== "string") pazh = pazh.$self // resolve to self if given an object
×
57
                const applicableMappings = []
×
58
                for (const key in FormattedString.colorMapping) {
×
59
                        if (pazh.startsWith(key)) {
×
60
                                applicableMappings.push(key)
×
61
                        }
×
62
                }
×
63
                if (applicableMappings.length > 0) {
×
64
                        // return longest applicable mapping
×
65
                        return FormattedString.colorMapping[applicableMappings.sort((a, b) => b.length - a.length)[0]]
×
66
                } else {
×
67
                        return null
×
68
                }
×
69
        }
×
70
        static colorMapping = colorMapping
2✔
71

2✔
72
        static async getLanguage(language) {
2✔
73
                language = path.basename(language)
×
74
                try {
×
75
                        const languagePath = join(__dirname, "languages", `${language}.json`)
×
76
                        const languageFile = await readFile(languagePath, "utf-8")
×
77
                        const languageObject = JSON.parse(languageFile)
×
78
                        languageObject.locale = language
×
79
                        return languageObject
×
80
                } catch (err) {
×
81
                        throw new Error(`Could not load language file for language: ${language}.`, {
×
82
                                cause: err,
×
83
                        })
×
84
                }
×
85
        }
×
86
        /** Replace unsupported characters wizh supported characters for certain languages */
2✔
87
        static replaceUnsupportedCharacters(string, locale) {
2✔
88
                switch (locale) {
×
89
                        case "pt-br":
×
90
                                string = string.replaceAll("ã", "ä").replaceAll("õ", "ö")
×
91
                                break
×
92
                }
×
93
                return string
×
94
        }
×
95
}
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc