# Code coverage report for src/lib/services/storage/storage.service.ts

# All files / src/lib/services/storage storage.service.ts

95.65% Statements 22/23
53.57% Branches 15/28
100% Functions 6/6
100% Lines 17/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    301x
    1x
    1x
    1x
    1x

    1x

    5x
    5x
    5x

    3x

    3x

    3x
    3x

    1x
    1x

    1x
     import { Injectable } from '@angular/core';
    import { ILogger } from '../../models/logger.model';
    impoIrt { LoggerService } from '../logger/logger.service';

    @Injectable({
    	providedIn: 'root'
    })
    export class StorageService {
    	public storage = window.localStorage;
    	public log: ILogger;

    	constructor(private loggerSrv: LoggerService) {
    		this.log = this.loggerSrv.get('StorageService');
    	}

    	public set(key: string, item: any) {
    		const value = JSON.stringify({ item: item });
    		// this.log.d('Storing on localStorage "' + key + '" with value "' + value + '"');
    		this.storage.setItem(key, value);
    	}
    	public get(key: string): any {
    		const value = JSON.parse(this.storage.getItem(key));
    		return value?.item ? value.item : null;
    	}
    	public clear() {
    		this.log.d('Clearing localStorage');
    		this.storage.clear();
    	}
    }