0.1.5 • Published 8 years ago

@hke/storage v0.1.5

Weekly downloads
3
License
ISC
Repository
github
Last release
8 years ago

Build Status

@hke/storage

How to use

Include @hke/storage in your code and initialize by creating a new object.

var Storage = require('@hke/storage').Storage;

storage = new Storage({
  caching: true,
  filename: '.storage',
  load: true
});

var list = storage.list('the_list');
console.log(list);
// { name: "the_list", uuid: "list-uuid-1", items: [] }

var item1 = list.add({
  foo: 'bar'
});
var item2 = list.add({
  bar: 'foo'
});

console.log(list.items);
// [ { foo: "bar", uuid: "item-uuid-1" }, { bar: "foo", uuid: "item-uuid-2" } ]

console.log(list.find({bar:'foo'}));
// { bar: "foo", uuid: "item-uuid-2" }

console.log(item2.update({bar:'f00'}));
// { bar: "f00", uuid: "item-uuid-2" }

There are some options available.

PropertyTypeDescription
cachingbooleanEn- or disables the caching system.
filenamestringDefines the filename of the cache file.
loadbooleanWheter the system should try to load a existing cache file.

To use the same storage in another file, use the static singleton() method.

var Storage = require('@hke/storage').Storage;

storage = Storage.singleton();

console.log(storage.list('the_list'));
// { name: "the_list", uuid: "list-uuid-1", items: [ { foo: "bar", uuid: "item-uuid-1" }, { bar: "f00", uuid: "item-uuid-2" } ] }

The Storage object contains some properties and methods. For detailed information clone the repo and run npm install && npm run docs && open ./doc/index.html.

Storage

Properties

PropertyTypeDescription
cachingbooleanIf caching is enabled.
filenamestringThe name of the file to save/load the caching data.
listsList[]The already created lists.
uuidstringA unique id to identify the storage object.

Methods

MethodReturned typeDescription
clearvoidRemoves the cache file if existing.
disableCaching()voidDisables automatic saving after each action.
enableCaching()voidEnables automatic saving after each action.
list(name: string)ListReturns list with passed name. If there is no list with that name a new list is created.
load()booleanLoads storage from filesystem if there is an existing cache file.
reset()voidResets storage and deletes all lists stored in memory.
save(force?: boolean)voidSaves the current storage to the filesystem if caching is enabled or it's forced.

List

Properties

PropertyTypeDescription
itemsItem[]The items of this list.
namestringThe name of the list.
storageStorageThe storage which contains the list.
uuidstringA unique id to identify the list.

Methods

MethodReturned typeDescription
add(data: any)ItemAdds and returns a new item to the list.
find(condition: any)ItemReturns the item which fits the passed condition. Returns null if there is no fitting item.
get(uuid: string)ItemReturns the item which got the passed uuid. Returns null if uuid is not found.

Item

Properties

PropertyTypeDescription
dataanyThe data of the item.
uuidstringA unique id to identify the item.

Methods

MethodReturned typeDescription
update(data: any)ItemUpdates the value of the item.
0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.20

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago