Skip to content

Commit

Permalink
fix: LocalStorage class implements Storage
Browse files Browse the repository at this point in the history
  • Loading branch information
izqalan committed Oct 10, 2020
1 parent 494d70d commit 0a05071
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, post, put, posh } from './lib/fetch'
import { get, post, put } from './lib/fetch'
import { Provider, UserAttributes } from './lib/types'

export default class Api {
Expand Down
22 changes: 19 additions & 3 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,28 @@ export function getParameterByName(name: string, url?: string) {
return decodeURIComponent(results[2].replace(/\+/g, ' '))
}

export class LocalStorage extends Storage{
export class LocalStorage implements Storage{
localStorage!: Storage
constructor(localStorage: Storage){
super();
constructor(localStorage: Storage) {
this.localStorage = localStorage;
}
[name: string]: any
length!: number
clear(): void {
return this.localStorage.clear();
}
key(index: number): string | null {
return this.localStorage.key(index);
}
setItem(key: string, value: any) {
return this.localStorage.setItem(key, value);
}
getItem(key: string) {
return this.localStorage.getItem(key);
}
removeItem(key: string) {
return this.localStorage.removeItem(key);
}
async getItemAsync(key: string) {
return await this.localStorage.getItem(key);
}
Expand Down

0 comments on commit 0a05071

Please sign in to comment.