File

src/lib/services/discuss-utils.service.ts

Index

Methods

Constructor

constructor()

Methods

getContrast
getContrast()
Returns : string
htmlDecode
htmlDecode(str: any)

The htmlDecode() method parses a string containing either HTML or XML

Parameters :
Name Type Optional
str any No
Returns : any
stringToColor
stringToColor(title)
Parameters :
Name Optional
title No
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;
  }

}

results matching ""

    No results matching ""