Files
discordeno/packages/utils/src/hash.ts
Fleny 27c261fee2 formatter: Use semicolons (#4686)
I prefer semicolors, they also help avoiding certain pitfalls in JavaScript/TypeScript, such as the following code sample:
```js
const xyz = "test"
(something.else as string) = "another"
```
This results in a TypeError: "test" is not a function, this is because js thinks we are trying to call the string "test" as a function.
To fix this it requires a `;` somewhere before the `(`, such as `;(something ... ` which in my opinion is ugly and less clean overall.
2026-01-17 21:54:15 +01:00

20 lines
702 B
TypeScript

export function iconHashToBigInt(hash: string): bigint {
// The icon is animated so it needs special handling
if (hash.startsWith('a_')) {
// Change the `a_` to just be `a`
hash = `a${hash.substring(2)}`;
} else {
// The icon is not animated but it could be that it starts with a 0 so we just put a `b` in front so nothing breaks
hash = `b${hash}`;
}
return BigInt(`0x${hash}`);
}
export function iconBigintToHash(icon: bigint): string {
// Convert the bigint back to a hash
const hash = icon.toString(16);
// Hashes starting with a are animated and with b are not so need to handle that
return hash.startsWith('a') ? `a_${hash.substring(1)}` : hash.substring(1);
}