UNPKG

1.04 kBMarkdownView Raw
1![Tests](https://github.com/SebastianSpeitel/proxystore/workflows/Tests/badge.svg?branch=master)
2
3# proxystore
4
5Persistent object storage using proxies
6
7## Usage
8
9```javascript
10import { ProxyStore, FileHandler } from "@sebastianspeitel/proxystore";
11
12const handler = new FileHandler("store.json");
13const store = new ProxyStore(handler).store;
14```
15
16Now you can use `store` as any other object and it will be saved in `store.json`
17
18## Options
19
20```typescript
21export interface ProxyStoreOptions<T extends object> {
22 // true to load the initial store using the provided handler
23 // or provide an object to use as initial value
24 init?: T | boolean;
25}
26```
27
28## TypeScript
29
30All methods take a type to use for the store, so you can provide it for autocompletion.
31
32### Example
33
34```typescript
35interface FooBar {
36 foo: number;
37 bar: string;
38}
39
40const store = new ProxyStore<FooBar>(handler).store;
41
42store.foo; // works
43store.baz; // doesn't work
44```
45
46## Handler
47
48You can provide your own handler. Any object with a `load` and `save` method works.