Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nixjs/web-storage

A minimalistic Typescript plugin for web storage
https://github.com/nixjs/web-storage

javascript localstorage nixjs react-local-storage react-session session sessionstorage storage typescript web-storage

Last synced: 22 days ago
JSON representation

A minimalistic Typescript plugin for web storage

Awesome Lists containing this project

README

        

# @nixjs23n6/web-storage

A minimalistic Typescript plugin for web storage

## Install

`yarn add @nixjs23n6/web-storage`

## Usage

### New instance

```typescript
import { LocalStorage, SessionStorage, WebStorage } from '@nixjs23n6/web-storage'

const localStorage = new LocalStorage();
// const sessionStorage = new SessionStorage();

localStorage.setItem("ACCESS_TOKEN_KEY", "ACCESS_TOKEN")
localStorage.getItem("ACCESS_TOKEN_KEY")
```

### Extend

```typescript
import { LocalStorage } from '@nixjs23n6/web-storage'

class LocalStore extends LocalStorage {

authorize (token: string): this {
return this.setItem('ACCESS_TOKEN', token);
}

deAuthorize (): this {
return this.removeItem('ACCESS_TOKEN');
}

}

const store = new LocalStore();
```

### Static class

```typescript
import { LocalStorageStatic } from '@nixjs23n6/web-storage'

LocalStorageStatic.setItem("ACCESS_TOKEN_KEY", "ACCESS_TOKEN")
LocalStorageStatic.getItem("ACCESS_TOKEN_KEY")
```