Skip to content

Commit c468332

Browse files
committed
more examples
1 parent 83f4645 commit c468332

2 files changed

Lines changed: 28 additions & 105 deletions

File tree

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ A storage wrapper that adds expiration functionality to `localStorage` or any ot
1010
npm install expiring-storage
1111
```
1212

13-
## Usage
13+
## Examples
14+
15+
### Basic Usage
1416

1517
```javascript
1618
import { wrapStorage } from "expirix";
@@ -25,6 +27,31 @@ storage.setItem("key", "value");
2527
const value = storage.getItem("key");
2628
```
2729

30+
### Creating a reusable storage module
31+
32+
```javascript
33+
// app-storage.js
34+
import { wrapStorage } from "expirix";
35+
36+
const wrappedLocalStorage = wrapStorage(localStorage, {
37+
expiresInSeconds: 3600,
38+
});
39+
40+
export default wrappedLocalStorage;
41+
```
42+
43+
```javascript
44+
// Using in your app
45+
import storage from "./app-storage.js";
46+
47+
// Store user preferences that expire in 1 hour
48+
storage.setItem("theme", "dark");
49+
storage.setItem("language", "en");
50+
51+
// Later...
52+
const theme = storage.getItem("theme"); // null if expired
53+
```
54+
2855
## API
2956

3057
### `wrapStorage(originalStorage, options?)`

examples/idle-cleanup.js

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)