Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1.  
  2. import { Injectable } from "@angular/core";
  3.  
  4. @Injectable()
  5. export class CookiesService {
  6.  
  7. getASpecyficCookieValue(nameOfValue: string): string {
  8. const cookies: string = document.cookie;
  9. const index = cookies.search(nameOfValue);
  10. let value = "";
  11.  
  12. if (index === -1) return "";
  13. else {
  14. for (let i = index + nameOfValue.length + 1; i < cookies.length; i++) {
  15. if (cookies.charAt(i) === ";") return value;
  16. else value += cookies.charAt(i);
  17. }
  18. }
  19. return value;
  20. }
  21.  
  22. setCookie(name: string, expDays: number, path: string, value: string) {
  23. const date = new Date();
  24. date.setTime(date.getTime() + expDays * 24 * 60 * 60 * 1000);
  25. const expireDate = "expires=" + date.toUTCString();
  26. document.cookie = name + "=" + value + ";" + expireDate + ";path=" + path;
  27. }
  28.  
  29. deleteCookie(name) {
  30. document.cookie = name+'=; Max-Age=-99999999;';
  31. }
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement