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

web-storage-es6

v1.2.0

Published

This is a library written in ES6. It provides an abstraction layer for using the HTML5 web storages, localStorage and sessionStorage. On top of utilizing these Storage types, a Global storage is introduced for temporary data storage.

Downloads

36

Readme

Web Storage ES6 Build Status Coveralls Status

This is a library written in ES6. It provides an abstraction layer for using the HTML5 web storages, localStorage and sessionStorage. On top of utilizing these Storage types, a Global storage is introduced for temporary data storage.

Installation

npm install --save web-storage-es6

Usage Summary

Overview

  • Local - A type of localStorage. Data persists until explicitly deleted by user. It has no expiration date
  • Session - A type of sessionStorage. Data lasts for as long as the browser is open and survives over page reloads
  • Global - Stores data in the global window variable. Data only lasts inside a single page session and will be destroyed upon page reload

Code

// Include library
const WebStorageES6 = require('web-storage-es6');

// Create a local storage with 'default' namespace
var localStorage = new WebStorageES6('Local');

// Create a session storage with 'default' namespace
var sessionStorage = new WebStorageES6('Session');

// Create a global storage with 'custom' namespace
var customGlobalStorage = new WebStorageES6('Global', 'custom');

// Sets 'var1' to 'value1'
localStorage.put('var1', 'value1');

// Gets 'var1'
localStorage.get('var1');

// Gets 'var1'. If 'var1' is not set, return 'default value'
localStorage.get('var1', 'default value');

// Checks if 'var1' exists
localStorage.has('var1');

// Removes 'var1' from storage
localStorage.forget('var1');

Don'ts

// Writing to storage is slow if you need to save repetitive data in loops
for (let i = 0; i < 100; i++) {
  storage.put('var' + i, i);
}

Dos

// Create data first
var data = {};

for (let i = 0; i < 100; i++) {
  data['var' + i] = i;
}

// Write at once
storage.populate(data);

// or append to existing data
storage.append(data);

API

Storage

Kind: global class
Access: public

new Storage(namespace, storage)

Constructor

| Param | Type | Description | | --- | --- | --- | | namespace | string | The namespace of storage | | storage | Object | The storage type |

storage.namespace ⇒ string

Get namespace

Kind: instance property of Storage
Returns: string - - The namespace
Access: public

storage.type ⇒ string

Get storage type

Kind: instance property of Storage
Returns: string - - The storage type
Access: public

storage._setData()

Save data to storage

Kind: instance method of Storage
Access: protected

storage._getData()

Get data from storage

Kind: instance method of Storage
Access: protected

storage._extend(obj, src)

Merge two objects

Kind: instance method of Storage
Access: protected
Returns: Object - Merged object

| Param | Type | Description | | --- | --- | --- | | obj | Object | Destination object | | src | Object | Source object |

storage.get(key, defaultValue)

Retrieve an item or return a default value

Kind: instance method of Storage
Access: public

| Param | Type | Default | Description | | --- | --- | --- | --- | | key | string | | The data key | | defaultValue | string | null | The default value | | | string | null | | The data value |

storage.put(key, value)

Store an item

Kind: instance method of Storage
Access: public

| Param | Type | Description | | --- | --- | --- | | key | string | The data key | | value | string | The data value |

storage.pull(key, defaultValue) ⇒ string

Retrieve an item and forget it

Kind: instance method of Storage
Returns: string - - The data value
Access: public

| Param | Type | Description | | --- | --- | --- | | key | string | The data key | | defaultValue | string | The default value |

storage.has(key) ⇒ boolean

Whether or not an item exists

Kind: instance method of Storage
Returns: boolean - - Whether or not item exists
Access: public

| Param | Type | Description | | --- | --- | --- | | key | string | The data key |

storage.populate(data)

Set all items

Kind: instance method of Storage
Access: public

| Param | Type | Description | | --- | --- | --- | | data | Object | Data object |

storage.all() ⇒ Object

Retrieve all items

Kind: instance method of Storage
Returns: Object - - All data
Access: public

storage.append(data)

Append to current items

Kind: instance method of Storage
Acess: public

| Param | Type | Description | | --- | --- | --- | | data | Object | Data to append |

storage.forget(key)

Remove an item

Kind: instance method of Storage
Access: public

| Param | Type | Description | | --- | --- | --- | | key | string | The data key |

storage.flush()

Remove all items

Kind: instance method of Storage
Access: public

License

MIT - See included LICENSE.md