πŸ“… You're Invited: Meet the Socket team at RSAC (April 28 – May 1).RSVP β†’
Socket
Sign inDemoInstall
Socket

local-sync

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

local-sync

A friendly, tiny, synchronous, namespaced, and dependency free local storage solution.

2.0.0
Source
npm
Version published
Weekly downloads
42
600%
Maintainers
1
Weekly downloads
Β 
Created
Source

Local Sync

A friendly, tiny, synchronous, namespaced, and dependency free local storage solution.

npm i local-sync -S

Usage

  • Buckets
  • set, get, put
  • remove, clear
  • keys, values, getAll

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()
// => []

API

new LocalSync([options])

Create a new Local Sync instance. Each instance can have its own prefix, buckets, and separator.

ParamTypeDefaultDescription
[options]Object{}Instance options.
[options.bucket]StringdefaultThe bucket namespace to use.
[options.prefix]StringlsThe key prefix namespace to use.
[options.separator]String.Separates prefix, bucket, and keys.

localSync.setBucket(bucket) β‡’ String

Set the current bucket. Methods will only operate on keys in this namespace.

Kind: instance method of LocalSync
Returns: String - The bucket name just set.

ParamTypeDescription
bucketStringThe bucket name.

localSync.getBucket() β‡’ String

Get the current bucket.

Kind: instance method of LocalSync
Returns: String - The current bucket name.

localSync.allBuckets() β‡’ Array.<String>

Get all buckets currently in storage.

Kind: instance method of LocalSync
Returns: Array.<String> - An array of bucket strings.

localSync.get(key) β‡’ *

Get a value from the current bucket.

Kind: instance method of LocalSync
Returns: * - The stored value at the specified key.

ParamTypeDescription
keyStringThe name of the key you want to retrieve the value of.

localSync.set(key, value) β‡’ *

Set a value in the current bucket.

Kind: instance method of LocalSync
Returns: * - The value that was just set.

ParamTypeDescription
keyStringThe name of the key you want to create/overwrite.
value*The value for this key.

localSync.put(key, value) β‡’ *

Update a value in the current bucket.

Kind: instance method of LocalSync
Returns: * - The updated value.

ParamTypeDescription
keyStringThe key under which the value to be updated is stored.
value*Value to assign to the stored object.

localSync.remove(key) β‡’ *

Remove a value from the current bucket.

Kind: instance method of LocalSync
Returns: * - The object just removed.

ParamTypeDescription
keyStringThe key under which the value to be deleted is stored.

localSync.clear()

Clears all values from the current bucket.

Kind: instance method of LocalSync

localSync.keys() β‡’ Array.<String>

Get all keys in the current bucket.

Kind: instance method of LocalSync
Returns: Array.<String> - An array of key strings.

localSync.values() β‡’ Array.<*>

Get all values in the current bucket.

Kind: instance method of LocalSync
Returns: Array.<*> - An array of values.

localSync.getAll() β‡’ Array.<Object>

Get all key/value pairs in the current bucket.

Kind: instance method of LocalSync
Returns: Array.<Object> - An array of objects {<key>: <value>}.

Β© 2015 TechnologyAdvice. API Docs by jsdoc-to-markdown.

Keywords

local

FAQs

Package last updated on 05 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts