Skip to content

Commit

Permalink
fix(avatar): empty name
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Apr 9, 2024
1 parent a4e593e commit 852a3d2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/avatar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ const {
round?: boolean,
} & GraphicsProps>()
function hash(str: string) {
// eslint-disable-next-line no-bitwise
return str.split('').reduce((code, char) => (code ^ char.charCodeAt(0)) * -5, 5) >>> 2
let code = 0
for (let i = 0, len = str.length; i < len; i++) {
const chr = str.charCodeAt(i)
// eslint-disable-next-line no-bitwise
code = ((code << 5) - code + chr) | 0
}
return code
}
const code = $computed(() => hash(name))
Expand Down

0 comments on commit 852a3d2

Please sign in to comment.