1.0.0 • Published 3 years ago

@josiahayres/llama-store v1.0.0

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

llama-store

Statements Statements Statements

llama-store is a Typescript library for interacting with browser storage. It makes it easy to store large objects into localStorage, and lets you so you can make small changes quickly. The restored objects are much more accurate copies of the saved ones and the API is incredibly simple. E.g.:

Installation

Use the package manager npm to install foobar.

npm install llama-store

Usage

import LlamaStore from 'llama-store';

interface MyAppStore extends Record<string, any> {
    name: string;
    age: number;
}

// Using localStorage
const store = new LlamaStore<MyAppStore>('storeName');

API

MethodDescription
new LlamaStore<T>("storeName")Create new instance of a llamaStore
.get(key)Returns stored value
.set(key, value)JSON.stringify(value) and stores that to localStorage
.delete(key)JSON.stringify(value) and stores that to localStorage
.knownKeys()Returns a list of keys stored for this storeName.
.storeConfigReturns config about store.

Events

These are a work in progress

// Write your event handler
const handleStoreSetupSuccess = (storeName: string) => {
    console.log(`[LlamaStore] []${storeName}`);
};

const storeConfig = {
    onStoreSetupSuccess: handleStoreSetupSuccess,
};
var messageStore = LlamaStore.persistent('messageStore', storeConfig);
ImplementedEvent nameDescription
onStoreSetup(key, value)Called when store
onStoreUpdateFailed(key, value)Called when update to store failed
onStoreLimitReached(error)Called when update to store failed
onStoreUpdateSuccess(key, value)Called after update to store was successful
onStoreRemoveSuccess(key)Called when the store was updated
onStoreRemoveFailure(key)Called when the store was updated

Tests

This project has tests written with Jest.

To run the tests: npm run test

Test dependencies:

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT