Registry / storage / sync-storage

sync-storage

JSON →
library0.4.2jsnpmunverified

SyncStorage wraps React Native's asynchronous AsyncStorage to provide a synchronous API for reading and writing key-value pairs. Version 0.4.2 (stable, less frequent releases) loads all stored data into memory on init, enabling synchronous get/set/remove operations thereafter. It supports any value type (via JSON serialization) and returns promises for post-verification. Unlike raw AsyncStorage which requires async/await, SyncStorage simplifies simple data access in synchronous contexts but requires careful memory management for large datasets.

npm install sync-storage
INSTALL
IMPORT
SIG · SYNC-STORAGE
S
sync-storage
storagejavascriptv0.4.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import SyncStorage from 'sync-storage'
import { SyncStorage } from 'sync-storage'
The module exports a default singleton object. No named exports.
init
await SyncStorage.init()
SyncStorage.init() (without await, returns a Promise)
init must be called before using get/set/remove; it populates in-memory cache from AsyncStorage.
getAllKeys
SyncStorage.getAllKeys()
await SyncStorage.getAllKeys()
Returns array of keys synchronously after init; no longer returns a promise.
require
const SyncStorage = require('sync-storage')
const { SyncStorage } = require('sync-storage')
CommonJS supported but ESM recommended for tree shaking.

Demonstrates initializing SyncStorage, then using synchronous get/set/remove/getAllKeys with various data types.

import SyncStorage from 'sync-storage'; async function main() { await SyncStorage.init(); // must await before using sync methods SyncStorage.set('foo', { bar: [1, 2, 3] }); const value = SyncStorage.get('foo'); console.log(value); // { bar: [1, 2, 3] } SyncStorage.set('counter', 42); console.log(SyncStorage.get('counter')); // 42 SyncStorage.remove('counter'); console.log(SyncStorage.get('counter')); // undefined SyncStorage.set('a', 1); SyncStorage.set('b', 2); console.log(SyncStorage.getAllKeys()); // ['a', 'b'] } main().catch(console.error);
Debug
Known issues
breakinginit() must be called and awaited before any synchronous operations; otherwise get returns undefined.
fix
Call await SyncStorage.init() at app startup before any SyncStorage usage.
affects: >=0.1.0
gotchaSyncStorage keeps the entire AsyncStorage in memory; large datasets can cause memory issues on devices.
fix
Avoid storing large amounts of data with SyncStorage; use AsyncStorage directly for large data.
affects: >=0.1.0
deprecatedremove() returns a Promise but is often mistaken as synchronous; not awaiting it may lead to race conditions.
fix
Use await SyncStorage.remove(key) or .then() to ensure removal completes.
affects: >=0.1.0
gotchaCalling init() multiple times may cause duplicate data but no error; it re-initializes the in-memory store.
fix
Call init() exactly once during app lifecycle.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: undefined is not an object (evaluating 'SyncStorage.get')
SyncStorage was imported incorrectly or not imported at all.
fix
Ensure import SyncStorage from 'sync-storage'; is correct.
SyncStorage is not a function
Using { SyncStorage } named import instead of default import.
fix
Use import SyncStorage from 'sync-storage'; (no curly braces).
ReferenceError: Can't find variable: AsyncStorage
react-native AsyncStorage not installed or linked correctly.
fix
Install @react-native-async-storage/async-storage and link for React Native <0.60.
Possible Unhandled Promise Rejection: TypeError: null is not an object
init() not awaited before calling get/set/remove, so internal AsyncStorage key list is null.
fix
Add await before SyncStorage.init().
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
reactrequiredpeer dependency required by React Native
react-nativerequiredpeer dependency that must be installed for accessing AsyncStorage
Agent activity
26 hits · last 30 days
node
22
Amazon
1
OpenAI (training)
1
Resources
sync-storage — npm install sync-storage · libregistry