2021-06-15 12:36:26 +02:00
|
|
|
'use strict';
|
|
|
|
|
2021-06-15 09:19:52 +02:00
|
|
|
class LocalStorageMock {
|
|
|
|
constructor() {
|
2023-04-20 17:12:32 +01:00
|
|
|
this.store = new Map();
|
2021-06-15 09:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clear() {
|
2023-04-20 17:12:32 +01:00
|
|
|
this.store.clear();
|
2021-06-15 09:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
getItem(key) {
|
2023-04-20 17:12:32 +01:00
|
|
|
/**
|
|
|
|
* We return null to avoid returning `undefined`
|
|
|
|
* because `undefined` is not a valid JSON value.
|
|
|
|
*/
|
|
|
|
return this.store.get(key) ?? null;
|
2021-06-15 09:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setItem(key, value) {
|
2023-04-20 17:12:32 +01:00
|
|
|
this.store.set(key, String(value));
|
2021-06-15 09:19:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
removeItem(key) {
|
2023-04-20 17:12:32 +01:00
|
|
|
this.store.delete(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
get length() {
|
|
|
|
return this.store.size;
|
2021-06-15 09:19:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-20 17:12:32 +01:00
|
|
|
// eslint-disable-next-line no-undef
|
|
|
|
Object.defineProperty(window, 'localStorage', {
|
|
|
|
writable: true,
|
|
|
|
value: new LocalStorageMock(),
|
|
|
|
});
|