merge next
This commit is contained in:
+10
-1
@@ -39,7 +39,7 @@ export function bytesToHumanSize(bytes) {
|
||||
|
||||
// Get 32 bit integer hash value for a string. Ideally it should produce the same value
|
||||
// as Java's String#hash().
|
||||
export function stringHash(value) {
|
||||
function stringToColorHash(value) {
|
||||
let hash = 0;
|
||||
value = '' + value;
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
@@ -48,3 +48,12 @@ export function stringHash(value) {
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
// Converts user or topic ID to a CSS color class. Ideally it should produce the same color value as Java version.
|
||||
// params:
|
||||
// - {string} id: user or topic ID
|
||||
// - {boolean} light: light or dark version of the color.
|
||||
// - {boolean} fg: foreground or background color.
|
||||
export function idToColorClass(id, light, fg) {
|
||||
return (light ? 'lt-' : 'dk-') + (fg ? 'fg-' : 'bg-') + (Math.abs(stringToColorHash(id)) % 16);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user