Skip to content

Commit 493c12b

Browse files
committed
more examples
1 parent 83f4645 commit 493c12b

2 files changed

Lines changed: 29 additions & 106 deletions

File tree

README.md

Lines changed: 29 additions & 2 deletions
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?)`
@@ -41,7 +68,7 @@ Wraps a Storage object to add expiration functionality.
4168

4269
### `cleanupFactory(originalStorage, options?)`
4370

44-
Creates a cleanup function to wrap existing values and remove expired ones.
71+
Creates a cleanup function to remove expired values and optionally wrap unwrapped values so that they can be cleaned up later on as well.
4572

4673
**Parameters:**
4774

examples/idle-cleanup.js

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

0 commit comments

Comments
 (0)