mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-18 18:46:19 +08:00
feat: global avatar
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
export function stringToColour(str: string) {
|
||||
str = str || 'affine';
|
||||
let colour = '#';
|
||||
let hash = 0;
|
||||
// str to hash
|
||||
for (
|
||||
let i = 0;
|
||||
i < str.length;
|
||||
hash = str.charCodeAt(i++) + ((hash << 5) - hash)
|
||||
);
|
||||
|
||||
// int/hash to hex
|
||||
for (
|
||||
let i = 0;
|
||||
i < 3;
|
||||
colour += ('00' + ((hash >> (i++ * 8)) & 0xff).toString(16)).slice(-2)
|
||||
);
|
||||
|
||||
return colour;
|
||||
}
|
||||
@@ -3,3 +3,5 @@ export { isDev } from './env';
|
||||
export * from './useragent';
|
||||
|
||||
export * from './tools';
|
||||
|
||||
export * from './colors';
|
||||
|
||||
Reference in New Issue
Block a user