This repository was archived by the owner on Nov 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export { WebStorageUtility } from './utility/webstorage.utility';
77export declare class Webstorable {
88 save ( ) : void ;
99}
10+ export type ClearType = 'decorators' | 'prefix' | 'all' ;
1011export let WEBSTORAGE_CONFIG = {
1112 prefix : 'angular2ws_'
1213} ;
Original file line number Diff line number Diff line change 11import { Injectable } from '@angular/core' ;
22import { WebStorageUtility } from '../utility/webstorage.utility' ;
3+ import { ClearType , WEBSTORAGE_CONFIG } from '../index' ;
34
45export interface WebStorageServiceInterface {
56 keys : Array < string > ;
@@ -28,9 +29,20 @@ export abstract class WebStorageService {
2829 WebStorageUtility . remove ( this . storage , key ) ;
2930 }
3031
31- clear ( ) : void {
32- for ( let key of ( < WebStorageServiceInterface > this . constructor ) . keys ) {
33- this . storage . removeItem ( key ) ;
32+ public clear ( clearType : ClearType = 'decorators' ) : void {
33+ let keys = ( < WebStorageServiceInterface > this . constructor ) . keys ; // get keys from child class
34+ if ( clearType === 'decorators' ) {
35+ for ( let key of keys ) {
36+ this . storage . removeItem ( key ) ;
37+ }
38+ } else if ( clearType === 'prefix' ) {
39+ for ( let key in this . storage ) {
40+ if ( this . storage . getItem ( key ) . startsWith ( WEBSTORAGE_CONFIG . prefix ) ) {
41+ this . storage . removeItem ( key ) ;
42+ }
43+ }
44+ } else if ( clearType === 'all' ) {
45+ this . storage . clear ( ) ;
3446 }
3547 }
3648}
You can’t perform that action at this time.
0 commit comments