0.0.6 • Published 9 years ago

dev-storage v0.0.6

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

dev-storage

Local development data storage utility.

Introduction

A simple to use utility library for interacting with HTML5's localStorage. (or a super simplified node version if used on a node server)

Useful when, e.g., working on the frontend side of a project, before connecting to an API service or similar.

API Documentation

.init

Initialize storage with data.

var storage = require('dev-storage'),
    initialData = { foo: { bar: "baz" } };

storage.init(initialData);

storage.get("foo", "bar"); // -> baz

.set

Set data for either an entire collection/category, or set data for a specific key within a collection/category.

var storage = require('dev-storage');

storage.set("collection1", "key1", "val1");
storage.get("collection1"); // -> { key1: "val1" }

storage.set("collection2", { key1: { nestedkey1: "nestedval1" } });
storage.get("collection2", "key1"); // -> { nestedkey1: "nestedval1" }

.get

Get data from a specific key within a collection/category, or get all data from a collection/category. See .set for examples.

.all

Get all data in storage.

var storage = require('dev-storage');

storage.all(); // -> {}

storage.set("foo", "bar");
storage.set("one", "two");

storage.all(); // -> { foo: "bar", one: "two" }

.empty

Check whether or not storage is empty.

var storage = require('dev-storage');

storage.all();   // -> {}
storage.empty(); // -> true

storage.set("foo", "bar");
storage.empty(); // -> false

.filter

Search with filter and extract all matching items in an array.

var storage = require('dev-storage');

storage.set("foo", { bar: "baz" });

storage.filter("foo", { bar: "baz" }); // -> [{ bar: "baz" }]
storage.filter("foo", { bar: "woo" }); // -> []

.find

Find the first item in a collection/category matching the specified conditions.

var storage = require('dev-storage');

storage.set("foo", { one: { a: "b" } }, two: { c: "d" });

storage.find("foo", { c: "d" }); // -> { c: "d" }
storage.find("foo", { c: "e" }); // -> undefined

.delete

Delete a specific key from a collection/category.

var storage = require('dev-storage');

storage.set("foo", { bar: 1, baz: 2 });
storage.get("foo"); // -> { bar: 1, baz: 2 }

storage.delete("foo", "bar");
storage.get("foo"); // -> { baz: 2 }

.flush

Clear all data in storage.

var storage = require('dev-storage');

storage.init({ foo: "bar" });
storage.all(); // -> { foo: "bar" }

storage.flush();
storage.all(); // -> {}
0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago