@stevenleep/storage
Version:
enhanced local storage
33 lines (26 loc) • 602 B
text/typescript
import { BaseStorageInterface } from "../dist";
export default class CustomStorage implements BaseStorageInterface {
/**
* 自己实现的存储层
* @private
*/
private store: Record<string, string> = {};
/**
* 以下是必须实现的接口
*/
clear(): void {
this.store = {};
}
getItem(key: string): string | null {
return this.store[key] || null;
}
key(index: number): string | null {
return null;
}
removeItem(key: string): void {
delete this.store[key];
}
setItem(key: string, value: string): void {
this.store[key] = value;
}
}