@dash0/sdk-web
Version:
Dash0's Web SDK to collect telemetry from end-users' web browsers
26 lines (20 loc) • 647 B
text/typescript
// localStorage API re-exposed to allow testing.
import { localStorage } from "./globals";
export const isSupported =
localStorage != null && typeof localStorage.getItem === "function" && typeof localStorage.setItem === "function";
export function getItem(k: string): string | null | undefined {
if (isSupported && localStorage) {
return localStorage.getItem(k);
}
return null;
}
export function setItem(k: string, v: string): void {
if (isSupported && localStorage) {
localStorage.setItem(k, v);
}
}
export function removeItem(k: string): void {
if (isSupported && localStorage) {
localStorage.removeItem(k);
}
}