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

mirrorstore

v1.0.8

Published

Mirror stored data across available storage mechanisms

Downloads

7

Readme

mirrorstore: Store data into multiple backends at once

Build Status

This module allows storage and retrieval of values across multiple backend storage mechanisms at the same time.

Currently, it supports:

  • LocalStorage

  • IndexedDB

  • WebSQL

  • Cookies

It will use all available backends when writing.

This module uses Promises for asynchronous operation.

Usage

Install via npm:

npm install --save mirrorstore

In your code:

var MirrorStore = require('mirrorstore');

var ms = new MirrorStore('MyDatabase')

var opts = {
    domain: '.example.com',
    path: '/',
    expires: 60 * 60 * 24 * 7,
    secure: false,
}

// You can store any kind of data...
ms.setItem('userId', '141562716', opts)
// Objects, too!
ms.setItem('prefs', {notify: true, volume: 0.7}, opts)

// Retrieve data by key
ms.getItem('prefs').then(function(value) {
    console.log(value)
})

ms.keys().then(function(keys) {
    console.log(keys)
})

// Remove data by key
ms.removeItem('prefs', opts).then(function() {
    // removed!
})

API

new MirrorStore([databaseName])

Creates a new instance of MirrorStore.

If databaseName is set, it will be used to partition data stored into IndexedDB and WebSQL databases. This value is also visible if browser asks user to allow storing additional data when the backend- and browser-specific limit is reached.

supports() -> Array

Returns an array of supported backends that will be used for storage.

setItem(key, value, [options]) -> Boolean

Write value under a key into all available backends.

Returns true.

See Options below for more information on options argument.

Note: it is not possible to store null or undefined value. If such a value is set, when fetched, it will be returned as undefined, as if it weren't set at all.

getItem(key) -> Mixed

Retrieve the value stored under the key from all available backends.

If value is available under any backend, it will be returned.

If a different value is available via different backends, the value with most occurrences will be returned.

removeItem(key, [options]) -> Boolean

Return the value stored under key from all available backends.

See Options below for more information on options argument.

keys() -> Array

Returns an array of all keys available in all storage backends.

Keys will be retrieved only from the database named during instantiation of this class (the databaseName argument to constructor).

Options

If options map is passed when invoking setItem() or removeItem() methods, it will be passed on to a cookie backend. This is important because a different cookie value can be visible depending on the current page path, whether or not a page is loaded via https, etc.

expires (Mixed)

When the cookie expires.

Possible values:

  • Infinity,

  • Number of seconds when to expire the cookie (e.g. 180 for 3 minutes),

  • Any parseable date or time string (e.g. 2016-01-01 00:00:00),

  • An instance of Date class,

  • unset: cookie will expire when the browser is closed,

Default: expires is not set.

domain (String)

A string indicating a valid domain where the cookie should be visible. The cookie will also be visible to all subdomains.

Default: Cookie is visible only to the domain or subdomain of the page where the cookie was created, except for Internet Explorer (visible on current domain/subdomain and all nested subdomains, too).

path (String)

A path under which cookie is visible (e.g. /admin/)

Default: /

secure (Boolean)

Either true or false, indicating if the cookie transmission requires a secure protocol (https).

Default: false, cookie will be transferred, regardless of https.

License

BSD 3-Clause License

Copyright (c) 2015, Boris Ćeranić