All files / client/src/utils resetStaleEventStorage.ts

100% Statements 6/6
100% Branches 2/2
100% Functions 2/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18          361x 361x 722x   1310x     722x 2x        
import { browserStoragePrefix } from "shared/constants/browserStorage";
 
// Konsti storage keys are prefixed with the event+year (browserStoragePrefix),
// so a new event never reads a previous event's data; this removes the
// leftover keys on page load
export const resetStaleEventStorage = (): void => {
  for (const storage of [localStorage, sessionStorage]) {
    const staleKeys = Object.keys(storage).filter(
      (key) =>
        key.startsWith("konsti-") &&
        !key.startsWith(`${browserStoragePrefix}-`),
    );
    for (const staleKey of staleKeys) {
      storage.removeItem(staleKey);
    }
  }
};