import { Injectable } from '@angular/core' ; import { CookieService , CookieServiceSetOptions } from '../interfaces/cookie-service.interface' ; import { CookieStorage } from '../interfaces/cookie-storage.interface' ; @ Injectable ( ) export class BaseCookieStorage implements CookieStorage { constructor ( private cookieService ) { } get length ( ) : number { return Object . keys ( this . cookieService . getAll ( ) ) . length ; } clear ( ) { this . cookieService . removeAll ( ) ; } getItem ( key ) { const item = this . cookieService . get ( key ) ; return item != null ? item : null ; } key ( index ) { const keys = Object . keys ( this . cookieService . getAll ( ) ) ; return index >= 0 && index < keys . length ? keys [ index ] : null ; } removeItem ( key ) { this . cookieService . remove ( key ) ; } setItem ( key , data , options = { path : '/' } ) { this . cookieService . put ( key , data , options ) ; } }