aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-02-20 21:38:14 -0600
committermat <github@matdoes.dev>2022-02-20 21:38:14 -0600
commit13e5974114f759bae73f3bfd68c62ce9cfaf785e (patch)
tree8a196b27b8d4dece1dc2187332422a4e41423dfa /src/lib/utils.ts
parent582409e7cb1598b65bee6d1023b77620bb3791af (diff)
downloadskyblock-stats-13e5974114f759bae73f3bfd68c62ce9cfaf785e.tar.gz
skyblock-stats-13e5974114f759bae73f3bfd68c62ce9cfaf785e.tar.bz2
skyblock-stats-13e5974114f759bae73f3bfd68c62ce9cfaf785e.zip
add more stuff to profile and fix bugs
Diffstat (limited to 'src/lib/utils.ts')
-rw-r--r--src/lib/utils.ts8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index f16021d..197bf6b 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -26,7 +26,7 @@ const colorCodeCharacter = 'ยง'
export function formattingCodeToHtml(formatted: string): string {
let htmlOutput = ''
// we store the hex code, not the formatting code
- let currentColor = null
+ let currentColor: null | string = null
// we store the css code, not the formatting code
const activeSpecialCodes: string[] = []
function reset() {
@@ -50,7 +50,7 @@ export function formattingCodeToHtml(formatted: string): string {
// if there's already a color, close that tag
if (currentColor) htmlOutput += '</span>'
currentColor = colorCodes[colorCharacter]
- htmlOutput += `<span style="color: ${currentColor}">`
+ htmlOutput += `<span style="color:${currentColor}">`
}
} else if (specialCodes[colorCharacter]) {
if (!activeSpecialCodes.includes(specialCodes[colorCharacter])) {
@@ -133,7 +133,7 @@ export function twemojiHtml(s: string) {
const htmlEncoded = s.replace('<', '&lt;').replace('>', '&gt;').replace('&', '&amp;')
// replace unicode emojis with <img src="/emoji/[hex].svg">
const asTwemoji = htmlEncoded.replace(emojiRegex, (match) => {
- return `<img src="/emoji/${[...match].map(p => p.codePointAt(0).toString(16)).join('-')}.svg" class="emoji">`
+ return `<img src="/emoji/${[...match].map(p => p.codePointAt(0)!.toString(16)).join('-')}.svg" class="emoji">`
})
return asTwemoji
}
@@ -150,5 +150,5 @@ export function formatNumber(n: number, digits = 3) {
{ value: 1e18, symbol: 'E' },
]
const item = numberSymbolsLookup.slice().reverse().find(item => n >= item.value)
- return (n / item.value).toPrecision(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + item.symbol
+ return (n / (item?.value ?? 1)).toPrecision(digits).replace(/\.0+$|(\.[0-9]*[1-9])0+$/, '$1') + (item?.symbol ?? '')
} \ No newline at end of file