A friendly, tiny, synchronous, namespaced, and dependency free local storage solution.
npm install local-syncA friendly, tiny, and cross-browser local storage solution:
✓ No dependencies
✓ Synchronous
✓ Namespaced storage support
✓ In-memory fallback
```
yarn add local-sync
CDN
Common JS
``
https://unpkg.com/local-sync@x.x.x/dist/cjs/local-sync.js
https://unpkg.com/local-sync@x.x.x/dist/cjs/local-sync.min.js
ES Module
``
https://unpkg.com/local-sync@x.x.x/dist/esm/local-sync.js
https://unpkg.com/local-sync@x.x.x/dist/esm/local-sync.min.js
UMD
``
https://unpkg.com/local-sync@x.x.x/dist/umd/local-sync.js
https://unpkg.com/local-sync@x.x.x/dist/umd/local-sync.min.js
See API Documentation.
Set or get the current bucket. Subsequent methods operate only in the current bucket namespace.
`js
ls = new LocalSync() // default settings
ls = new LocalSync({ // custom settings
prefix: 'ocean',
bucket: 'fish',
separator: '~'
})
ls.setBucket('BikiniBottom') // => 'BikiniBottom'
ls.getBucket() // => 'BikiniBottom'
`
List all buckets in storage.
`js`
ls.allBuckets() // => [...buckets]
Use any JSON serializable data type.
`js
ls.set('bob', {name: 'SpongeBob'})
ls.get('bob')
// => {name: 'SpongeBob'}
ls.set('quotes', ['Squidward!'])
ls.get('quotes')
// => ['Squidward!]
`
Update stored objects and arrays.
`js
ls.put('bob', {address: '124 Conch Street'})
// => {name: 'SpongeBob', address: '124 Conch Street'}
ls.put('quotes', ['Why so crabby, Patty?'])
// => ['Squidward!', 'Why so crabby, Patty?']
`
List all keys in storage.
`js`
ls.keys()
// => ['bob', 'quotes']
List all values in storage.
`js`
ls.values()
// [
// {address: '124 Conch Street', name: 'SpongeBob'},
// ['Squidward!', 'Why so crabby, Patty?']
// ]
List all keys and values in storage.
`js`
ls.getAll()
// [
// {address: '124 Conch Street', name: 'SpongeBob'},
// {quotes: ['Squidward!', 'Why so crabby, Patty?']}
// ]
Remove a single value by key or clear all values.
`js`
ls.remove('bob')
ls.keys()
// => ['quotes']
Clear all keys and values.
`js``
ls.clear()
ls.keys()
// => []