Files
barker/bookie/src/app/shared/cookie.service.ts
Amritanshu 2495c24e1a Chore: Updated python dependencies
Chore: Updated angular to v19
Chore: Refactored ops with docker and ansible
2024-12-16 17:58:17 +05:30

33 lines
909 B
TypeScript

import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class CookieService {
public getCookie(name: string) {
const ca: string[] = document.cookie.split(';');
const caLen: number = ca.length;
const cookieName = `${name}=`;
let c: string;
for (let i = 0; i < caLen; i += 1) {
c = ca[i].replace(/^\s+/g, '');
if (c.indexOf(cookieName) === 0) {
return c.substring(cookieName.length, c.length);
}
}
return '';
}
public deleteCookie(name: string) {
this.setCookie(name, '', -1);
}
public setCookie(name: string, value: string, expireDays: number, path = '') {
const d: Date = new Date();
d.setTime(d.getTime() + expireDays * 24 * 60 * 60 * 1000);
const expires = `expires=${d.toUTCString()}`;
document.cookie = `${name}=${value}; ${expires}${path.length > 0 ? `; path=${path}` : ''}`;
}
}