generics-storage
v1.0.0
Published
local storage for any implementation or cookie with immutable-helper
Downloads
6
Maintainers
Readme
generics-storage
local storage for any implementation or cookie with immutable-helper update
Installation
yarn add immutable-helper generics-storage
or
npm install immutable-helper generics-storage --save
Simple usage
import {GenericsStorage} from 'generics-storage';
const storage = new GenericsStorage(); // default storage is cookie
const query = {$push: [1, 2, "test"]}; // immutable-helper query
storage.update("some-field", query);
storage.getValue("some-field");
// should be an array [1, 2, "test"]
storage.remove("some-field");
// undefined
API
| Method | Argument(Type) | Return Type | Description | |:---:|:---:|:---:|:---| | update | key: string, query: object | void | update current object or array to key by query | | getValue | key: string | object or Array | Get value (object or array) from key | | remove | key: string | void | Clean data of key |
Custom your storage (optional)
import * as Cookies from 'js-cookie';
import {Storage, GenericsStorage} from 'generics-storage';
export class CookieStorage implements Storage {
setItem(key, value) {
Cookies.set(key, value);
}
getItem(key) {
return Cookies.get(key);
}
removeItem(key) {
Cookies.remove(key);
}
}
const cookie = new CookieStorage();
export const storage = new GenericsStorage(cookie);
Contributing
npm test