51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
/** @file
|
|
* @author Edouard DUPIN
|
|
* @copyright 2018, Edouard DUPIN, all right reserved
|
|
* @license PROPRIETARY (see license file)
|
|
*/
|
|
|
|
import { Injectable } from '@angular/core';
|
|
import { environment } from 'environments/environment';
|
|
|
|
@Injectable()
|
|
export class StorageService {
|
|
private baseLocalStorageName = environment.applName + '_';
|
|
|
|
constructor() {}
|
|
|
|
set(cname: string, cvalue: string): void {
|
|
//console.debug(`storage set: ${cname} : ${cvalue}`);
|
|
localStorage.setItem(this.baseLocalStorageName + cname, cvalue);
|
|
}
|
|
// limit at the current session ...
|
|
setSession(cname: string, cvalue: string): void {
|
|
sessionStorage.setItem(this.baseLocalStorageName + cname, cvalue);
|
|
}
|
|
|
|
remove(cname: string): void {
|
|
//console.debug(`storage remove: ${cname}`);
|
|
localStorage.removeItem(this.baseLocalStorageName + cname);
|
|
}
|
|
removeSession(cname: string): void {
|
|
sessionStorage.removeItem(this.baseLocalStorageName + cname);
|
|
}
|
|
|
|
get(cname: string): string | undefined {
|
|
//console.debug(`storage get: ${cname}`);
|
|
// TODO check expire day...
|
|
const data = localStorage.getItem(this.baseLocalStorageName + cname);
|
|
//console.debug(`get value form the storage (1): ${data}`)
|
|
if (data === null || data === undefined) {
|
|
return undefined;
|
|
}
|
|
return data;
|
|
}
|
|
getSession(cname: string): string | undefined {
|
|
const data = sessionStorage.getItem(this.baseLocalStorageName + cname);
|
|
if (data === null || data === undefined) {
|
|
return undefined;
|
|
}
|
|
return data;
|
|
}
|
|
}
|