localStorage with expire time
npm install @hooshid/local-store``js`
import localStore from '@hooshid/local-store'
- set — Add item to local storage.get
- — Get item from local storageremove
- — Remove item from local storage.clearAll
- — Removes all or just Prefixed items from local storage.has
- — Check item exist in local storage.getExpireTime
- — Get item expire time.getRemainTime
- — Get remaining TTL of a item.
Set an item in local storage.
`js`
set(key: string, value: string, ttl?: number | string): void
- key - The key of the item to set.value
- - The value to set.ttl
- - The time life in seconds format for living cache in localStorage.ttl
- - The time life in default is one year, if you want set time life you should set in seconds or set like below format.
`bash`
m for minute
h for hour
d for day
#### examples
* 60m -> 60 minute
* 1h -> 1 hour (equal to 60m)
* 24h -> 24 hours (equal to 1d)
* 1d -> 1 day
* 30d -> 30 days
just use 1 above method and don't mixed (1d12h does not work -> 36h work fine!)
Get an item from local storage.
`js`
get(key: string): string | null
- key — The key of the item to get.
Remove item from local storage.
`js`
remove(key: string): void
- key — The key of the item to remove.
Removes all or just Prefixed items from local storage.
`js`
clearAll(prefix?: string): void
- prefix — if prefix provided, only keys start with prefix cleared and if prefix undefined all keys cleared.
Check key is exist
`js`
has(key: string): boolean
- key — The key of the item.
Get item expire time.
`js`
getExpireTime(key: string): null|number
- key — The key of the item.
Get remaining time of a item.
`js`
getRemainTime(key: string): null|number
- key` — The key of the item.