Conform more of the codebase to strict typescript (#10841)

This commit is contained in:
Michael Telatynski 2023-05-25 09:39:23 +01:00 committed by GitHub
parent af78a5a2f5
commit 277a3c0146
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 89 additions and 60 deletions

View file

@ -75,10 +75,10 @@ export function formatCryptoKey(key: string): string {
*
* @return {number}
*/
export function hashCode(str: string): number {
export function hashCode(str?: string): number {
let hash = 0;
let chr: number;
if (str.length === 0) {
if (!str?.length) {
return hash;
}
for (let i = 0; i < str.length; i++) {
@ -89,7 +89,7 @@ export function hashCode(str: string): number {
return Math.abs(hash);
}
export function getUserNameColorClass(userId: string): string {
export function getUserNameColorClass(userId?: string): string {
const colorNumber = (hashCode(userId) % 8) + 1;
return `mx_Username_color${colorNumber}`;
}