1
import { StorageDriver } from './interfaces'
2 1
export default class StroageDriverImpl implements StorageDriver {
3
	private storage
4 1
	constructor(storage: Storage) {
5 1
		this.storage = storage
6
	}
7 1
	set(key: string, value: any) {
8 1
		this.storage.setItem(key, JSON.stringify(value))
9
	}
10 1
	get(key: string) {
11 1
		return JSON.parse(this.storage.getItem(key))
12
	}
13 1
	has(key: string) {
14 1
		return !!this.storage.getItem(key)
15
	}
16 1
}
17 1
export const localStorage = new StroageDriverImpl(window.localStorage)
18 1
export const sessionStorage = new StroageDriverImpl(window.sessionStorage)

Read our documentation on viewing source code .

Loading