import { Injectable } from '@angular/core' ; import { Log } from './logger.service' ; @ Injectable ( ) export class StorageService { getText ( key ) { const serialisedItemData = localStorage . getItem ( key ) ; return serialisedItemData ; } getNumber ( key ) { const serialisedItemData = localStorage . getItem ( key ) ; if ( isNaN ( + serialisedItemData ) ) { return undefined ; } return + serialisedItemData ; } getItem < T > ( key ) { const serialisedItemData = localStorage . getItem ( key ) ; if ( ! serialisedItemData ) { return undefined ; } try { const item = JSON . parse ( serialisedItemData ) ; return item as T ; } catch ( e ) { Log . error ( e ) ; return undefined ; } } setItem < T > ( key , value ) { if ( ! value ) { localStorage . setItem ( key , null ) ; return ; } localStorage . setItem ( key , JSON . stringify ( value ) ) ; } removeItem ( key ) { localStorage . removeItem ( key ) ; } setText ( key , value ) { if ( ! ! value ) { localStorage . setItem ( key , null ) ; return ; } localStorage . setItem ( key , value ) ; } setNumber ( key , value ) { if ( ! ! value ) { localStorage . setItem ( key , null ) ; return ; } localStorage . setItem ( key , value + '' ) ; } }