typesafe-storage
Version:
Typesafe Web Storage API wrapper to support objects and arrays
30 lines (22 loc) • 560 B
text/typescript
class AltStorage implements Storage {
private values: Record<string, string> = {};
get length(): number {
return Object.keys(this.values).length;
}
clear(): void {
this.values = {};
}
getItem(key: string): string | null {
return this.values[key] || null;
}
key(index: number): string | null {
return Object.keys(this.values)[index] || null;
}
setItem(key: string, value: string): void {
this.values[key] = value;
}
removeItem(key: string): void {
delete this.values[key];
}
}
export default AltStorage;