2021-06-21 22:05:08 +00:00
|
|
|
# typescript/storage
|
2019-10-02 20:12:55 +00:00
|
|
|
|
2021-06-21 22:05:08 +00:00
|
|
|
[![Build Status](https://thunderk.visualstudio.com/typescript/_apis/build/status/storage?branchName=master)](https://dev.azure.com/thunderk/typescript/_build?pipelineNameFilter=storage)
|
2021-09-16 21:22:24 +00:00
|
|
|
|
|
|
|
## About
|
|
|
|
|
|
|
|
Javascript/Typescript persistent storage, with key-value stores as foundation.
|
|
|
|
|
|
|
|
## Import
|
|
|
|
|
|
|
|
In deno:
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
import { getLocalStorage } from "https://js.thunderk.net/storage/mod.ts";
|
|
|
|
```
|
|
|
|
|
|
|
|
In browser:
|
|
|
|
|
|
|
|
```html
|
|
|
|
<script type="module">
|
|
|
|
import { getLocalStorage } from "https://js.thunderk.net/storage/mod.js";
|
|
|
|
</script>
|
|
|
|
```
|
|
|
|
|
|
|
|
## Use
|
|
|
|
|
|
|
|
To get a storage locally persistent (saved in browser data or on disk for Deno):
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
const storage = getLocalStorage("myapp");
|
|
|
|
await storage.get("key"); // => null
|
|
|
|
await storage.set("key", "value");
|
|
|
|
await storage.get("key"); // => "value"
|
|
|
|
```
|
|
|
|
|
|
|
|
To get a storage remotely persistent (saved on a compliant server):
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
const storage = getRemoteStorage("myapp", "https://tk-storage.example.io/", {
|
|
|
|
shared: true,
|
|
|
|
});
|
|
|
|
await storage.get("key"); // => null
|
|
|
|
await storage.set("key", "value");
|
|
|
|
await storage.get("key"); // => "value"
|
|
|
|
```
|
|
|
|
|
|
|
|
Run a server for remote storage:
|
|
|
|
|
|
|
|
```shell
|
|
|
|
./cli.ts
|
|
|
|
```
|