Skip to content
This repository has been archived by the owner on Sep 30, 2021. It is now read-only.

A tiny synchronous local storage solution.

Notifications You must be signed in to change notification settings

TechnologyAdvice/local-sync

Repository files navigation

Circle CI Codecov npm

A friendly, tiny, and cross-browser local storage solution:

✓ No dependencies
✓ Synchronous
✓ Namespaced storage support
✓ In-memory fallback

NPM

CommonJS build that needs to be bundled in your app.

npm i local-sync -S

CDN

Browser ready build that can be included in a script tag.

https://cdn.taplatform.net/local-sync/x.x.x/local-sync.js
https://cdn.taplatform.net/local-sync/x.x.x/local-sync.min.js

API

See API Documentation.

Usage

Buckets

Set or get the current bucket. Subsequent methods operate only in the current bucket namespace.

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.

ls.allBuckets()                   // => [...buckets]

set, get, put

Use any JSON serializable data type.

ls.set('bob', {name: 'SpongeBob'})
ls.get('bob')
// => {name: 'SpongeBob'}

ls.set('quotes', ['Squidward!'])
ls.get('quotes')
// => ['Squidward!]

Update stored objects and arrays.

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?']

keys, values, getAll

List all keys in storage.

ls.keys()
// => ['bob', 'quotes']

List all values in storage.

ls.values()
// [
//   {address: '124 Conch Street', name: 'SpongeBob'},
//   ['Squidward!', 'Why so crabby, Patty?']
// ]

List all keys and values in storage.

ls.getAll()
// [
//   {address: '124 Conch Street', name: 'SpongeBob'},
//   {quotes: ['Squidward!', 'Why so crabby, Patty?']}
// ]

remove, clear

Remove a single value by key or clear all values.

ls.remove('bob')
ls.keys()
// => ['quotes']

Clear all keys and values.

ls.clear()
ls.keys()
// => []

Releasing

On the latest clean master run a build, commit and push, then:

npm run release:major
npm run release:minor
npm run release:patch

Credit

© 2016 TechnologyAdvice