{"_id":"@asaidimu/browser-store","_rev":"4-6fa3878f6f6a4848b4bce26776429304","name":"@asaidimu/browser-store","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@asaidimu/browser-store","version":"1.0.0","keywords":["tooling"],"author":{"name":"Saidimu","email":"47994458+asaidimu@users.noreply.github.com"},"license":"MIT","_id":"@asaidimu/browser-store@1.0.0","maintainers":[{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"}],"homepage":"https://github.com/asaidimu/#readme","bugs":{"url":"https://github.com/asaidimu//issues"},"dist":{"shasum":"5ec7faf5507b89d65faf54e03b44cd236ab8c3a0","tarball":"https://registry.npmjs.org/@asaidimu/browser-store/-/browser-store-1.0.0.tgz","fileCount":7,"integrity":"sha512-C7dMAOeLISjzRsak97pQbxKGObbZ3HTdjH7XG1cXcCnghmOcWHNz+CWxVVfXSBZFXp1DGBpLr9WQQE3EY0wIjQ==","signatures":[{"sig":"MEYCIQDwo+z2a4FYoJf3Dy1oIY9GoyMo08JY6oNVhq9qSKyQlAIhAMlpsRFag2+1ZfwP1FDsvktrCk3LG1JrpM34vRXzP85t","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9338},"main":"index.js","types":"index.d.ts","gitHead":"2a25f9970167a38d5da4e08c29773b38e4ecbc25","_npmUser":{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"},"repository":{"url":"git+https://github.com/asaidimu/.git","type":"git"},"_npmVersion":"10.5.2","description":"A simple wrapper around localstorage and session storage","directories":{},"_nodeVersion":"20.13.1","publishConfig":{"tag":"latest","access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.0.3"},"_npmOperationalInternal":{"tmp":"tmp/browser-store_1.0.0_1730191848544_0.8254882352773236","host":"s3://npm-registry-packages"},"deprecated":"⚠️ WARNING: This package is deprecated and will no longer receive updates or support. Please look into '@asaidimu/utils' for alternatives and future development. Use of this package in new projects is discouraged."},"1.0.1":{"name":"@asaidimu/browser-store","version":"1.0.1","keywords":["tooling"],"author":{"name":"Saidimu","email":"47994458+asaidimu@users.noreply.github.com"},"license":"MIT","_id":"@asaidimu/browser-store@1.0.1","maintainers":[{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"}],"homepage":"https://github.com/asaidimu/#readme","bugs":{"url":"https://github.com/asaidimu//issues"},"dist":{"shasum":"dd3a41159151b0134734bcaa52d718b79f461817","tarball":"https://registry.npmjs.org/@asaidimu/browser-store/-/browser-store-1.0.1.tgz","fileCount":7,"integrity":"sha512-6aSuwLZwIfRaL/VTFw1FPt6X6uhg7OGp5mQMbCa97r3+bAzYG7hauubmDGiJsV8ylOCOYwS3Do1cAqQ4M+Fhiw==","signatures":[{"sig":"MEQCIGe5QfCDMkgXf+aQ0O+Di/jrAan95jyefUMYUkz3sGaaAiBk7/zNfH3jsNnxtG/05x0sNMSq/BribYunsh/V+TmnaA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":13843},"main":"index.js","types":"index.d.ts","gitHead":"a98f1575a2d134d6d53fa3116061a50172b96661","_npmUser":{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"},"repository":{"url":"git+https://github.com/asaidimu/.git","type":"git"},"_npmVersion":"10.5.2","description":"A simple wrapper around localstorage and session storage","directories":{},"_nodeVersion":"20.13.1","publishConfig":{"tag":"latest","access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.0.3"},"_npmOperationalInternal":{"tmp":"tmp/browser-store_1.0.1_1730192328664_0.15458672590635825","host":"s3://npm-registry-packages"},"deprecated":"⚠️ WARNING: This package is deprecated and will no longer receive updates or support. Please look into '@asaidimu/utils' for alternatives and future development. Use of this package in new projects is discouraged."},"1.0.2":{"name":"@asaidimu/browser-store","version":"1.0.2","keywords":["tooling"],"author":{"name":"Saidimu","email":"47994458+asaidimu@users.noreply.github.com"},"license":"MIT","_id":"@asaidimu/browser-store@1.0.2","maintainers":[{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"}],"homepage":"https://github.com/asaidimu/browser-store/#readme","bugs":{"url":"https://github.com/asaidimu/browser-store/issues"},"dist":{"shasum":"0e04788a29c1709eeec1bfcd92a033962dfaee73","tarball":"https://registry.npmjs.org/@asaidimu/browser-store/-/browser-store-1.0.2.tgz","fileCount":7,"integrity":"sha512-UuyKzNpSN1tz72MKCJ/zgsDUM0RcL2mahxqBJIPKLU4/QNQnOWw6Ljwz0oFM384eiWZp02cDGQ3xVqlaZi2xAw==","signatures":[{"sig":"MEUCIQCWaAMX62Ex146sz+LCEDOWLG5/CYIpCwOI8XPp9PhAEgIgR64pLmAueY4slgexrNgsfKTdiRnGh1gyxTCEpXEh8P0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":14081},"main":"index.js","types":"index.d.ts","gitHead":"fce87eca3c5879b9bb0e4926c9719587198669e0","_npmUser":{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"},"repository":{"url":"git+https://github.com/asaidimu/browser-store.git","type":"git"},"_npmVersion":"10.8.2","description":"A simple wrapper around localstorage and session storage","directories":{},"_nodeVersion":"20.19.1","publishConfig":{"tag":"latest","access":"public","registry":"https://registry.npmjs.org/"},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.0.3"},"_npmOperationalInternal":{"tmp":"tmp/browser-store_1.0.2_1748081379623_0.5418876707542608","host":"s3://npm-registry-packages-npm-production"},"deprecated":"⚠️ WARNING: This package is deprecated and will no longer receive updates or support. Please look into '@asaidimu/utils' for alternatives and future development. Use of this package in new projects is discouraged."}},"time":{"created":"2024-10-29T08:50:48.450Z","modified":"2025-05-24T10:13:07.675Z","1.0.0":"2024-10-29T08:50:48.723Z","1.0.1":"2024-10-29T08:58:48.870Z","1.0.2":"2025-05-24T10:09:39.809Z"},"bugs":{"url":"https://github.com/asaidimu/browser-store/issues"},"author":{"name":"Saidimu","email":"47994458+asaidimu@users.noreply.github.com"},"license":"MIT","homepage":"https://github.com/asaidimu/browser-store/#readme","keywords":["tooling"],"repository":{"url":"git+https://github.com/asaidimu/browser-store.git","type":"git"},"description":"A simple wrapper around localstorage and session storage","maintainers":[{"name":"asaidimu","email":"lolokilesaidimu@gmail.com"}],"readme":"# @asaidimu/browser-store\n## TypeScript Local Storage Manager\n\n⚠️ WARNING: This package is deprecated and will no longer receive updates or support. Please look into '@asaidimu/utils' for an alternative. Use of this package in new projects is discouraged.\n\n[![MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue?logo=typescript)](https://www.typescriptlang.org/)\n\nA type-safe, robust wrapper around browser's Storage API with cross-tab synchronization support. Built with TypeScript for maximum type safety and developer experience.\n\n## ✨ Features\n\n- 🔒 **Type-safe**: Full TypeScript support with precise type inference\n- 🔄 **Cross-tab synchronization**: Real-time updates across browser tabs\n- 🎯 **Namespacing**: Prefix support to avoid key collisions\n- 🧹 **Memory efficient**: Automatic cleanup of event listeners\n- 🛡️ **Error handling**: Graceful handling of storage quota and parsing errors\n- 💪 **Flexible**: Works with both localStorage and sessionStorage\n\n## 📦 Installation\n\n```bash\nnpm install @asaidimu/browser-store\n# or\nyarn add @asaidimu/browser-store\n# or\npnpm add @asaidimu/browser-store\n```\n\n## 🚀 Quick Start\n\n```typescript\nimport createLocalStore from '@asaidimu/browser-store';\n\n// Define your store structure\ninterface MyStore {\n  user: {\n    name: string;\n    age: number;\n  };\n  settings: {\n    theme: 'light' | 'dark';\n    notifications: boolean;\n  };\n}\n\n// Create a store instance\nconst store = createLocalStore<MyStore>({\n  prefix: 'myApp:', // Optional prefix for all keys\n});\n\n// Set values\nstore.set('user', { \n  name: 'John Doe', \n  age: 30 \n});\n\n// Partial updates\nstore.update('user', { \n  age: 31  // Only updates age, preserves name\n});\n\n// Get values\nconst user = store.get('user');\nconsole.log(user?.name); // \"John Doe\"\n\n// Listen for changes (including from other tabs)\nconst cleanup = store.onChange('settings', (current, previous) => {\n  console.log('Settings changed:', { current, previous });\n});\n\n// Remove specific key\nstore.clear('user');\n\n// Clear all data with prefix\nstore.clearAll();\n\n// Clean up listeners when done\ncleanup();\n```\n\n## 📖 API Reference\n\n### `createLocalStore<T>(options?: StoreOptions): LocalStore<T>`\n\nCreates a new store instance.\n\n#### Options\n\n```typescript\ninterface StoreOptions {\n  storage?: Storage;        // defaults to localStorage\n  prefix?: string;         // namespace prefix for keys\n}\n```\n\n#### Methods\n\n- **`set<K>(key: K, value: T[K]): void`**  \n  Sets a value for a key, replacing any existing value.\n\n- **`update<K>(key: K, value: Partial<T[K]>): void`**  \n  Partially updates an existing value, preserving unspecified fields.\n\n- **`get<K>(key: K): T[K] | null`**  \n  Retrieves a value by key. Returns null if not found.\n\n- **`clear<K>(key: K): void`**  \n  Removes a specific key and its value.\n\n- **`clearAll(): void`**  \n  Removes all values with the store's prefix.\n\n- **`onChange<K>(key: K, callback: (current: T[K] | null, previous?: T[K] | null) => void): () => void`**  \n  Subscribes to changes for a specific key. Returns a cleanup function.\n\n## 🔥 Advanced Usage\n\n### Cross-Tab Communication\n\n```typescript\n// Tab 1\nconst store = createLocalStore<MyStore>({ prefix: 'myApp:' });\nstore.onChange('settings', (current) => {\n  console.log('Settings updated in another tab:', current);\n});\n\n// Tab 2\nconst store2 = createLocalStore<MyStore>({ prefix: 'myApp:' });\nstore2.set('settings', { theme: 'dark', notifications: true });\n// Tab 1 will log the new settings\n```\n\n### Using with SessionStorage\n\n```typescript\nconst sessionStore = createLocalStore<MyStore>({\n  storage: window.sessionStorage,\n  prefix: 'myApp:',\n});\n```\n\n### Type-Safe Partial Updates\n\n```typescript\ninterface User {\n  name: string;\n  age: number;\n  preferences: {\n    newsletter: boolean;\n    theme: string;\n  };\n}\n\ninterface MyStore {\n  user: User;\n}\n\nconst store = createLocalStore<MyStore>();\n\n// This will error if fields don't match User type\nstore.update('user', {\n  age: 32,\n  preferences: {\n    newsletter: true,\n  },\n});\n```\n\n## ⚠️ Error Handling\n\nThe library handles common errors gracefully:\n\n- Storage quota exceeded\n- JSON parsing errors\n- Invalid data types\n- Missing keys\n\n```typescript\ntry {\n  store.set('user', { /* large data */ });\n} catch (error) {\n  if (error instanceof Error) {\n    console.error('Storage operation failed:', error.message);\n  }\n}\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n## 📝 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","readmeFilename":"README.md"}