Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/axetroy/deno_storage
implementation of localStorage and sessionStorage for Deno
https://github.com/axetroy/deno_storage
Last synced: about 2 months ago
JSON representation
implementation of localStorage and sessionStorage for Deno
- Host: GitHub
- URL: https://github.com/axetroy/deno_storage
- Owner: axetroy
- License: mit
- Created: 2019-12-15T15:37:03.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-29T00:59:28.000Z (almost 4 years ago)
- Last Synced: 2024-07-11T05:33:06.727Z (2 months ago)
- Language: TypeScript
- Homepage:
- Size: 23.4 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - axetroy/deno_storage - implementation of localStorage and sessionStorage for Deno (TypeScript)
README
[![Build Status](https://github.com/axetroy/deno_storage/workflows/test/badge.svg)](https://github.com/axetroy/deno_storage/actions)
# deno_storage
This is an exploration of Deno's Storage APIs.
explore how to implement the LocalStorage interface.
#### Design Goal
```bash
$ cat setItem.ts
localStorage.setItem("foo", "bar");
# Set the value of the specified domain
$ deno run --domain=deno.land setItem.ts
$ cat getItem.ts
localStorage.getItem("foo");
# Get the value of the specified domain
$ deno run --domain=deno.land getItem.ts
bar
# Cannot get value because no domain was provide
$ deno run getItem.ts
null
```if run without flag `--domain`. then use defaults domain
principle:
1. Isolation using a domain name as a namespace with `--domain` flag
2. File system based to storage data
1. `$HOME/.deno/storage/localstorage/:domain/storage`: Store `value` in `setItem (key, value)`
2. `$HOME/.deno/storage/localstorage/:domain/storage.map` Store `key` in `setItem (key, value)`## Usage
```typescript
import {
LocalStorage,
SessionStorage
} from "https://lib.axetroy.xyz/github.com/axetroy/deno_storage";// when process exits
// sessionStorage is just memory storage, so when the process exits, data is also lost
const sessionStorage = new SessionStorage();// localStorage is based on the file system
// Is persistent storage, when the process exits, the next load of data still exists
const localStorage = new LocalStorage({ domain: "deno.land" });localStorage.setItem("foo", "bar");
localStorage.getItem("foo");
```## Don't use it in production environment
This is just an exploration of Deno's localStorage
There are still many problems
- Not using a mature K-V database, eg. Chrome uses leveldb
- Problems with performance (Not fast enough)
## License
The [MIT License](LICENSE)