Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/klren0312/localstorage_hasexpiration
localStorage that has expired time
https://github.com/klren0312/localstorage_hasexpiration
localstorage
Last synced: 6 days ago
JSON representation
localStorage that has expired time
- Host: GitHub
- URL: https://github.com/klren0312/localstorage_hasexpiration
- Owner: klren0312
- Created: 2019-01-25T02:21:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-02-06T02:25:35.000Z (about 1 year ago)
- Last Synced: 2025-01-13T19:47:27.880Z (24 days ago)
- Topics: localstorage
- Language: TypeScript
- Homepage:
- Size: 644 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# zstorage
the localStorage that has expired time[![NPM version][npm-image]][npm-url]
[![npm](https://img.shields.io/npm/dt/zstorage.svg)](https://www.npmjs.com/package/zstorage)
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fklren0312%2FlocalStorage_hasExpiration.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fklren0312%2FlocalStorage_hasExpiration?ref=badge_shield)
[![codecov](https://codecov.io/gh/klren0312/localStorage_hasExpiration/branch/master/graph/badge.svg)](https://codecov.io/gh/klren0312/localStorage_hasExpiration)[npm-image]: https://img.shields.io/badge/npm-v1.0.10-blue.svg
[npm-url]: https://www.npmjs.com/package/zstorage## Install
```bash
$ npm install zstorage --save
```## Test
```bash
$ git clone https://github.com/klren0312/localStorage_hasExpiration.git
$ cd localStorage_hasExpiration
$ npm install
$ npm run test
```
## Use
> you can see example in ./index.html```javascript
import Storage from 'zstorage'
Storage.set('test', {t:1,b:2}, 5)
console.log('current,', Storage.get('test'))
setTimeout(() => console.log('after 5s,', Storage.get('test')), 5000)
```## Api
**get (key)**
>get the value by key from localStorage```
param:
key
return:
null (expired)
value (not expired)
```
**set (key, value, expired_second)**
> set the localStorage, with key, value and expired_second(unit: s)**Tips**: You'll not use `JSON.stringify()` to stringify Object or Array
```
param:
key
value
expired_second
return
```
**remove (key)**
> remove the value by key from localStorage```
param:
key
return
```
**clear ()**
> clear all values from localStorage## License
[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fklren0312%2FlocalStorage_hasExpiration.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fklren0312%2FlocalStorage_hasExpiration?ref=badge_large)