Files
gridpilot.gg/apps/website/lib/display-objects/AvatarDisplay.ts
Marc Mintel d97f50ed72
Some checks failed
Contract Testing / contract-tests (pull_request) Failing after 6m4s
Contract Testing / contract-snapshot (pull_request) Has been skipped
view data fixes
2026-01-23 11:59:49 +01:00

39 lines
969 B
TypeScript

/**
* AvatarDisplay
*
* Deterministic mapping of avatar-related data to display formats.
*/
export class AvatarDisplay {
/**
* Converts binary buffer to base64 string for display.
*/
static bufferToBase64(buffer: ArrayBuffer): string {
const bytes = new Uint8Array(buffer);
let binary = '';
for (let i = 0; i < bytes.byteLength; i++) {
binary += String.fromCharCode(bytes[i]);
}
return btoa(binary);
}
/**
* Determines if avatar data is valid for display.
* Accepts base64-encoded string buffer.
*/
static hasValidData(buffer: string, contentType: string): boolean {
return buffer.length > 0 && contentType.length > 0;
}
/**
* Formats content type for display (e.g., "image/png" → "PNG").
*/
static formatContentType(contentType: string): string {
const parts = contentType.split('/');
if (parts.length === 2) {
return parts[1].toUpperCase();
}
return contentType;
}
}