Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@jmondi/browser-storage
Advanced tools
An abstracted storage library for browser applications that interfaces with localStorage, sessionStorage, in-memory storage, or any custom serializer. It provides serialization capabilities with optional key prefixing for better storage management.
pnpm add @jmondi/browser-storage
For Deno:
import { LocaleStorage, SessionStorage, BrowserStorage } from "https://deno.land/x/browser_storage"
LocalStorage
and SessionStorage
are wrappers for window.localStorage
and window.sessionStorage
.
Persists after closing browser:
import { LocalStorage } from "@jmondi/browser-storage";
const storage = new LocalStorage();
storage.set("user2", { email: "hermoine@hogwarts.com", name: "Hermoine" });
console.log(storage.get("user2")); // { email: "hermoine@hogwarts.com", name: "Hermoine" }
Resets on browser close:
import { SessionStorage } from "@jmondi/browser-storage";
const storage = new SessionStorage();
storage.set("user2", { email: "hermoine@hogwarts.com", name: "Hermoine" });
console.log(storage.get("user2")); // { email: "hermoine@hogwarts.com", name: "Hermoine" }
import { type Adapter, BrowserStorage } from "@jmondi/browser-storage";
import Cookies, { type CookieAttributes } from "js-cookie";
export class CookieAdapter implements Adapter {
getItem(key: string): string | null { return Cookies.get(key) ?? null; }
removeItem(key: string): void { Cookies.remove(key); }
setItem(key: string, value: string, config: CookieAttributes): void { Cookies.set(key, value, config); }
}
const storage = new BrowserStorage({ prefix: "app_", adapter: new CookieAdapter() });
storage.set("user2", { email: "hermoine@hogwarts.com", name: "Hermoine" }, { expires: 5 });
console.log(storage.get("user2"));
define
for individual keys:const storage = new BrowserStorage();
const USER_COOKIE = storage.define<{ email: string }>("user_info");
USER_COOKIE.set({ email: "jason@example.com" });
defineGroup
for key groups:const storage = new BrowserStorage();
const GROUP = storage.defineGroup({ token: "refresh_token", user: "user_info" });
GROUP.token.set("newtoken");
GROUP.user.set({ email: "jason@example.com" });
Optional settings: prefix
(key prefix), serializer
(defaults to JSON
).
import { BrowserStorage } from "./index.ts";
const storage = new LocalStorage({ prefix: 'app_', serializer: JSON });
To create a custom serializer, implement parse
and stringify
.
import superjson from "superjson";
import { StorageSerializer } from "@jmondi/browser-storage";
export class SuperJsonSerializer implements StorageSerializer {
parse<T = unknown>(value: string): T { return superjson.parse(value); }
stringify<T = unknown>(value: T): string { return superjson.stringify(value); }
}
FAQs
Utilities for local and session browser storage.
We found that @jmondi/browser-storage demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.