First Release of Claw3D (#11)
Co-authored-by: iamlukethedev <iamlukethedev@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
|
||||
const ensureLocalStorage = () => {
|
||||
if (typeof window === "undefined") return;
|
||||
const existing = window.localStorage as unknown as Record<string, unknown> | undefined;
|
||||
if (
|
||||
existing &&
|
||||
typeof existing.getItem === "function" &&
|
||||
typeof existing.setItem === "function" &&
|
||||
typeof existing.removeItem === "function" &&
|
||||
typeof existing.clear === "function"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const store = new Map<string, string>();
|
||||
const storage = {
|
||||
get length() {
|
||||
return store.size;
|
||||
},
|
||||
clear() {
|
||||
store.clear();
|
||||
},
|
||||
getItem(key: string) {
|
||||
return store.has(String(key)) ? store.get(String(key)) ?? null : null;
|
||||
},
|
||||
key(index: number) {
|
||||
return Array.from(store.keys())[index] ?? null;
|
||||
},
|
||||
removeItem(key: string) {
|
||||
store.delete(String(key));
|
||||
},
|
||||
setItem(key: string, value: string) {
|
||||
store.set(String(key), String(value));
|
||||
},
|
||||
};
|
||||
|
||||
Object.defineProperty(window, "localStorage", {
|
||||
value: storage,
|
||||
configurable: true,
|
||||
});
|
||||
};
|
||||
|
||||
ensureLocalStorage();
|
||||
Reference in New Issue
Block a user