Skip to content

Instantly share code, notes, and snippets.

@GuyHarwood
Created December 16, 2019 15:37
Show Gist options
  • Save GuyHarwood/cd560cc7325eee662c8a9ac7edccf25b to your computer and use it in GitHub Desktop.
Save GuyHarwood/cd560cc7325eee662c8a9ac7edccf25b to your computer and use it in GitHub Desktop.
local storage wrapper with key prefix type
export class StorageService {
setItem (key: StorageKey, item: any): void {
localStorage.setItem(key.toString(), item)
}
}
export class StorageKey {
private key: string
constructor (prefix: StorageKeyPrefix, suffix: string) {
this.key = `${prefix}-${suffix}`
}
public toString (): string {
return this.key
}
}
export type StorageKeyPrefix = 'Audit' | 'Input' | 'Answer'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment