npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cross-storage-plus

v1.1.1

Published

Cross-domain browser storage API that supports any kind of storage. More extensible and featured than [cross-storage](https://github.com/zendesk/cross-storage) and [cross-domain-storage](https://github.com/MatthewLarner/cross-domain-storage).

Downloads

7

Readme

cross-storage-plus

Cross-domain browser storage API that supports any kind of storage. More extensible and featured than cross-storage and cross-domain-storage.

🆘 Help this project by conttributing to its documentation or developing its roadmap.

Features

  • [x] Remote cross-domain storage initialization
  • [x] LocalStorage, SessionStorage and cookies support
  • [x] Custom storage provider
  • [ ] Origin validation in client and server
  • [ ] Method authorization per client domain
  • [ ] IndexedDB support

*Not checked features are in roadmap.

Basic Usage

What you will need first

Cross domain storage is designed to initialize a storage server inside a web application, that listens to commands sent to it.

In its way, the client inside another web application send commands to the server intialized in the first web application.

Then, you will need at least two web applications in different domains (one as the server).

1. Install it via package manager in both server and client apps

$ npm i --S cross-storage-plus

2. Initialize the server on server app

https://your-example-domain-server.com/cross-storage

require('cross-storage-plus').initializeServer();

3. Initialize the client on client apps

const CrossStorage = require('cross-storage-plus');

const storage = await CrossStorage.initializeClient('https://your-example-domain-server.com/cross-storage');

Default storage methods

By default, the initializeClient() method will always return the localStorage provider, so you can use the LocalStorage main methods (getItem, setItem, removeItem and clear), i.e.:

await storage.setItem('key', { complex: 'value' });

SessionStorage and cookie storage

You can change the storage provider to sessionStorage or cookie using the getProvider() method.

const cookieStorage = storage.getProvider('cookieStorage');
const value = cookieStorage.get('key');

ℹ When using cookie provider, you must use the storage methods as implemented in js-cookie (get, set, remove, getJSON).

Advanced Usage

⭐ Adding your own custom provider

Halt! See the template file for an entire example to make your client and server provider classes.

Basically, the client and server classes must implement:

Server

  • A constructor($window), where $window is the DOM Window object in the server.
  • A processCommand(command, commandArguments) method.

Client

  • A constructor(sendCommandFunction), where sendCommandFunction is the function to call by you class methods.
  • Your own class async methods

Then, you must add the provider to server and clients:

In the server:

const server = require('cross-storage-plus').initializeServer();

server.addProvider('custom', ProviderServer);

In the client:

storage.addProvider('custom', ProviderClient);