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

origin-storage

v2.2.6

Published

A same-origin storage(IndexedDB/WebSQL/localStorage) for cross-domain access

Downloads

72

Readme

origin-storage

Node CI npm version

A same-origin storage for cross-domain access, it is based on localForage and supports IndexedDB, WebSQL and localStorage.

origin-storage uses localStorage in browsers with no IndexedDB or WebSQL support. And Safari is not supported.

Table of Contents

Motivation

When different Website domains need a same-origin storage container, we have to use iframe's same-origin policy Web local storage solution. localForage is an excellent storage library, it supports IndexedDB, WebSQL and localStorage, but it can't solve this problem directly.

That's why we have this library for same-origin storage based on localForage.

Installation

yarn add origin-storage

Usage and Example

  • Use OriginStorage on http://localhost:9000/storage.js:
import { OriginStorage } from 'origin-storage';

const originStorage = new OriginStorage();

If you need to set up a more secure origin control, you can set targetOrigin like this.

const originStorage = new OriginStorage({
  targetOrigin: 'http://example.com',
});
  • Create and host a Web page(http://localhost:9000/storage.html) containing JavaScript file storage.js.

  • Use OriginStorageClient on a cross-domain page:

import { OriginStorageClient } from 'origin-storage';

const originStorageClient = new OriginStorageClient({
  uri: 'http://localhost:9000/storage.html',
});

API

OriginStorage

  • new OriginStorage(options)
interface OriginStorageOptions extends IFrameTransportInternalOptions {
  /**
   * Enable read access to OriginStorage.
   */
  read?: boolean;
  /**
   * Enable write access to OriginStorage.
   */
  write?: boolean;
  /**
   * Enable broadcast data changes on OriginStorage.
   */
  broadcastChanges?: boolean;
  /**
   * Specify broadcastChannel name.
   */
  broadcastChannelName?: string;
}

OriginStorageClient

  • new OriginStorageClient(options)
interface OriginStorageClientOptions extends IFrameMainTransportOptions {
  /**
   * Specify the uri of an OriginStorage container.
   */
  uri: string;
  /**
   * Set storage options for localforage.
   */
  storageOptions?: LocalForageOptions;
}
  • OriginStorageClient instance methods.
interface IOriginStorageClient {
  /**
   * The callback will be called when the iframe is connected.
   */
  onConnect(callback: () => void): void;
  /**
   * The callback will be called when the storage is changed.
   */
  onChange(callback: (data: IChangeData) => void): Promise<{
    off: () => void;
    broadcastChanges: boolean;
  }>;
  /**
   * Get the value of the specified key.
   */
  getItem(key: string): Promise<any>;
  /**
   * Set the value of the specified key.
   */
  setItem(key: string, value: any): Promise<void>;
  /**
   * Remove the value of the specified key.
   */
  removeItem(key: string): Promise<void>;
  /**
   * Clear all key/value pairs in the storage.
   */
  clear(): Promise<void>;
  /**
   * Get the number of key/value pairs in the storage.
   */
  length(): Promise<number>;
  /**
   * Get the name of the nth key in the storage.
   */
  key(index: number): Promise<string>;
  /**
   * Get all keys in the storage.
   */
  keys(): Promise<string[]>;
}