src/lib/services/discuss-utils.service.ts
Methods |
constructor()
|
Defined in src/lib/services/discuss-utils.service.ts:6
|
getContrast |
getContrast()
|
Defined in src/lib/services/discuss-utils.service.ts:23
|
Returns :
string
|
htmlDecode | ||||||
htmlDecode(str: any)
|
||||||
Defined in src/lib/services/discuss-utils.service.ts:31
|
||||||
The htmlDecode() method parses a string containing either HTML or XML
Parameters :
Returns :
any
|
stringToColor | ||||
stringToColor(title)
|
||||
Defined in src/lib/services/discuss-utils.service.ts:10
|
||||
Parameters :
Returns :
string
|
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class DiscussUtilsService {
constructor() { }
stringToColor(title) {
let hash = 0;
for (let i = 0; i < title.length; i++) {
// tslint:disable-next-line: no-bitwise
hash = title.charCodeAt(i) + ((hash << 5) - hash);
}
const hue = Math.abs(hash % 360);
// tslint:disable-next-line: prefer-template
const colour = 'hsl(' + hue + ',100%,30%)';
return colour;
}
getContrast() {
return 'rgba(255, 255, 255, 80%)';
}
/**
* The htmlDecode() method parses a string containing either HTML or XML
* @param {any} str
*/
htmlDecode(str: any) {
const doc = new DOMParser().parseFromString(str, "text/html");
return doc.documentElement.textContent;
}
}