cross-domain-storage

WebJar for cross-domain-storage

License

License

ISC
Categories

Categories

Doma Data ORM
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

cross-domain-storage
Last Version

Last Version

1.0.8
Release Date

Release Date

Type

Type

jar
Description

Description

cross-domain-storage
WebJar for cross-domain-storage
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/MatthewLarner/cross-domain-storage

Download cross-domain-storage

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/cross-domain-storage/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>cross-domain-storage</artifactId>
    <version>1.0.8</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/cross-domain-storage/
implementation 'org.webjars.npm:cross-domain-storage:1.0.8'
// https://jarcasting.com/artifacts/org.webjars.npm/cross-domain-storage/
implementation ("org.webjars.npm:cross-domain-storage:1.0.8")
'org.webjars.npm:cross-domain-storage:jar:1.0.8'
<dependency org="org.webjars.npm" name="cross-domain-storage" rev="1.0.8">
  <artifact name="cross-domain-storage" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='cross-domain-storage', version='1.0.8')
)
libraryDependencies += "org.webjars.npm" % "cross-domain-storage" % "1.0.8"
[org.webjars.npm/cross-domain-storage "1.0.8"]

Dependencies

compile (2)

Group / Artifact Type Version
org.webjars.npm : crel jar [3.0.0,4)
org.webjars.npm : try-parse-json jar [1.0.0,2)

Project Modules

There are no modules declared in this project.

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.

Versions

Version
1.0.8