blob: 0ba5aa3561f6f806b774f6235ce630f2ca7ce617 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
import { Mock } from './mock';
import { nullIfUndefined } from '../utilities/language-untilities';
export function createMockStorage(): Mock<Storage> {
const map: { [key: string]: string } = {};
return {
get length(): number {
return Object.keys(map).length;
},
key(index: number): string | null {
const keys = Object.keys(map);
if (index >= keys.length) { return null; }
return keys[index];
},
clear() {
Object.keys(map).forEach(key => delete map.key);
},
getItem(key: string): string | null {
return nullIfUndefined(map[key]);
},
setItem(key: string, value: string) {
map[key] = value;
},
removeItem(key: string) {
delete map[key];
}
};
}
|