export default class LocalStorage { constructor( private readonly source: Storage, private readonly serializer: (t: T) => string = JSON.stringify, private readonly deserializer: (s: string) => T = JSON.parse, ) {} getCollection(collectionId: string) { const raw = this.source.getItem(collectionId) if (raw !== null) { return this.deserializer(raw) } return null } replaceCollection(collectionId: string, collectionData: T) { this.source.setItem(collectionId, this.serializer(collectionData)) } removeCollection(collectionId: string) { this.source.removeItem(collectionId) } }