0.1.5 • Published 8 years ago
@hke/storage v0.1.5
@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.
Property | Type | Description |
---|---|---|
caching | boolean | En- or disables the caching system. |
filename | string | Defines the filename of the cache file. |
load | boolean | Wheter 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
Property | Type | Description |
---|---|---|
caching | boolean | If caching is enabled. |
filename | string | The name of the file to save/load the caching data. |
lists | List[] | The already created lists. |
uuid | string | A unique id to identify the storage object. |
Methods
Method | Returned type | Description |
---|---|---|
clear | void | Removes the cache file if existing. |
disableCaching() | void | Disables automatic saving after each action. |
enableCaching() | void | Enables automatic saving after each action. |
list(name: string) | List | Returns list with passed name. If there is no list with that name a new list is created. |
load() | boolean | Loads storage from filesystem if there is an existing cache file. |
reset() | void | Resets storage and deletes all lists stored in memory. |
save(force?: boolean) | void | Saves the current storage to the filesystem if caching is enabled or it's forced. |
List
Properties
Property | Type | Description |
---|---|---|
items | Item[] | The items of this list. |
name | string | The name of the list. |
storage | Storage | The storage which contains the list. |
uuid | string | A unique id to identify the list. |
Methods
Method | Returned type | Description |
---|---|---|
add(data: any) | Item | Adds and returns a new item to the list. |
find(condition: any) | Item | Returns the item which fits the passed condition. Returns null if there is no fitting item. |
get(uuid: string) | Item | Returns the item which got the passed uuid. Returns null if uuid is not found. |
Item
Properties
Property | Type | Description |
---|---|---|
data | any | The data of the item. |
uuid | string | A unique id to identify the item. |
Methods
Method | Returned type | Description |
---|---|---|
update(data: any) | Item | Updates 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