[Feature] Add browser storage utilities#671
Merged
titouanmathis merged 11 commits intomainfrom Mar 26, 2026
Merged
Conversation
Export Size@studiometa/js-toolkit
Unchanged@studiometa/js-toolkit
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #671 +/- ##
==========================================
- Coverage 98.96% 98.64% -0.32%
==========================================
Files 117 118 +1
Lines 2604 2801 +197
Branches 655 719 +64
==========================================
+ Hits 2577 2763 +186
- Misses 25 34 +9
- Partials 2 4 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Replace provider identity checks with capability-based syncEvent flag - Add prefix option for key namespacing - Add default value support in get() - Add createUrlSearchParamsProvider() and createUrlSearchParamsInHashProvider() factories with replace option (replaceState vs pushState) - Use hasWindow() helper consistently - Preserve hash when setting URL search params - Omit provider from convenience hook options type - Update and expand tests (47 tests)
Switch URL providers to use replaceState by default to avoid polluting browser history. Add push option to opt into pushState when needed.
- has(key): check if a key exists in storage - keys(): list all keys (filtered by prefix when set) - clear(): remove all entries (only prefixed keys when prefix is set, notifies all subscribers with null) - Added keys() and clear() to StorageProvider interface - Implemented on all 4 providers (localStorage, sessionStorage, URL search params, URL hash params) - 10 new tests (58 total)
002541a to
af79100
Compare
titouanmathis
added a commit
that referenced
this pull request
Apr 4, 2026
- Remove syncEvent from sessionStorageProvider (no cross-tab sync) - Add storageArea to StorageProvider interface for StorageEvent filtering - Filter StorageEvents by storageArea to prevent cross-provider interference - Add try/catch in JSON deserializer for malformed data resilience - Fall through to default value when deserialization fails - Remove unused generic from StorageProvider interface - Add keys() and clear() stubs to custom provider test mocks - Add JSON serialization notes to URL storage docs - Add cleanup warning to createStorage docs - Add tests for storageArea filtering and JSON resilience
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔗 Linked issue
No issue.
❓ Type of change
📚 Description
Add browser storage utilities with a unified API supporting multiple backends.
Features
createStorage<T>(options)— Factory to create a typed, multi-key storage instanceuseLocalStorage()— localStorage with cross-tab sync viastorageeventuseSessionStorage()— sessionStorage for session-scoped datauseUrlSearchParams()— URL search params (?key=value) for shareable stateuseUrlSearchParamsInHash()— URL hash params (#key=value) for client-side stateAPI
get(key)/get(key, defaultValue)— Read values with optional defaultsset(key, value)— Write values (passnullto remove)has(key)— Check if a key existskeys()— List all keys (prefix-filtered when namespaced)clear()— Remove all entries (prefix-scoped when namespaced)subscribe(key, callback)— React to changes (local + external sync)destroy()— Clean up all listenersOptions
prefix— Key namespacing (e.g."myapp:"stores"theme"as"myapp:theme")serializer— Custom serialize/deserialize (defaults to JSON)push— URL providers: usepushStateinstead ofreplaceState(default:false)Architecture
syncEventcapability flag for automatic event syncreplaceStateby default for URL providers (opt intopushStatewith{ push: true })hasWindow()guardsDocumentation
Full docs added under
/utils/storage/with pages for each utility, providers guide, and custom provider example.📝 Checklist