New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cross-domain-storage

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cross-domain-storage

Cross domain local storage

  • 2.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
decreased by-8.55%
Maintainers
2
Weekly downloads
 
Created
Source

Allows sharing of local storage across domains.

Use a host to give access to local storage.

Use a guest to gain access to the local storage on a host.

Install

npm i cross-domain-storage

Usage

Host

var createHost = require('cross-domain-storage/host');
host(allowedDomains)

Call with an array of allowed domains.

var storageHost = createHost([
    {
        origin: 'http://www.foo.com',
        allowedMethods: ['get', 'set', 'remove'],
    },
    {
        origin: 'http://www.bar.com',
        allowedMethods: ['get'],
    },
]);
host.close()
storageHost.close();
// storageHost will no longer allow access from guests and can no longer be used.

Guest

var createGuest = require('cross-domain-storage/guest');
guest(hostURL)

Create a guest and connect to the host.

Any methods that are called while connecting are queued up and handled seamlessly.

// Hosted on http://www.foo.com
var bazStorage = createGuest('http://www.baz.com/accessStorage');
guest.get(key, callback)
bazStorage.get('fizz', function(error, value) {
    // value for the key of 'fizz' will be retrieved from localStorage on www.baz.com
});
guest.set(key, value, callback)

NOTE: The keys and the values in localStorage are always strings thus objects, numbers etc used as keys or values will be automatically converted to strings.

bazStorage.set('foo', 'bar', function(error, data) {
    // foo is now set to 'bar'
});
guest.remove(key, callback)
bazStorage.remove('foo', function(error, data) {
    // foo is now removed
});
guest.close()
bazStorage.close();
//connection is now closed and bazStorage can no longer be used.

FAQs

Package last updated on 19 Aug 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc