@veams/utility-storage

1.0.1 • Public • Published

npm version Gitter Chat

Storage

Description

This utility offers a simple API for storing Javascript objects in HTML5 web storage using distinct namespaces


Requirements


Installation

Installation with Veams

veams install u storage
veams -i u storage

Usage (API)

Just initialize on demand like this:

let myStorage = new Storage({
	type: 'permanent', // or 'session'
	name: 'someName' // custom namespace (e.g. from module)
});

Constructor

Storage(opts: StorageOptions)

/**
 * Constructor
 *
 * @param {Object} opts - options which will be passed as object
 * @param {String} opts.type - storage type ('permanent' || 'session')
 * @param {String} opts.name - namespace in which items will be saved
 */

Properties

  • length {Number} - item count

Methods

setItem(name:String, obj:Object)

/**
 * Set item
 *
 * @param {String} name - item name
 * @param {Object} obj - object to save
 */

getItem (name:String)

/**
 * Get item by name
 *
 * @param {String} name - item name
 * @return {Object} - object retrieved by item name
 */

getAllItems ()

/**
 * Get all items
 *
 * @public
 *
 * @return {Object} - object containing all items
 */

removeItem (name:String)

/**
 * Remove item by name
 *
 * @param {String} name - item name
 */

clear ()

/**
 * Clear all items
 */

Readme

Keywords

Package Sidebar

Install

npm i @veams/utility-storage

Weekly Downloads

4

Version

1.0.1

License

MIT

Unpacked Size

7.28 kB

Total Files

7

Last publish

Collaborators

  • andy-gutsche
  • sebastian-fitzner