Gathering detailed insights and metrics for @m4dm4x/pocketstore
Gathering detailed insights and metrics for @m4dm4x/pocketstore
Gathering detailed insights and metrics for @m4dm4x/pocketstore
Gathering detailed insights and metrics for @m4dm4x/pocketstore
A lightweight, type-safe storage library for browser and Node.js environments with support for namespacing, TTL, and encryption
npm install @m4dm4x/pocketstore
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
4 Stars
20 Commits
1 Forks
2 Watchers
2 Branches
1 Contributors
Updated on Jun 06, 2025
Latest Version
1.1.0
Package Id
@m4dm4x/pocketstore@1.1.0
Unpacked Size
17.41 kB
Size
6.39 kB
File Count
5
NPM Version
10.8.2
Node Version
18.20.8
Published on
Apr 21, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
8
A lightweight, type-safe storage library for browser and Node.js environments with support for namespacing, TTL, and basic obfuscation.
1# Using npm 2npm install @m4dm4x/pocketstore 3 4# Using yarn 5yarn add @m4dm4x/pocketstore 6 7# Using pnpm 8pnpm add @m4dm4x/pocketstore
Perfect for storing user preferences, theme settings, or UI state that should persist across page reloads:
1const settingsStore = createStore<{theme: string, fontSize: number}>('settings'); 2settingsStore.set('userPrefs', { theme: 'dark', fontSize: 14 });
Automatically save form data to prevent loss during accidental page refreshes:
1const formStore = createStore('forms', { autoCleanup: true }); 2formStore.set('draft', formData, 3600); // Auto-expires after 1 hour
Cache API responses with automatic expiration:
1const cacheStore = createStore('api-cache', { autoCleanup: true }); 2cacheStore.set('user-data', apiResponse, 300); // Cache for 5 minutes
Handle session data with automatic cleanup:
1const sessionStore = createStore('session', { 2 storage: 'session', 3 autoCleanup: true 4}); 5sessionStore.set('auth', { token: '...', user: '...' }, 1800); // 30 minutes
Store data that needs to be shared between browser tabs:
1const sharedStore = createStore('shared'); 2sharedStore.set('notification', { message: 'New update!' });
Data Sensitivity
obfuscate: true
only for non-sensitive dataTTL & Cleanup
autoCleanup
to automatically remove expired itemsclear()
when handling sensitive dataStorage Limitations
Storage Type
localStorage
for persistent datasessionStorage
for temporary session dataAutomatic Cleanup
autoCleanup
only when necessaryData Size
Feature | Chrome | Firefox | Safari | Edge | IE11 |
---|---|---|---|---|---|
Basic Storage | ✅ | ✅ | ✅ | ✅ | ✅ |
TTL Support | ✅ | ✅ | ✅ | ✅ | ✅ |
Obfuscation | ✅ | ✅ | ✅ | ✅ | ✅ |
TypeScript | ✅ | ✅ | ✅ | ✅ | ✅ |
SSR Support | ✅ | ✅ | ✅ | ✅ | ✅ |
Feature | Pocketstore | localforage | store.js | js-cookie |
---|---|---|---|---|
Size (min+gzip) | 2KB | 8KB | 2KB | 1KB |
API Type | Promise-free | Promise-based | Sync | Sync |
Storage Types | localStorage, sessionStorage, memory | IndexedDB, WebSQL, localStorage | localStorage, memory | Cookies |
TypeScript | ✅ Native | ⚠️ Types available | ⚠️ Types available | ⚠️ Types available |
SSR Support | ✅ Built-in | ❌ Requires setup | ✅ Built-in | ✅ Built-in |
Namespacing | ✅ Built-in | ❌ Manual | ❌ Manual | ✅ Built-in |
TTL Support | ✅ Built-in | ❌ Manual | ❌ Manual | ✅ Built-in |
Auto Cleanup | ✅ Built-in | ❌ No | ❌ No | ✅ Built-in |
Type Safety | ✅ Full | ⚠️ Partial | ⚠️ Partial | ⚠️ Partial |
Browser Support | Modern + IE11 | Modern only | Modern + IE8 | All browsers |
Simplicity First
Modern Features
Universal Usage
Developer Experience
1import { createStore } from '@m4dm4x/pocketstore'; 2 3// Create a store with a namespace 4const store = createStore('myapp'); 5 6// Store a value 7store.set('user', { name: 'John', age: 30 }); 8 9// Get a value 10const user = store.get('user'); // { name: 'John', age: 30 } 11 12// Remove a value 13store.remove('user'); 14 15// Clear all values in the namespace 16store.clear();
1const store = createStore('myapp'); 2 3// Set and get values 4store.set('theme', 'dark'); 5const theme = store.get('theme'); // 'dark' 6 7// Remove values 8store.remove('theme'); 9const removedTheme = store.get('theme'); // null
1const store = createStore('myapp'); 2 3// Set a value that expires in 60 seconds 4store.set('token', '123456', 60); 5 6// Value is available until TTL expires 7const token = store.get('token'); // '123456' 8 9// After 60 seconds: 10const expiredToken = store.get('token'); // null
1const store = createStore('myapp', { 2 obfuscate: true, 3 secret: 'your-secret-key' 4}); 5 6// Values are automatically obfuscated before storage 7store.set('data', { apiKey: '12345' }); 8 9// Values are automatically deobfuscated when retrieved 10const data = store.get('data'); // { apiKey: '12345' }
⚠️ Security Note: The obfuscation feature is NOT encryption and should NOT be used for sensitive data. It provides basic obfuscation only and is suitable for non-sensitive data that you want to make slightly harder to read in the browser's dev tools.
1const store = createStore('myapp', { 2 autoCleanup: true // Enable automatic cleanup 3}); 4 5// Set some values with TTL 6store.set('temp1', 'value1', 1); // Expires in 1 second 7store.set('temp2', 'value2', 60); // Expires in 60 seconds 8 9// After 2 seconds: 10store.getAll(); // Automatically cleans up expired items 11// Returns: { temp2: 'value2' }
1// Use localStorage (default) 2const localStore = createStore('myapp'); 3 4// Use sessionStorage 5const sessionStore = createStore('myapp', { 6 storage: 'session' 7});
1// Create stores with different namespaces 2const userStore = createStore('users'); 3const settingsStore = createStore('settings'); 4 5// Values don't conflict even with the same key 6userStore.set('data', { name: 'John' }); 7settingsStore.set('data', { theme: 'dark' }); 8 9userStore.get('data'); // { name: 'John' } 10settingsStore.get('data'); // { theme: 'dark' }
1const store = createStore('myapp'); 2 3// Check if a key exists 4store.has('user'); // true/false 5 6// Get all keys 7const keys = store.keys(); // ['user', 'theme', ...] 8 9// Get all values 10const all = store.getAll(); // { user: {...}, theme: 'dark', ... } 11 12// Initialize store (cleans up expired items if autoCleanup is enabled) 13store.init();
createStore<T>(namespace: string, options?: StoreOptions)
Creates a new store instance.
namespace
: String to prefix all keys withoptions
: Configuration object (optional)
storage
: Storage type ('local' | 'session')obfuscate
: Enable basic obfuscation (boolean)secret
: Obfuscation secret key (required if obfuscate is true)autoCleanup
: Enable automatic cleanup of expired items (boolean)Object with methods:
set(key: string, value: T, ttlSeconds?: number): void
get(key: string): T | null
remove(key: string): void
clear(): void
has(key: string): boolean
keys(): string[]
getAll(): Record<string, T>
init(): void
The library includes TypeScript definitions out of the box:
1import { createStore } from '@m4dm4x/pocketstore'; 2 3interface UserData { 4 name: string; 5 age: number; 6} 7 8const store = createStore<UserData>('myapp'); 9store.set('user', { name: 'John', age: 30 }); 10const user = store.get('user'); // Type is UserData | null
The library automatically falls back to in-memory storage when running in Node.js or SSR environments, making it safe to use in server-side rendered applications.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
Give a ⭐️ if this project helped you!
No vulnerabilities found.
No security vulnerabilities found.